I have a project that uses the Tx/Rx pins to transmit through an RS-485 chip. I'm using GPIO18 as a flow control. As it stands when I go to transmit the following sequence occurs.
1 - Calculate transmission time(ms) based on baudrate and buffer size x = f(y)
2 - Set to GPIO 18 to transmit
3 - Send the buffer data to be written
4 - Set GPIO 18 to receive after x time has passed.
This process works, but I would feel better about the resilience of the application if I could somehow check Tx/Rx to confirm that the buffer has been written rather than hoping my timeout processes in the correct amount of time.
Application is written in node using GPIO and serialport libraries.
Any advice would be greatly appreciated. As always, thanks guys.
For the project I was working on I ended up moving to an RS485 with flow control hardware, but I was able to find a solution to my problem in a Node library SerialPort
They have a function drain that polls the OS to see if the serial port has transmitted all of it's data
It works...however there is a ≈20ms delay in the response coming from the OS on a Raspberry pi 3 running Raspbian Stretch with a few other tasks running. That was too much for my needs, but for some (most probably) that is sufficient.
Note: With a 20ms delay you do run the risk of collision on a line. I was running a Modbus scheme with the Pi device as the master. I was getting a response from the slave device about 5ms after I sent out the request, but was continuing to drive the line high waiting for the OS to tell me it had written everything on the port.
Thanks everyone for the help.