Communication with USBRLY82
I am trying to connect to a USBRLY82 (RobotElectronics) board over serial port (ttyACM0).
I have no problem sending commands to the board and action relays on it. Where I am facing issues is reading the DI status from the board and that is because to read the state of those DI’s I need to first Write() to the board and the board will send back the status once it receives the command. The value returned by the board is the value that I am trying to get. I can not get it through Read() since the Write() is non-blocking and by the time it get’s executed, the data sent by the USBRLY82 board as an answer, is not there anymore.
Is there anything that can help me with this? The read and write commands in REXLANG C-like are non-blocking. Can you please let me know if there is anything that I can do about it?
Thanks for your question. You need to create a kind of state machine which basically does the following (one line = one task period):
- Write() - send a read request to the device
- Read() - save received data and length into a global buffer/variable and distinguish if the received message is complete
- Retry and repeat Read() if the previously received message was not complete
You will need to introduce a timeout - it can happen that you lost some data so there should be some timeout when you say "Message incomplete, resend the read request".