tarm / serial

BSD 3-Clause "New" or "Revised" License
1.6k stars 451 forks source link

Reading a predefined amount of bytes - RS485 mode #103

Closed lg007 closed 4 years ago

lg007 commented 4 years ago

I have to implement an RS-485 (Modbus) interface with GO on an RPI 3B using a Seeed RS-485 Shield. This means that to get data from a Modbus device, the following has to be done:

I have done the whole process (together with other processes) with RXJAVA using Pi4J (which uses the Wiringpi library) and it works fine.

But I have to port it to C or GO because of performance (speed) reasons. And I definitely prefer doing it in GO.

I have started some basic coding but I have a problem with the part that is expected to receive a predefined amount of bytes. If I suspect well, the problem is with the answer coming from the Modbus device, because it contains 0x00 bytes as well. What I need is a code snippet that reads a predefined amount of bytes (even if it contains several 0x00 bytes as well).

Any help is welcome!

lg007 commented 4 years ago

Problem solved by reading in only one byte at a time.