2016-07-08 51 views
3

當我嘗試導入序列我碰到下面的錯誤:錯誤Python的串行進口

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的筆記本電腦。到處嘗試,發現沒有類似的問題。有沒有解決方案? 在此先感謝...

回答

3

您正在使用的pySerial版本試圖調用僅在Windows Vista中可用的function,而您正在運行Windows XP。

這可能是值得嘗試使用舊版本的pySerial。

有問題的代碼是added to pySerial on 3 May 2016,所以之前的版本可能是一個好的開始。

+0

誠如,有一箇舊版本(3.0),它的工作正常。謝謝! – Hagah

2

舊版本似乎不可用。但是,這個工作對我來說(假設nanpy版本3.1.1):

  1. 打開文件\ LIB \站點包\序列\ serialwin32.py
  2. DELETE方法_cancel_overlapped_io()cancel_read()cancel_write()在線路436-455幾乎在文件
  3. 變化方法_close()ALS的鈕如下:

(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. 
1

,串行\ win32.py評論

#CancelIoEx = _stdcall_libraries['kernel32'].CancelIoEx 
#CancelIoEx.restype = BOOL 
#CancelIoEx.argtypes = [HANDLE, LPOVERLAPPED] 
+0

請問您能否擴展您的答案並解釋如何解決問題? – zuazo