PySerial 和 IronPython - 出现奇怪的错误
我有一个设备连接到 COM31。我创建串行连接所需的代码看起来非常简单
port = 31
trex_serial = serial.Serial(port - 1, baudrate=19200, stopbits=serial.STOPBITS_ONE, timeout=1)
当我使用Python2.6运行它时,愚蠢的代码可以工作,但是当我使用IronPython2.6.1执行时,这就是我得到的:
Traceback (most recent call last):
File "c:\Python26\lib\site-packages\serial\serialutil.py", line 188, in __init__
File "c:\Python26\lib\site-packages\serial\serialutil.py", line 236, in setPort
File "c:\Python26\lib\site-packages\serial\serialcli.py", line 139, in makeDeviceName
File "c:\Python26\lib\site-packages\serial\serialcli.py", line 17, in device
IndexError: index out of range: 30
我不确定发生了什么。 PySerial 明确表示它符合 IronPython 标准。 有什么想法我做错了什么吗?
I have a device connected to COM31. And the code that I need to create a serial connection looks very simple
port = 31
trex_serial = serial.Serial(port - 1, baudrate=19200, stopbits=serial.STOPBITS_ONE, timeout=1)
The foollowing code works when I run it using Python2.6, but when executed by IronPython2.6.1, this is what I get:
Traceback (most recent call last):
File "c:\Python26\lib\site-packages\serial\serialutil.py", line 188, in __init__
File "c:\Python26\lib\site-packages\serial\serialutil.py", line 236, in setPort
File "c:\Python26\lib\site-packages\serial\serialcli.py", line 139, in makeDeviceName
File "c:\Python26\lib\site-packages\serial\serialcli.py", line 17, in device
IndexError: index out of range: 30
I am not sure what is going on. PySerial clearly says that it is IronPython compliant.
Any ideas what am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
IronPython 正在询问 .NET 端口是什么。它们的列举方式不同。您很可能要求打开一个就 IronPython/.NET 而言不存在的连接。要找出“真实”端口号,请使用从 pySerial 扫描示例修改的以下代码。然后使用列出的 COM 旁边的号码。
对我来说,输出如下所示:
(0) COM9
(1) COM15
(2) COM16
(3) COM1
(4) COM15
然后,当您尝试打开连接时,使用左侧的数字而不是实际的 COMportNumber - 1。例如,我需要打开到 COM15 的连接,因此使用上面的扫描:
此外,一旦连接,pySerial 将期望字节写入 connectio,而不是字符串。所以请确保您像这样发送:
IronPython is asking .NET what the ports are. They are enumerated differently. Most likely you are asking to open a connection that doesn't exist as far as IronPython/.NET is concerned. To find out the "real" port number, use the following code modified from the pySerial scan examples. Then use the number next to the listed COM.
The output looks like this for me:
(0) COM9
(1) COM15
(2) COM16
(3) COM1
(4) COM15
Then when you try to open the connection, use the number on the left NOT the actual COMportNumber - 1. For instance I need to open a connection to COM15, so using the above scan:
Also, once you are connected, pySerial will expect bytes to write to the connectio, not strings. So make sure you send like this: