modbus icon indicating copy to clipboard operation
modbus copied to clipboard

Use a better maintained serial library, pass UnitID, Endianess and WordOrder to Read and Write methods

Open munnik opened this issue 1 year ago • 1 comments

With this serial library, we don't have any issues with the even parity anymore. Also, this serial library is still maintained.

Options can be passed to the read and write methods to set the UnitID, Endianess and WordOrder. This is especially helpfull when the client is shared between multiple goroutines that each do a request to a different modbus slave.

munnik avatar Oct 04 '24 15:10 munnik

Hi there,

thanks for the PR. I haven't had much issues with parity so far, so I'd need to be able to troubleshoot that more in detail.

This is especially helpfull when the client is shared between multiple goroutines that each do a request to a different modbus slave.

This is usually really easily solved by having the goroutines in question sharing a mutex and doing something like this:

mutex.Lock()
client.SetUnitId(...)
client.SetEncoding(...)
err = client.WriteRegister(...)
mutex.Unlock()

Since they're already sharing a client, sharing an additional mutex shouldn't require too much boilerplate.

Would that work for you ? I'd like to avoid dealing with that additional complexity at the client level, if possible.

simonvetter avatar Nov 14 '24 13:11 simonvetter