谷动谷力

 找回密码
 立即注册
查看: 1716|回复: 0
打印 上一主题 下一主题
收起左侧

【linux】OPENWRT串口通信stty安装使用

[复制链接]
跳转到指定楼层
楼主
发表于 2022-7-5 23:24:59 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
【linux】OPENWRT串口通信stty安装使用

概述

本文讲述如何在【linux】OPENWRT环境下安装使用串口通信工具stty

stty安装--在线安装

在线安装 前题先连接网络

更新opkg


Openwrt是基于opkg包管理,安装前先更新opkg,注意要连接网络
  1. root@SunLink:~# opkg update
  2. Downloading http://downloads.openwrt.org/chaos_calmer/15.05.1/ramips/mt7628/pack                                                                                                        ages/base/Packages.gz.
  3. Updated list of available packages in /var/opkg-lists/chaos_calmer_base.
  4. Downloading http://downloads.openwrt.org/chaos_calmer/15.05.1/ramips/mt7628/pack                                                                                                        ages/base/Packages.sig.
  5. Signature check passed
  6. ......
  7. Downloading http://downloads.openwrt.org/chaos_calmer/15.05.1/ramips/mt7628/pack                                                                                                        ages/telephony/Packages.sig.
  8. Signature check passed.
复制代码


stty安装



执行命令:
  1. opkg install coreutils-stty
复制代码
  1. root@SunLink:~# opkg install coreutils-stty
  2. Installing coreutils-stty (8.23-1) to root...
  3. Downloading http://downloads.openwrt.org/chaos_calmer/15.05.1/ramips/mt7628/pack                                                                                                        ages/packages/coreutils-stty_8.23-1_ramips_24kec.ipk.
  4. Installing coreutils (8.23-1) to root...
  5. Downloading http://downloads.openwrt.org/chaos_calmer/15.05.1/ramips/mt7628/pack                                                                                                        ages/packages/coreutils_8.23-1_ramips_24kec.ipk.
  6. Configuring coreutils.
  7. Configuring coreutils-stty.
复制代码


stt查看帮助

