Skip to content

Conversation

@stefanportmann
Copy link

Added the RTU server in the same manner as the TCP server. You can use the same modbus.conenctionHandler.
You can start the server like this:

func ModbusServeRTU(ttypath string, modbusAddress uint8) (err error) {
	var server *modbus.ModbusRtuServer

	go modbusConnectionHandler.StartUptimeCounting()

	server, err = modbus.NewRTUServer(&modbus.ModbusRtuServerConfig{
		TTYPath:       ttypath,
		ModbusAddress: modbusAddress,
	}, modbusConnectionHandler)
	if err != nil {
		modbusLog.Printf("Failed to create RTU server: %v\n", err)
		return
	}

	err = server.Start()
	if err != nil {
		modbusLog.Printf("Failed to start RTU server: %v\n", err)
		return
	}
	modbusLog.Printf("RTU server started on %v, with address %v\n", ttypath, modbusAddress)
	return
}

Because we need pre-defined 'any' type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant