Why characters received in serial connection only after pressing enter?

后端 未结 1 1408
伪装坚强ぢ
伪装坚强ぢ 2020-12-11 21:49

I have a simple PC to board connection using serial (9600, no parity, 8 bits, no hw flow) I opened simple terminal *with teraterm) in PC and enter keys in teraterm and in bo

相关标签:
1条回答
  • 2020-12-11 22:42

    but I see the characters in the board console, only after pressing "enter" in teraterm

    The behavior you describe is characteristic of canonical read (aka reading lines).
    The behavior you seem to want is called non-canonical read (aka raw read or binary read).

    1. why are the characters received in Linux driver only when pressing enter key ?

    No, the Linux serial port driver is receiving every character as it is appears on the wire.
    Each character is buffered (typically in DMA-able memory), and then forwarded to a line discipline handler, which is also buffering the received data.
    A canonical read() syscall by the userland program is blocked until the line discipline handler detects a line termination character.

    1. Is there some way to receive the characters without pressing the enter key ?

    Yes, before issuing the cat command, configure the serial port to non-canonical mode:

    stty -F /dev/tty05 raw
    

    or more likely the correct device node is

    stty -F /dev/ttyO5 raw
    

    Or use the termios interface to configure the serial port to non-canonical mode in a userspace program on the board. Sample code is here.

    Documentation on how to properly program a serial port are Serial Programming Guide for POSIX Operating Systems and Setting Terminal Modes Properly.

    0 讨论(0)
提交回复
热议问题