Skip to content

Instantly share code, notes, and snippets.

@nannja
Created December 11, 2017 08:31
Show Gist options
  • Save nannja/44554e7d90f6c98af3df4c5dd0f412d6 to your computer and use it in GitHub Desktop.
Save nannja/44554e7d90f6c98af3df4c5dd0f412d6 to your computer and use it in GitHub Desktop.
RaspberryPiでRS232C機器を制御した ref: https://qiita.com/nannja/items/9d30a810b073a97a7ae5
/dev/ttyUSB0
import serial # PySerial
dev = "/dev/ttyUSB0" # デバイス名
rate = 9600 # レート (bps)
ser = serial.Serial(dev, rate, timeout=10)
string = "Hello World"
string = string + "\r\n" # ターミネーターを付ける
ser.write(string) # コマンド送信
res = ser.readline() # コマンド受信
res = res.encode() # エンコード
print res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment