[Ed. Note: Content created by Jesse Off, May 18, 2012]
I've added native support for using libmodbus via xuartctl TCP serial port servers. Since TS supports the usage of XUART serial ports as network services, this allows one to create apps using libmodbus and the MODBUS/RTU protocol that are hosted on the local or a remote machine but use RS485 or RS232 serial ports on a SBC anywhere on the internet or local network.
Real serial port hardware is increasing becoming a rare feature on modern computers and often times USB to Serial converters are the only option. Unfortunately, in my experience, these USB to serial converters seem to always have sub-standard device drivers that often cause the host machines to crash or the USB device to lock up until you unplug/replug it in. Not only that, their performance is often quite poor when it comes to protocols like MODBUS that have a lot of request/responses due to lack of a real discrete IRQ signal on USB. The default software "xuartctl" on most of our XUART capable SBCs basically allows the SBC to function like a serial to ethernet converter out of the box. These network "exported" serial ports can be connected to by any other machine on the network that knows its IP address and used just as conveniently as a local serial port on any computer on the network.
To use MODBUS/RTU over real serial drivers in the past you've had to start out your C application something like this:
modbus_t *ctx; ctx = modbus_new_rtu("/dev/ttyUSB0", 115200, 'N', 8, 1);
This has not been changed in the patch, but now that function is smart about being passed a device name matching "HOSTNAME_OR_IPADDRESS:PORT", such that the following will also work to (e.g.) connect to an XUART port being served up at 192.168.0.50 on TCP port 7350:
modbus_t *ctx; ctx = modbus_new_rtu("192.168.0.50:7350", 115200, 'N', 8, 1);
The rest of the interaction with libmodbus is exactly the same. It should be noted that the patch makes use of a native "xuartctl" binary installed somewhere in the $PATH. "xuartctl" compiles on just about any POSIX system out there, Mac, Windows, Linux, Solaris, etc and its source is available here: http://ftp.embeddedTS.com/ftp/ts-ar...linux/sources/ It is installed by default on all SBC's with XUARTs.
Note that this has nothing to do with MODBUS/TCP which is another protocol which is supported by much fewer MODBUS devices out there that happen to have an ethernet port instead of RS485 serial.
I'm not sure if this will be integrated in future official distributions of libmodbus as that is up to the original author, but the patches are being submitted freely with the same open source GPL license as the original libmodbus. To find out more about libmodbus, please visit its website at http://libmodbus.org
To find out more about XUARTs and the userspace driver "xuartctl", please visit the wiki documentation at http://wiki.embeddedTS.com/wiki/Xuartctl
[Ed. Note: Content added by Grant Peacock, May 20th, 2012]
For anyone who is not familiar with XUART hardware and MODBUS/RTU, I'd like to further explain the performance advantage of this patch.
MODBUS/RTU has strict timing on its serial frames. Each frame of typically 8 or more characters is not permitted to have a gap in it of 3.5 character times. If the transmitting device is running an RTOS, this is not a problem, but it is difficult for Linux to make this sort of guarantee. The faster the baud rate, the more this is an issue. At 9600 baud, any modern device can keep up, but at 115200 or 250000 baud, on an embedded system that is busy with other processing tasks, malformed MODBUS frames can become a concern. Any time the frame is transmitted with a gap, the client software will have to time out after waiting for a response and then retry. If this scenario is prevented, a maximum latency is established for MODBUS transactions.
The XUART hardware can transmit serial frames of up to 256 characters that are 100% guaranteed to be contiguous with no gaps. The libmodbus patch takes advantage of this capability to guarantee MODBUS compliance.
TS is also developing a series of affordable MODBUS/RTU slaves that can operate at up to 2.5 megabaud. The TS-7520-BOX and other MODBUS-capable SBCs will work with these devices as well as any MODBUS compliant legacy products. This makes it easy to use MODBUS as a high-performance IO expander to build a control system that is low cost, reliable, rugged, and physically distributed around a large area or building.