(Linux) (Bash) Communcating to telnet or serial port

[Telnet]

  • 寫入command至telnet 終端:

    (echo "command") | telnet 192.168.1.1
    

[Serial port]

  • 使用stty設定serial port

    stty -F /dev/ttyS0 speed 9600 -icrnl
    stty -F <dev> speed  <baudrate> -icrnl
    

    *-crnl: translate carriage return to a newline

  • 寫入 command至serial port:

    (echo "command") | > /dev/ttyS0
    
  • 讀取serial port上回傳值:

    cat /dev/ttyS0
    read /dev/ttyS0 > /dev/tty