在 Python 中实施 serialPort.write

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”...