Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Signal end of file in serial communication

Tags:

linux

terminal

What control character do I need to send to make the serial client receive end of file or end of stream result? Is there such a thing? For example if I simply cat a serial device into a file, is it somehow possible to make the cat program receive end of file when a certain character is sent so that it exists? Some kind of stty setting perhaps?

(I'm not even sure how to word this question) Basically I want to define a character that when sent by the sending device will make the read call in the receiving device return end of file. I suppose it must be a terminal setting as opposed to being a feature of the terminal program.

like image 590
Martin Avatar asked Nov 15 '25 14:11

Martin


1 Answers

The key was to disable raw mode on the terminal explicitly and then send \x04 character (end of transmission) from the sending uart to signal that the stream is over.

stty -F <device> -raw <baud> 
cat <device>

"cat" will exit when sending side sends 0x04 value which is handled internally by serial driver instead of being passed to the program when terminal is not in raw mode.

like image 173
Martin Avatar answered Nov 18 '25 16:11

Martin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!