
func ReadInputRegisters(s *Server, frame Framer) (byte, *Exception).func ReadHoldingRegisters(s *Server, frame Framer) (byte, *Exception).func ReadDiscreteInputs(s *Server, frame Framer) (byte, *Exception).func ReadCoils(s *Server, frame Framer) (byte, *Exception).func GetException(frame Framer) (exception Exception).

func Uint16ToBytes(values uint16) byte.func SetDataWithRegisterAndNumberAndValues(frame Framer, register uint16, number uint16, values uint16).func SetDataWithRegisterAndNumberAndBytes(frame Framer, register uint16, number uint16, bytes byte).func SetDataWithRegisterAndNumber(frame Framer, register uint16, number uint16).Results, err := client.ReadHoldingRegisters(0, 3) _, err = client.WriteMultipleRegisters(0, 3, byte) Connect manually so that multiple requests are handled in one session

Handler := modbus.NewTCPClientHandler("localhost:1502") Change the port number as required.Ĭhange the address to 0.0.0.0 to listen on all network interfaces.Īn example of a client writing and reading holding regsiters: package main Modbus typically uses port 502 (standard users require special permissions to listen on port 502). The server will continue to listen until killed (-c). Example Modbus TCP ServerĬreate a Modbus TCP Server (Slave): package main Modbus requests are processed in the order they are received and will not overlap/interfere with each other. On start, all values are initialzied to zero. The server internally allocates memory for 65536 coils, 65536 discrete inputs, 653356 holding registers and 65536 input registers. The Golang Modbus Server (Slave) responds to the following Modbus function requests: (s) RegisterFunctionHandler(funcCode, function) SetDataWithRegisterAndNumberAndValues(frame, register, number, values) SetDataWithRegisterAndNumberAndBytes(frame, register, number, bytes) SetDataWithRegisterAndNumber(frame, register, number) msg.Example Listening on Multiple TCP Ports and Serial Devices In addition, you can pass in a msg with one or more payload settings to initiate additional modbus read events. Run the following command in the root directory of your Node-RED install npm install node-red-contrib-modbustcp

Node-Red Modbus TCP nodes for communicating with a Modbus TCP server. Node-RED nodes for communicating with a MODBUS TCP Server.
