Created
December 11, 2017 08:31
-
-
Save nannja/44554e7d90f6c98af3df4c5dd0f412d6 to your computer and use it in GitHub Desktop.
RaspberryPiでRS232C機器を制御した ref: https://qiita.com/nannja/items/9d30a810b073a97a7ae5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/dev/ttyUSB0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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