Serial Server - syue99/Lab_control GitHub Wiki
The serial server is roughly analogous to the better developed GPIB server.
It uses the LabRAD Registry to communicate to identify serial devices. To facilitate this the serial server requires a folder at the highest level of the Registry called "Ports". Inside this folder specific serial devices should be listed as the "key" with the corresponding "value" being their port address.
- Improved port finding on all platforms. Requires pyserial >= 2.6
Changed the original serial_server_v1_1 found among provided LabRAD modules
- support for both windows and linux
- additional settings for flushing input and output
#####Fast way:
One may use the folder /dev/serial/by-id/ this should avoid changing ports
#####Probably safer way?:
Devices may get assigned a new port name (COM1 instead of COM0 or ttyUSB1 instead of ttyUSBO) if they are restarted while the port is open. This is the case, for instance, when the serial server and the device server are both running while the physical device is restarted. To avoid this issue, the device server has to be turned off before power cycling or disconnecting the device.
Alternatively, by defining udev rules, we can address each device using an alias regardless of which port it decides to connect to. Say, for example, that the deice is currently assigned to /dev/ttyUSB1. Using udevadm, we can determine complete information about the device attributes:
$ udevadm info -a --name /dev/ttyUSB1
...
ATTRS{manufacturer}=="FTDI"
ATTRS{product}=="USB Serial Converter"
ATTRS{serial}=="FTF89AE9"
...
The combination of manufacturer, product, and serial should uniquely identify each device. We can use these attributes to assign a permanent alias. Create a .rules file in the /etc/udev/rules.d directory, e.g., /etc/udev/rules.d/assign-USB.rules.
ATTRS{serial}=="FTF89AE9",SYMLINK+="mydevice"
After triggering our new udev rule, the device will be accessible accessible via /dev/mydevice. One can also specify NAME ="ttyUSB10" to have a permanent reference.
$ udevadm trigger
On Linux, if no serial ports are found, make sure the user has the right permissions to open the serial ports.
ls -l /dev/
For instance, one can add the user to the group dialout
adduser username dialout
To make sure one can open the port, use the python serial library, i.e
import serial
ser = serial.Serial('/dev/ttyUSB0')