Basic ethernet control of 2010 R8xPL via python


I’ve got a 2010 8-relay board with a Lantronix ethernet adapter that I’d like to control from python. I’ve got the code from the github repo, and edited it as per a different post I read suggesting that these older boards need something like this (no ‘self.wrap_in_api()’):

def turn_on_relay_by_index(self, relay):
lsb = relay-1 & 255
msb = relay >> 8
command = [254,48,lsb,msb]
return self.process_control_command_return_no_api(self.send_command(command, 1))

and a

def process_control_command_return_no_api(self, data):
return [True, self.hex_to_decimal(data)]

In any case, I only ever get a timeout when running:

import socket
import ncd_industrial_relay

#set up your socket with the desired settings.
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#instantiate the board object and pass it the network socket
board1 = ncd_industrial_relay.Relay_Controller(sock)
#connect the socket using desired IP and Port
#PORT = 2101
PORT = 10001

sock.connect((IP_ADDRESS, PORT))


I just need to toggle three or four different relays independently. Happy to do it in BASH if there’s a way… What am I missing?



These older models don’t support the turn_on_relay_by_index command. I would recommend the turn_on_relay_by_bank command instead.

Thanks for the speedy reply. It still just times out though. :frowning:

I would first attempt to use Base Station to control the relays: Start -

Power cycle the board and close any application that may be holding a socket open to the relay controller. You might even restart the computer just to make sure nothing is attempting to connect to it.

If Base Station is unable to control the relays then most likely there’s a fault on the board or a misconfiguration on the Ethernet module. For the code above it should be setup to act as a TCP server.

Can you send the configuration settings of your Ethernet module?

The guide for the Ethernet module you have can be found at: (Deprecated Technology) Lantronix XPort Communications Module Quick Start Guide -

I would need to see the “Network” page as well as the Channel 1 > “Serial Settings” page.

I’m on Ubuntu, so no Base Station for me :confused:

Well Base Station is useful, but not required. The closest we have on linux for testing would be the Python library though.

Can you send the configurations mentioned previously, a copy/paste or screenshot of the error message, and an image of your relay controller?