不会新命令都执行一下加--help参数就没错
  1. root@SunLink:~# stty --help
  2. Usage: stty [-F DEVICE | --file=DEVICE] [SETTING]...
  3. or:  stty [-F DEVICE | --file=DEVICE] [-a|--all]
  4. or:  stty [-F DEVICE | --file=DEVICE] [-g|--save]
  5. Print or change terminal characteristics.
  6. Mandatory arguments to long options are mandatory for short options too.
  7. -a, --all          print all current settings in human-readable form
  8. -g, --save         print all current settings in a stty-readable form
  9. -F, --file=DEVICE  open and use the specified DEVICE instead of stdin
  10. --help     display this help and exit
  11. --version  output version information and exit
  12. Optional - before SETTING indicates negation.  An * marks non-POSIX
  13. settings.  The underlying system defines which settings are available.
  14. Special characters:
  15. dsusp CHAR    CHAR will send a terminal stop signal once input flushed

  16. eof CHAR      CHAR will send an end of file (terminate the input)
  17. eol CHAR      CHAR will end the line
  18. eol2 CHAR     alternate CHAR for ending the line

  19. erase CHAR    CHAR will erase the last character typed
  20. intr CHAR     CHAR will send an interrupt signal
  21. kill CHAR     CHAR will erase the current line
  22. lnext CHAR    CHAR will enter the next character quoted

  23. quit CHAR     CHAR will send a quit signal
  24. rprnt CHAR    CHAR will redraw the current line

  25. start CHAR    CHAR will restart the output after stopping it
  26. stop CHAR     CHAR will stop the output
  27. susp CHAR     CHAR will send a terminal stop signal
  28. swtch CHAR    CHAR will switch to a different shell layer
  29. werase CHAR   CHAR will erase the last word typed

  30. Special settings:
  31. N             set the input and output speeds to N bauds
  32. cols N        tell the kernel that the terminal has N columns
  33. columns N     same as cols N

  34. ispeed N      set the input speed to N
  35. line N        use line discipline N

  36. min N         with -icanon, set N characters minimum for a completed read
  37. ospeed N      set the output speed to N
  38. rows N        tell the kernel that the terminal has N rows
  39. size          print the number of rows and columns according to the kernel

  40. speed         print the terminal speed
  41. time N        with -icanon, set read timeout of N tenths of a second
  42. Control settings:
  43. [-]clocal     disable modem control signals
  44. [-]cread      allow input to be received
  45. [-]crtscts    enable RTS/CTS handshaking
  46. [-]cdtrdsr    enable DTR/DSR handshaking

  47. csN           set character size to N bits, N in [5..8]
  48. [-]cstopb     use two stop bits per character (one with '-')
  49. [-]hup        send a hangup signal when the last process closes the tty
  50. [-]hupcl      same as [-]hup
  51. [-]parenb     generate parity bit in output and expect parity bit in input
  52. [-]parodd     set odd parity (or even parity with '-')
  53. [-]cmspar     use "stick" (mark/space) parity

  54. Input settings:
  55. [-]brkint     breaks cause an interrupt signal
  56. [-]icrnl      translate carriage return to newline
  57. [-]ignbrk     ignore break characters
  58. [-]igncr      ignore carriage return
  59. [-]ignpar     ignore characters with parity errors
  60. [-]imaxbel    beep and do not flush a full input buffer on a character

  61. [-]inlcr      translate newline to carriage return
  62. [-]inpck      enable input parity checking
  63. [-]istrip     clear high (8th) bit of input characters
  64. [-]iutf8      assume input characters are UTF-8 encoded
  65. [-]iuclc      translate uppercase characters to lowercase
  66. [-]ixany      let any character restart output, not only start character

  67. [-]ixoff      enable sending of start/stop characters
  68. [-]ixon       enable XON/XOFF flow control
  69. [-]parmrk     mark parity errors (with a 255-0-character sequence)
  70. [-]tandem     same as [-]ixoff
  71. Output settings:
  72. bsN           backspace delay style, N in [0..1]
  73. crN           carriage return delay style, N in [0..3]
  74. ffN           form feed delay style, N in [0..1]
  75. nlN           newline delay style, N in [0..1]
  76. [-]ocrnl      translate carriage return to newline
  77. [-]ofdel      use delete characters for fill instead of NUL characters
  78. [-]ofill      use fill (padding) characters instead of timing for delays
  79. [-]olcuc      translate lowercase characters to uppercase
  80. [-]onlcr      translate newline to carriage return-newline
  81. [-]onlret     newline performs a carriage return
  82. [-]onocr      do not print carriage returns in the first column

  83. [-]opost      postprocess output
  84. tabN          horizontal tab delay style, N in [0..3]
  85. tabs          same as tab0
  86. -tabs         same as tab3
  87. vtN           vertical tab delay style, N in [0..1]

  88. Local settings:
  89. [-]crterase   echo erase characters as backspace-space-backspace
  90. crtkill       kill all line by obeying the echoprt and echoe settings
  91. -crtkill      kill all line by obeying the echoctl and echok settings
  92. [-]ctlecho    echo control characters in hat notation ('^c')

  93. [-]echo       echo input characters
  94. [-]echoctl    same as [-]ctlecho

  95. [-]echoe      same as [-]crterase
  96. [-]echok      echo a newline after a kill character
  97. [-]echoke     same as [-]crtkill

  98. [-]echonl     echo newline even if not echoing other characters
  99. [-]echoprt    echo erased characters backward, between '' and '/'

  100. [-]icanon     enable erase, kill, werase, and rprnt special characters
  101. [-]iexten     enable non-POSIX special characters
  102. [-]isig       enable interrupt, quit, and suspend special characters
  103. [-]noflsh     disable flushing after interrupt and quit special characters
  104. [-]prterase   same as [-]echoprt
  105. [-]tostop     stop background jobs that try to write to the terminal
  106. [-]xcase      with icanon, escape with '' for uppercase characters

  107. Combination settings:
  108. [-]LCASE      same as [-]lcase

  109. cbreak        same as -icanon
  110. -cbreak       same as icanon
  111. cooked        same as brkint ignpar istrip icrnl ixon opost isig
  112. icanon, eof and eol characters to their default values
  113. -cooked       same as raw
  114. crt           same as echoe echoctl echoke
  115. dec           same as echoe echoctl echoke -ixany intr ^c erase 0177
  116. kill ^u
  117. [-]decctlq    same as [-]ixany

  118. ek            erase and kill characters to their default values
  119. evenp         same as parenb -parodd cs7
  120. -evenp        same as -parenb cs8
  121. [-]lcase      same as xcase iuclc olcuc

  122. litout        same as -parenb -istrip -opost cs8
  123. -litout       same as parenb istrip opost cs7
  124. nl            same as -icrnl -onlcr
  125. -nl           same as icrnl -inlcr -igncr onlcr -ocrnl -onlret
  126. oddp          same as parenb parodd cs7
  127. -oddp         same as -parenb cs8
  128. [-]parity     same as [-]evenp
  129. pass8         same as -parenb -istrip cs8
  130. -pass8        same as parenb istrip cs7
  131. raw           same as -ignbrk -brkint -ignpar -parmrk -inpck -istrip
  132. -inlcr -igncr -icrnl  -ixon  -ixoff  -iuclc  -ixany
  133. -imaxbel -opost -isig -icanon -xcase min 1 time 0
  134. -raw          same as cooked
  135. sane          same as cread -ignbrk brkint -inlcr -igncr icrnl -iutf8
  136. -ixoff -iuclc -ixany imaxbel opost -olcuc -ocrnl onlcr
  137. -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
  138. isig icanon iexten echo echoe echok -echonl -noflsh
  139. -xcase -tostop -echoprt echoctl echoke, all special
  140. characters to their default values
  141. Handle the tty line connected to standard input.  Without arguments,
  142. prints baud rate, line discipline, and deviations from stty sane.  In
  143. settings, CHAR is taken literally, or coded as in ^c, 0x37, 0177 or
  144. 127; special values ^- or undef used to disable special characters.
  145. GNU coreutils online help: http://www.gnu.org/software/coreutils/
  146. Report stty translation bugs to http://translationproject.org/team/
  147. For complete documentation, run: info coreutils 'stty invocation'
复制代码

stty应用举例

设置串口波特率


老规矩串口使用前先配置波特率
  1. root@SunLink:~# stty -F /dev/ttyS1 raw speed 115200
  2. 115200
复制代码

查看串口配置
  1. root@SunLink:~# stty -F /dev/ttyS2
  2. speed 115200 baud; line = 0;
  3. intr = ; quit = ; erase = ; kill = ; eof = ; susp = ;
  4. rprnt = ; werase = ; lnext = ; flush = ; min = 1; time = 0;
  5. -brkint -icrnl -imaxbel
  6. -opost
  7. -isig -icanon -iexten -echo
复制代码

Shell命令读串口(接收数据)命令
  1. cat /dev/ttyS1 & #后台运行
复制代码

Shell命令写串口(发送数据)命令
  1. echo -e "ttyS1 Send.." > /dev/ttyS1
复制代码



+10
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|深圳市光明谷科技有限公司|光明谷商城|Sunshine Silicon Corpporation ( 粤ICP备14060730号|Sitemap

GMT+8, 2024-11-18 08:19 , Processed in 0.178676 second(s), 42 queries .

Powered by Discuz! X3.2 Licensed

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表