Do you have python driver for latching relay USB-RLY16L?

Hi!

I require your help regarding a problem I’m encountering.

Description:
Can’t find a python driver to control Devantech latching relay USB-RLY16L. I need to control this relay with Python program.

Hardware concerned:

Software concerned:
Python

Troubleshooting steps already taken:

Additional information:
Why can’t talk to it with NI MAX?

Thank you so much in advance for your help!

Hello @sheldonchen and welcome to the RobotShop forum,

There’s no official Python code from the manufacturer but I found these:


Great! I will try it out. Thank you very much!

1 Like

I tried both, none of the two work, either “missing argument” or device no any response after running the code. They don’t have detailed description of how to use their API.

in one case:
n [50]: runfile(‘C:/Users/shchen/Documents/equipment/Relay/Devantech/code_RLY8.py’, wdir=‘C:/Users/shchen/Documents/equipment/Relay/Devantech’)
usage: code_RLY8.py [-h] -p PORT [-t SECONDS] [-a {on,off}]
[-n {0,1,2,3,4,5,6,7}] [-f {0,1,2,3,4,5,6,7}] [-r value]
[-g] [-s] [-i]
code_RLY8.py: error: the following arguments are required: -p/–port
An exception has occurred, use %tb to see the full traceback.
SystemExit: 2

with 2nd code:
In [49]: runfile(‘C:/Users/shchen/Documents/equipment/Relay/Devantech/code2.py’, wdir=‘C:/Users/shchen/Documents/equipment/Relay/Devantech’)
Enter your commands below.
Insert “exit” to leave the application.

100
110
91

But device won’t response or switch at all.

If you are getting a “missing argument” error it’s because you are missing arguments when running the code. You need to specify the serial port, the timeout parameter in seconds and the state of the relays.

Check the README file, there’s an example there:

% ./usbrly08.py -p /dev/tty.usbmodem00030611 -g -a off

Thank you for reply again. This seems to be Linux command, I am using Window’s system. I have already selected Numato and Ontrak raley to use, they have drivers available for Python users, fairly convenient to get them working. I may come back later to try this model again. Thanks.

Hello again,

No, those aren’t Linux commands, those are arguments needed as input to run the code.
You simply need to open the command prompt, cd to where you have the code and run

python usbrly08.py -p /dev/tty.usbmodem00030611 -g -a off

But that’s an example, here’s more info on that:

Setup tool’s command line arguments

ap = argparse.ArgumentParser(description="USB-RLY controlling tool version %s" % (__version__))

ap.add_argument('-p', '--port', help='Serial port of the USB-RLY device', required=True)
ap.add_argument('-t', '--timeout', metavar='SECONDS',
                type=int, help='Timeout for serial communications')

controlGroup = ap.add_argument_group('control')
controlGroup.add_argument('-a', '--all-relays',
                          help='Set all relays to specified state', choices=['on', 'off'])
controlGroup.add_argument('-n', '--relay-on', help='Set a relay to ON state',
                          type=int, choices=range(0, 8), action='append')
controlGroup.add_argument('-f', '--relay-off', help='Set a relay to OFF state',
                          type=int, choices=range(0, 8), action='append')
controlGroup.add_argument('-r', '--set-relays', help='Set the state of relays by 8-bit value (0-255, 0x00-0xff)',
                          metavar='value', action=Uint8ValueAction)

queryGroup = ap.add_argument_group('query')
queryGroup.add_argument('-g', '--relays', help='Get the state of the relays', action='store_true')
queryGroup.add_argument('-s', '--get-serial',
                        help='Get serial number of the board', action='store_true')
queryGroup.add_argument('-i', '--get-version',
                        help='Get SW version of the board', action='store_true')

Anyway, good luck with the other relays and your project!

I found the following method more straight forward to use for Python users, no need of any driver:

import serial
ser = serial.Serial(port=‘COM5’,baudrate=9600, timeout=1)
ser.isOpen()
inpt = b’\x64’ # All relays to position 1.
ser.write(inpt)
inpt = b’\x5C\xAA’ # 2,4,6,8 relays to position 1.
ser.write(inpt)
ser.close()

1 Like