OPENWRT串列埠通訊的實現
阿新 • • 發佈:2019-02-10
【轉自 http://rmingwang.com/720n-openwrt-stty-uart.html】
【轉自 http://blog.csdn.net/yfykisssky/article/details/45817971】
串列埠設定
串列埠名稱(不同機型不同)
開機啟動資訊可以看到串列埠的名稱,例如以下串列埠啟動資訊:
Serial: 8250/16550 driver, 1 ports, IRQ sharing disabled ar933x-uart: ttyATH0 at MMIO 0x18020000 (irq = 11) is a AR933X UART console [ttyATH0] enabled, bootconsole disabled
可以看到串列埠的名稱為ttyATH0,此時可以ls /dev/檢視確認。
stty 串列埠波特率設定
opkg update //<a target=_blank target="_blank" href="http://www.zishuo.net/tag/%E6%9B%B4%E6%96%B0/" title="更新" style="color: rgb(0, 119, 187); text-decoration: none;">更新</a>軟體列表 opkg install coreutils-stty //<a target=_blank target="_blank" href="http://www.zishuo.net/tag/%E5%AE%89%E8%A3%85/" title="安裝" style="color: rgb(0, 119, 187); text-decoration: none;">安裝</a>stty stty -F /dev/ttyATH0 raw speed 9600 //設定ttyATH0串列埠的波特率為9600 echo "hello" > /dev/ttyATH0 //向串列埠輸出字元"hello" cat /dev/ttyATH0 //讀取串列埠
遮蔽串列埠的系統顯示(消除亂碼和串列埠BusyBox 影響)
編輯檔案:vi /etc/inittab
::sysinit:/etc/init.d/rcS S boot ::shutdown:/etc/init.d/rcS K shutdown ttyS0::askfirst:/bin/ash --login #ttyATH0::askfirst:/bin/ash --login #註釋此行
將串列埠波特率設定新增到開機啟動
編輯檔案:vi /etc/init.d/usart
檔案屬性:chmod 777 /etc/init.d/usart
#!/bin/sh /etc/rc.common #/etc/init.d/usart START=80 start() { /usr/bin/stty -F /dev/ttyS0 raw speed 9600 } stop(){ killall usart }
啟用開機啟動:/etc/init.d/usart enable