This Go package provides Modbus access for client (master) applications to communicate with server (slave) devices, over both TCP/IP and Serial Line/RTU frame protocols.
Note that in modbus terminology, client refers to the master application or device, and the server is the slave waiting to respond to instructions, as shown in this transaction diagram:
This code was originally forked from lubia/modbus and repositioned as a pure client (master) library for use by controller applications.
Slave devices which have USB ports for RTU access will not work immediately upon hot-plugging into a master computer.
For master devices running linux, the USB serial port adapter must be explicitly activated using the usbserial linux kernel module, as follows:
-
Immediately after plugging in the serial port USB, use dmesg to find the vendor and product ID numbers:
$ sudo dmesg | tail
There should be a line which looks like this:
````
[ 556.572417] usb 3-1: New USB device found, idVendor=04d8, idProduct=000c
-
Use the usbserial linux kernel module to enable it, using the same vendor and product ID numbers from the dmesg output:
$ sudo modprobe usbserial vendor=0x04d8 product=0x000c
3. Confirm that the serial port is attached to a specific tty device file:
```
$ sudo dmesg | tail
There should now be a line like this:
```
[ 2134.866724] usb 3-1: generic converter now attached to ttyUSB0
which means that the serial port is now programmatically accessible via <tt>/dev/ttyUSB0</tt>
## References
- [Modbus Technical Specifications](http://www.modbus.org/specs.php)
- [Modbus Interface Tutorial](http://www.lammertbies.nl/comm/info/modbus.html)
- [Modbus TCP/IP Overview](http://www.rtaautomation.com/modbustcp/)
- [Modbus RTU Protocol Overview](http://www.rtaautomation.com/modbusrtu/)
## Acknowledgements
- [Lubia Yang](http://www.lubia.me) for the [original modbus code](https://github.com/lubia/modbus) in Go
- [l.lefebvre](http://source.perl.free.fr/) for his excellent [modbus client](https://github.com/sourceperl/MBclient) and [server (slave device simulator)](https://github.com/sourceperl/mbserverd) code repositories
- [modbusdriver.com](http://www.modbusdriver.com/) for their free [Diagslave Modbus Slave Simulator](http://www.modbusdriver.com/diagslave.html) tool
- [Mohammad Hafiz (mypapit)](https://plus.google.com/113437861006502895279?rel=author) for his well-written [How to enable USB-Serial Port adapter (RS-232) in Ubuntu Linux](http://blog.mypapit.net/2008/05/how-to-use-usb-serial-port-converter-in-ubuntu.html) blog post