Implement serialPort.write in Python



在我的javascript代码中,我打开arudino灯,如下所示:

var serialport = require("serialport");
var SerialPort = require("serialport").SerialPort;
serialPort.write("1", function(err, results) 

如何在Python中实现此方法?

import serial
port,baud = "/dev/ttyUSB0",9600 #just an example (linux)
port,baud = "COM5",9600 #just an example (win)
ser = serial.serial(port,baud,timeout=1)
ser.write("1")
print "RESP 1:",ser.read(10000)
ser.write("2")
print "RESP 2:",ser.read(10000)

我想。。。。看起来你只想把"1"发送到串行端口,后面跟着"2"。。。

最新更新