XLR switch remote control via RS-232 and Telnet from Python

The XLR switch and BNC switch from LinkBone can be remotely controlled via a Ethernet or RS-232 interfaces from Python environment. This article explains how to prepare an Python environment for remote control of XLR switches. The complete python module implementations and code examples are included.
Coaxial BNC switch with Remote access from LinkBone

 

The example application using XLR switch as a microphone multiplexer is shown on the following drawing:

XLR switch used as a microphone multiplexer (audio)

The LinkBone XLR switch is routing signals from microphone to the audio recorder. As all signal lines are bidirectional the LinkBone XLR switch can be also used in audio distribution to a set of a speakers from single audio source. The device can be controlled manually via touch screen or IR remote control. The second option is remote control via 10/100Ethernet or RS-232 interfaces. The Python environment can be used for control of the XLR switches. All LinkBone devices also include visual web interface(http) shown on the following picture:

XLR switch remote Web/http interface

Preparing Python environment for XLR switch

Before starting, make sure that you have already installed Python 3 on your machine. If not, you can easily download it from official page. You need also Python Serial Port Extension (pyserial), which encapsulates the access for the serial port. You can find this module here. Finally, you can download our Python modules from our website:

  • Module RS232linkbone.py for remote control via RS-232 can be found here
  • Module TELNETlinkbone.py for remote control via Telnet can be found here

Please note, that these libraries are intended to use in Python 3.0

XLR switch with remote control via RS-232 in Python

The LinkBone XLR switch can be controlled via serial RS-232 from Python program level. The following paragraph shortly explains how to setup a serial port and send text commands to the device using Python scripts.

First, the RS232linkbone module has to be imported:

import RS232linkbone

Using rs232 class from RS232linkbone module, serial connection to LinkBone switch can be established, for instance:

serial = RS232linkbone.rs232("COM12", 9600, "N", 1, False)
Serial connection to LinkBone has been established!
Serial<id=0x364e270, open=True>(port='COM12', baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=1, xonxoff=False, rtscts=False, dsrdtr=False)

Class rs232(port, baudrate, parity, stopbits, rtscts) takes the following arguments:

  • port – serial port
  • baudrate – RS-232 port baud rate, 9600…115200
  • parity – parity bit, “N” (No parity), “O” (Odd parity), “E” (Even parity)
  • stopbits – number of stop bits between data words
  • rtscts – hardware control flow, True (data is transmitted using RTS / CTS control flow according to the RS-232 standard) or False (data is transmitted without control flow mechanism)

After setting the serial port, test commands can be send to the switch by using sendCommand(command) method.

# send control commands to LinkBone XLR switch with remote control 
serial.sendCommand("mode single")
Done.
serial.sendCommand("on a")
Done.

A good practice is to close serial port, when you finish your work with LinkBone switch. The following code can be used for closing serial port connection.

serial.close()

XLR switch with remote control via Telnet in Python

The LinkBone XLR switch can be also controlled via Telnet from Python program level. The following paragraph shortly explains how to setup a Telnet connection and send text commands to the device using Python scripts.

First, the TELNETlinkbone module has to be imported:

import TELNETlinkbone

Using telnet class from TELNETlinkbone module, telnet connection to LinkBone switch can be established, for instance:

telnet = TELNETlinkbone.telnet("169.254.89.200")
Telnet connection to LinkBone has been established!

Class telnet(ip) takes the following argument:

  • ip – ip address of LinkBone switch

After setting the telnet connection, test commands can be send to the switch by using sendCommand(command) method.

# send control commands to LinkBone XLR switch with remote control 
telnet.sendCommand("reset")
Done.
telnet.sendCommand("mode multi")
Done.
telnet.sendCommand("on a b c d")
Done.

After finishing work with LinkBone switch, telnet connection can be closed. The following code can be used for closing telnet connection.

telnet.close()

For more commands which can be sent to LinkBone switch, please refer to LinkBone-1-to-15-Switch-user-manual-v0.9.pdf.

Source code of module RS232linkbone.py for remote control via RS-232 can be found here,  whereas module TELNETlinkbone.py for remote control via Telnet can be found here.