Closed wz2b closed 3 years ago
Another approach here would be to read the response in a loop. If the transaction ID is not the one you expected, go around the loop again. The reason I didn't do that is it's more intrusive of a code change, but if somebody feels strongly that's a better way to solve this let me know.
hey @wz2b thanks for your contribution, i will have a look in the next days. What might help is a unittest that shows the behaviour.
hey @wz2b thanks for your contribution, i will have a look in the next days. What might help is a unittest that shows the behaviour.
I think that to really test it would require mocking the TCP stream, wouldn't it? The behavior I would want to see would be send it a mismatched transaction id and see that it closes the connection, fails that transaction, then starts over at transaction id 1 with a new connection. I'm not really sure how to approach this in go.
see #36.
connection) you might go to send the next poll and immediately receive the previous response. The result is a mismatch in the transaction ID from which the connection will never recover. There are a few ways to mitigate this, including receiving the response in a loop, but since this modbus tcp implementation is completely synchronous the simplest thing to do is to simply flush the receive buffer immediately prior to sending the next poll.