bash: serial port write THEN read
I need to communicate with a target device using serial port and want to access it with bash commands solely. I poll the device by sending a string and then wait for a response string.
Setting up the connection using stty works fine and I can send messages to the device simply by "abcdef > /dev/ttyS2", which are well received. I'm facing a problem when trying a WRITE/READ operation:
It works, if I send the message and put a breakpoint in my device before it responds. That way "read -n20 ..." will receive the 20 characters perfectly.
I can only guess that the read command is executed too late.
Unfortunately I can't get into read mode before sending, since then I'm told "Permission denied".
Is there any way to open /dev/ttyS2 for both writing and reading? Or can I redirect input buffering in a way, that no messages will get lost?
Appreciating your suggestions.
Your problem most likely has to do with the way serial ports tend to be configured by default. It is waiting for a line terminated by an end-of-line character(s). You probably want to get it into raw mode.
I would consider bash to be a poor choice for developing serial communications applications.
|All times are GMT -5. The time now is 08:38 PM.|