Hi folks,
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:
Code:
abcdef > /dev/ttyS2 ; read -n20 RESPONSE < /dev/ttyS2 ; echo $RESPONSE
This way I'll end up stuck waiting for a response, although I know that my target device sends more than 20 characters.
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.