rossmann-engineering / EasyModbusTCP.NET

Modbus TCP, Modbus UDP and Modbus RTU client/server library for .NET implementations
922 stars 396 forks source link

RX Buffer was being cleared with correct data in it. #94

Open bjornComate opened 1 year ago

bjornComate commented 1 year ago

The transmit buffer was send before the RX buffer was being cleared. When a slave device was answering faster then the lib was clearing the buffer. correct data was being removed, and the packet was lost.

Padanian commented 1 year ago

AFAIK, I don't think this is the right way to do it. Never had this issue before. Check if slave is abiding to the correct timings. Sometimes, embedded devices are able to answer before the UART switches TX/RX lines.

bjornComate commented 1 year ago

Slave is abiding timings. We've checked this with a saleae logic analyzer. I can also see the data in the buffer that as being answered back (also checked this). before it's being deleted. We're also using RS232. so no switching of RX/TX lines

Clearing your buffer before sending solves this. and I can't see a reason why you would want to first send and then clear the receive buffer, since modbus is half duplex, a slave will never answer before the master sends so there isn't going to be rogue data in the buffer if you clear it beforehand.