Serial port Cygwin中Python串行导入错误
当我想使用串行库时,出现以下错误: $./console.py回溯(最近一次调用上次):文件 “/console.py”,第7行,in 导入串行导入错误:没有名为串行的模块 我在Windows7上安装了Cygwin $uname-a CYGWIN_NT-6.1 ES-T20019350 1.7.24(0.269/5/3)2013-08-15 11:59 x86_64 Cygwin 我的Python版本是3: Python 3.2.5(默认值,2013年7月30日,20:11:30) 有人能告诉我怎样才能让这部连续剧正常工作吗?我需要这个来运行串行通信到我的串行端口:Serial port Cygwin中Python串行导入错误,serial-port,cygwin,python-3.2,Serial Port,Cygwin,Python 3.2,当我想使用串行库时,出现以下错误: $./console.py回溯(最近一次调用上次):文件 “/console.py”,第7行,in 导入串行导入错误:没有名为串行的模块 我在Windows7上安装了Cygwin $uname-a CYGWIN_NT-6.1 ES-T20019350 1.7.24(0.269/5/3)2013-08-15 11:59 x86_64 Cygwin 我的Python版本是3: Python 3.2.5(默认值,2013年7月30日,20:11:30) 有人能告诉我
#!/usr/bin/python3
# =======================================
# establish communication using python
# =======================================
import time
import serial
# initialization and open the port
# possible timeout values:
# 1. None: wait forever, block call
# 2. 0: non-blocking mode, return immediately
# 3. x, x is bigger than 0, float allowed, timeout block call
ser = serial.Serial()
#ser.port = "/dev/ttyUSB0"
ser.port = "/dev/ttyS3"
#ser.port = "/dev/ttyS2"
ser.baudrate = 115200
ser.bytesize = serial.EIGHTBITS #number of bits per bytes
ser.parity = serial.PARITY_NONE #set parity check: no parity
ser.stopbits = serial.STOPBITS_ONE #number of stop bits
#ser.timeout = None #block read
ser.timeout = 0 #non-block read
#ser.timeout = 2 #timeout block read
ser.xonxoff = False #disable software flow control
ser.rtscts = False #disable hardware (RTS/CTS) flow control
ser.dsrdtr = False #disable hardware (DSR/DTR) flow control
ser.writeTimeout = 2 #timeout for write
try:
ser.open()
except getopt.GetoptError as e:
print ("error openning serial port",str(e))
exit()
if ser.isOpen():
try:
ser.flushInput() #flush input buffer, discarding all its contents
ser.flushOutput()#flush output buffer, aborting current output
#and discard all that is in buffer
#write data
ser.write("ac_spi_slash 3\x0D")
print("ac_spi_slash 3 sent\x0D")
time.sleep(0.5) #give the serial port sometime to receive the data
numOfLines = 0
while True:
response = ser.readline()
print("read data: " + response)
numOfLines = numOfLines + 1
if (numOfLines >= 5):
break
ser.close()
except getopt.GetoptError as e1:
print ("error communicating...: ",str(e1));
else:
print ("cannot open serial port ")
我最近在处理这个问题,你可能也有同样的问题 此线程指出了一个问题,即使用python.org安装程序进行python的标准安装不能很好地与cygwin配合使用,即使您正确设置了path变量: 我的解决方案是允许cygwin安装程序进行单独的python安装: cygwin setup.exe->然后选择“python:python语言解释器” 然后抓取pyserial库(通常只是一个名为“serial”的文件夹)并复制到C:\cygwin\lib\pythonX.X\site包\
这样,交互模式工作,pyserial软件包可以在标准cygwin搜索路径中找到。您尝试过安装它吗?如何在cygwin中安装它?Cygwin没有apt get install命令!这是pySerial吗?安装它的方法有很多种-