0

I'm using python 3.9.6 to manage a hid relay board enter image description here

I can read vendor id 1305 and product id 8216 of my board using enumerate command, then I tried some commands:

>>> device = hid.Device(1305,8216)
>>> device.manufacturer
'Ucreatefun.com'
>>> device.product
'HIDRelay'
>>> device.serial
'A0001'

Now I'd like to manage the relays on the board using "device.write", how can I do this? From the manual of relay board:

" Channel 1 open: 0x00 0xf1, close: 0x00 0x01 "

Unfortunately it doesn't work, when I try this:

>>> device.write([0x00,0xF1])
Traceback (most recent call last):
File "<pyshell#61>", line 1, in <module>
device.write([0x00,0xF1])
File 
"C:\Users\trevisan\AppData\Local\Programs\Python\Python39\lib\site- 
packages\hid\__init__.py", line 155, in write
return self.__hidcall(hidapi.hid_write, self.__dev, data, len(data))
File 
"C:\Users\trevisan\AppData\Local\Programs\Python\Python39\lib\site- 
packages\hid\__init__.py", line 142, in __hidcall
ret = function(*args, **kwargs)
ctypes.ArgumentError: argument 2: <class 'TypeError'>: wrong type
>>> 

Why python raises a type error when I pass a list in device.write method?

Thanks a lot! Max

double-beep
  • 5,031
  • 17
  • 33
  • 41
mtre
  • 21
  • 4
  • what you have done so far. There are lot of threads about this perhaps one of them could help? Just an example: https://stackoverflow.com/questions/65705541/q-write-a-string-to-hid-device-in-python –  Jul 08 '21 at 16:03
  • When I use "device.write([0x00,0xF1])", python raises a "TypeError", is there something wrong in arguments of write method? – mtre Jul 12 '21 at 15:38

1 Answers1

1

I solved using the class bytes:

>>> device.write(bytes([0x00,0xf1]))

I'm very happy! Max

mtre
  • 21
  • 4