2018年3月15日木曜日

Bash on Ubuntu on Windowsでシリアルポートを使う

現在のBash on Ubuntu on Windowsではシリアルポートが使えるようです。
Windows Subsystem for Linuxでのシリアルポートサポート
https://opcdiary.net/?p=35053

WSLでシリアル通信をする
http://matsuneko22.hateblo.jp/entry/2017/12/09/144803

Serial Support on the Windows Subsystem for Linux
https://blogs.msdn.microsoft.com/wsl/2017/04/14/serial-support-on-the-windows-subsystem-for-linux/
上記のMSDNの資料によれば、以下のように見えるようです。
In WSL, the lxcore driver maps COM ports to Linux devices by the COM port number so /dev/ttyS<N> is tied to COM<N>.  More specifically, the mapping is on the minor number, so minor number 65 (/dev/ttyS1) is COM1, 66 (/dev/ttyS2) is COM2, and so forth.  Since pty, tty, and ttyS share a terminal library code base, ttyS will behave similarly but also support the following termios settings which are simply mapped to Windows serial driver ioctls:
  • Standard baud rates - B*
  • Stop bits - CSTOPB
  • Word length - CSIZE
  • Parity checking - PARENB, PARODD, CMSPAR, INPCK
  • Software flow control - IXON, IXOFF
  • Hardware flow control - CRTSCTS, CLOCAL
  • Control characters - VSTART, VSTOP, VEOF
/dev/ttysS1などで使えるのですね。cuなどでルーターに接続できそうです。