在Python中实现serialPort.write

时间:2015-02-09 19:26:39

标签: python serial-port

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

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

如何在Python中实现此方法?

1 个答案:

答案 0 :(得分:0)

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