Categorygithub.com/CreatorsLab/go-modbus
modulepackage
0.0.0-20210901012020-6ce86e75d773
Repository: https://github.com/creatorslab/go-modbus.git
Documentation: pkg.go.dev

# README

go-modbus

About

This Go package provides Modbus access for client (master) applications to communicate with server (slave) devices, over both TCP/IP and Serial Line/RTU/ASCII 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:

Modbus Transaction

This code was originally forked from lubia/modbus and repositioned as a pure client (master) library for use by controller applications.

Installation and Usage

Install the package in your environment with these commands (the RTU code now depends on goserial):

go get github.com/tarm/goserial
go get github.com/dpapathanasiou/go-modbus

Next, build and run the examples:

Enabling the USB Serial Port adapter (RS-232) for RTU/ASCII Access

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:

  1. 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
  1. 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
  1. 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 /dev/ttyUSB0

References

Acknowledgements

# Packages

No description provided by the author

# Functions

ASCIIRead performs the given modbus Read function over ASCII to the given serialDevice, using the given frame data.
ASCIIWrite performs the given modbus Write function over ASCII to the given serialDevice, using the given frame data.
ConnectASCII attempts to access the Serial Device for subsequent ASCII writes and response reads from the modbus slave device.
ConnectRTU attempts to access the Serial Device for subsequent RTU writes and response reads from the modbus slave device.
ConnectTCP attempts to make a tcp connection to the given server/port and returns the connection object (or nil, if fail) and an error (which will be nil on success).
DecodeHiLo attempts to convert a byte array of High/Low Byte values into a 16-bit integer, and returns the result, also with an error, which will be non-nil if the decoding failed.
DisconnectASCII closes the underlying Serial Device connection.
DisconnectRTU closes the underlying Serial Device connection.
No description provided by the author
No description provided by the author
TCPRead performs the given modbus Read function over TCP to the given host/port combination, using the given frame data.
TCPWrite performs the given modbus Write function over TCP to the given host/port combination, using the given frame data.
ValidFunction returns a boolean, depending on whether or not the given code corresponds to a valid modbus function code, read, write, or interface.
ValidReadFunction returns a boolean, depending on whether or not the given code corresponds to a valid modbus read function code.
ValidWriteFunction returns a boolean, depending on whether or not the given code corresponds to a valid modbus write function code.

# Constants

No description provided by the author
No description provided by the author
this is not official.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
catch-all for unspecified modbus errors.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author