doc
doc copied to clipboard
Not able to teensy.write/read in python.
Default Code:
import hid
from urllib import request
import json
hidInterfaces = hid.enumerate() # get all hid interfaces
t_it = filter(lambda t: # filter by vid and usagepage/usage
t['vendor_id'] == 0x16c0 and
t['usage_page'] == 0xFFAB and
t['usage'] == 0x0200, hidInterfaces)
rawHID_interface = next(t_it, None) # 'firstOrDefault'
if rawHID_interface != None:
teensy = hid.Device(path = rawHID_interface["path"])
for i in range(10):
jsonurl = request.urlopen("https://api.adviceslip.com/advice")
slip = '\0' + json.loads(jsonurl.read())['slip']['advice'] # the sent report must always start with \0
teensy.write(slip.encode()[:64]) # rawHID report is 64 bytes long
Error:
File "hid.pyx", line 164, in hid.device.write
ValueError: not open
Does anyone know what error is this?