Hi all,
Last few days ago,
I facing the same issue with my windows 7 64bit...
it work well with windows XP 32-bit...
FYI, I’m using python 2.6 amd64 bit as my core programming tools
currently, I’m start study/learn some arduino robotic and rewrite
Python-Arduino API
I just do a quick anatomy to the Pyserial code and diff. of the (Ctypes) Handle
range...
found both are diff range with same Kernel32 dll function call,
for 64-bit, ctypes.wintypes.HANDLE(-1) ==> c_void_p(18446744073709551615L)
in 32 bit, give c_void_p(4294967295L)
so what I guest it cause by Platform and environments issues.
below is what I did and modifies on 64-bit server:
a.. win32.py (C:\Python26\Lib\site-packages\serial)
a.. use HRESULT to replace HANDLE for kernel32 function handle return
b.. serialwin32.py (C:\Python26\Lib\site-packages\serial)
a.. use win32file, pywintypes, win32event to rewrite readfile and writefile
function
it seem work now for my 64-bit server, somehow I didn’t put some effort on
self.timeout == 0 for serial as I don’t have enough time for it
that I will leave it back to Pyserial Owner to take the honor for that
hope this will help to all open source member... (that why I’m like python most)
Regards,
Cheeng Shu Chin
#! python
# Python Serial Port Extension for Win32, Linux, BSD, Jython
# serial driver for win32
# see __init__.py
#
# (C) 2001-2009 Chris Liechti
# this is distributed under a free software license, see license.txt
#
# Initial patch to use ctypes by Giovanni Bajo
import ctypes
import win32
import win32file
import pywintypes
import win32event
#from ctypes.wintypes import HWND
from serialutil import *
#from pywin32_testutil import str2bytes
def device(portnum):
"""Turn a port number into a device name"""
return 'COM%d' % (portnum+1) # numbers are transformed to a string
class Win32Serial(SerialBase):
"""Serial port implementation for Win32 based on ctypes."""
BAUDRATES = (50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
9600, 19200, 38400, 57600, 115200)
def __init__(self, *args, **kwargs):
self.hComPort = None
SerialBase.__init__(self, *args, **kwargs)
def open(self):
"""Open port with current settings. This may throw a SerialException
if the port cannot be opened."""
if self._port is None:
raise SerialException("Port must be configured before it can be
used.")
# the "\\.\COMx" format is required for devices other than COM1-COM8
# not all versions of windows seem to support this properly
# so that the first few ports are used with the DOS device name
port = self.portstr
try:
if port.upper().startswith('COM') and int(port[3:]) > 8:
port = '.\\' + port
except ValueError:
# for like COMnotanumber
pass
self.hComPort = win32.CreateFile(port,
win32.GENERIC_READ | win32.GENERIC_WRITE,
0, # exclusive access
None, # no security
win32.OPEN_EXISTING,
win32.FILE_ATTRIBUTE_NORMAL | win32.FILE_FLAG_OVERLAPPED,
0)
#self.pComPort=pywintypes.HANDLE(self.hComPort)
#self.cComPort=HWND(self.hComPort)
#print ctypes.sizeof(self.pComPort)
#print ctypes.sizeof(self.hComPort)
if self.hComPort == win32.INVALID_HANDLE_VALUE:
self.hComPort = None# 'cause __del__ is called anyway
raise SerialException("could not open port %s: %s" % (self.portstr,
ctypes.WinError()))
# Setup a 4k buffer
win32.SetupComm(self.hComPort, 4096, 4096)
# Save original timeout values:
self._orgTimeouts = win32.COMMTIMEOUTS()
win32.GetCommTimeouts(self.hComPort, ctypes.byref(self._orgTimeouts))
self._rtsState = win32.RTS_CONTROL_ENABLE
self._dtrState = win32.DTR_CONTROL_ENABLE
self._reconfigurePort()
# Clear buffers:
# Remove anything that was there
win32.PurgeComm(self.hComPort,
win32.PURGE_TXCLEAR | win32.PURGE_TXABORT |
win32.PURGE_RXCLEAR | win32.PURGE_RXABORT)
self._overlappedRead = win32.OVERLAPPED()
self._overlappedRead.hEvent = win32.CreateEvent(None, 1, 0, None)
self._overlappedWrite = win32.OVERLAPPED()
#~ self._overlappedWrite.hEvent = win32.CreateEvent(None, 1, 0, None)
self._overlappedWrite.hEvent = win32.CreateEvent(None, 0, 0, None)
self._isOpen = True
def _reconfigurePort(self):
"""Set communication parameters on opened port."""
if not self.hComPort:
raise SerialException(&qu