当我尝试导入序列时,我收到以下错误:
Traceback (most recent call last):
File "C:\Documents and Settings\eduardo.pereira\workspace\thgspeak\tst.py", line 7, in <module>
import serial
File "C:\Python27\lib\site-packages\serial\__init__.py", line 27, in <module>
from serial.serialwin32 import Serial
File "C:\Python27\lib\site-packages\serial\serialwin32.py", line 15, in <module>
from serial import win32
File "C:\Python27\lib\site-packages\serial\win32.py", line 182, in <module>
CancelIoEx = _stdcall_libraries['kernel32'].CancelIoEx
File "C:\Python27\lib\ctypes\__init__.py", line 375, in __getattr__
func = self.__getitem__(name)
File "C:\Python27\lib\ctypes\__init__.py", line 380, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'CancelIoEx' not found
我安装了最新版本的pySerial,Python 2.7在WinXP笔记本电脑上运行。到处尝试,发现没有类似的问题。那有什么解决方案吗? 提前谢谢......
答案 0 :(得分:3)
您正在使用的pySerial版本正在尝试调用仅在Windows Vista中可用的function,而您正在运行Windows XP。
使用较旧版本的pySerial可能值得尝试。
有问题的代码是added to pySerial on 3 May 2016,所以在此之前的版本可能是一个好的开始。
答案 1 :(得分:3)
旧版本似乎不可用。但是,这对我有用(假设nanpy版本3.1.1):
_cancel_overlapped_io()
,cancel_read()
,cancel_write()
在第436-455行,几乎位于文件的底部(Python)
def _close(self):
"""internal close port helper"""
if self._port_handle is not None:
# Restore original timeout values:
win32.SetCommTimeouts(self._port_handle, self._orgTimeouts)
# Close COM-Port:
if self._overlapped_read is not None:
win32.CloseHandle(self._overlapped_read.hEvent)
self._overlapped_read = None
if self._overlapped_write is not None:
win32.CloseHandle(self._overlapped_write.hEvent)
self._overlapped_write = None
win32.CloseHandle(self._port_handle)
self._port_handle = None
此外,在开始通信时创建一个非默认的串行连接,否则你将被绑定到一些linux设备:
a = ArduinoApi(SerialManager("COM5:"))
for i in range(10):
a.pinMode(13, a.OUTPUT)
a.digitalWrite(13, a.HIGH)
# etc.
答案 2 :(得分:1)
并在串口\ win32.py评论中
#CancelIoEx = _stdcall_libraries['kernel32'].CancelIoEx
#CancelIoEx.restype = BOOL
#CancelIoEx.argtypes = [HANDLE, LPOVERLAPPED]