I’m trying to control a relay using Python, but I’ve hit a roadblock.
Unfortunately, I couldn’t find the datasheet for this specific relay, which means I don’t have the correct commands to send.
Here’s what I’ve tried so far:
The computer recognizes the device as an HID (Human Interface Device).
I’ve attempted various commands, but none seem to work.
I tried this code, but I got an error because my relay didn’t take any commands:
import hid
def list_hid_devices():
for device in hid.enumerate():
keys = list(device.keys())
keys.sort()
for key in keys:
print(f"{key}: {device[key]}")
print()
def send_hid_command(vendor_id, product_id, command):
try:
device = hid.device()
device.open(vendor_id, product_id)
print(f"Manufacturer: {device.get_manufacturer_string()}")
print(f"Product: {device.get_product_string()}")
print(f"Serial No: {device.get_serial_number_string()}")
device.write(command)
response = device.read(64)
print(f"Response: {response}")
device.close()
except Exception as e:
print(f"Error: {e}")
print(" HID devices:")
list_hid_devices()
VENDOR_ID = 0x16C0
PRODUCT_ID = 0x05DF
relay_commands = [
[0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
]
for command in relay_commands:
send_hid_command(VENDOR_ID, PRODUCT_ID, command)
My terminal is like this:
Manufacturer: www.dcttech.com
Product: USBRelay4
Serial No:
Error: read error
Manufacturer: www.dcttech.com
Product: USBRelay4
Serial No:
Error: read error
Does anyone know the right commands for controlling this relay?
Where can I find the datasheet for this relay?
ukser is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.