【发布时间】:2014-11-18 21:45:57
【问题描述】:
我正在尝试使用 PySerial 来接受来自 RFID 阅读器的输入。根据here: 的答案,我尝试使用 WinObj 并发现一些奇怪的东西:GLOBAL??? 文件夹中没有 COM3 端口指向“更多驱动程序特定”的东西。但是,当我运行命令python -m serial.tools.list_ports 时,它会抛出COM3。当我尝试一个简单的程序时:
import serial
ser = serial.Serial()
ser.port = 2
print(ser)
ser.open()
我得到以下输出:
Serial<id=0x45e8198, open=False>(port='COM3', baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=None, xonxoff=False, rtscts=False, dsrdtr=False)
serial.serialutil.SerialException: could not open port 'COM3': FileNotFoundError(2, 'The system cannot find the file specified.', None, 2)
所以,我知道 PySerial 正在正确的位置寻找我的阅读器,并且根据两个不同的来源(设备管理器和命令行),设备正在注册。然而我仍然收到这个错误。到底是怎么回事?我在 Windows 8.1 上使用 Python 3.3。
编辑:这个错误实际上是我从 python 的命令行得到的。我从制作和运行上述程序中得到的结果是:
AttributeError: 'function' object has no attribute 'Serial.'
对此我也很感激。
【问题讨论】:
标签: python