Python Serial Port Example Windows Application
Python Serial Example Windows
I am trying to interface with a serial WWAN modem (for diagnostics /signal strength measurement purposes). This is via the onboard COM1 (115200-8-n-1) on my desktop, the connection works via PuTTY. I can script the AT commands using Python, but I am having a tough time getting it to open the serial port.I have installed Python 2.7.1 and PySerial according to instructions.
I am the local administrator of my machine and have run Python with and without admin privileges, but I get the following when I try to open the port: Python 2.7.1 (r271:86832, Nov 27 2010, 17:19:03) MSC v.1500 64 bit (AMD64) on win32Type 'help', 'copyright', 'credits' or 'license' for more information. import serial s = serial.Serial(.
) s.openTraceback (most recent call last):File ', line 1, in File 'C:Python27libsite-packagesserialserialwin32.py', line 56, in openraise SerialException('could not open port%s:%s'% (self.portstr, ctypes.WinError))serial.serialutil.SerialException: could not open port COM1: Error 5 Access isdenied.It is my understanding that 8-N-1 is the default, and even when I try to set them manually it throws the same exception.Can anyone offer advice?Thanks in advance. Thanks for the response @aix. I tried a different syntax in a new elevated py session, and am now getting a slightly different error: se = serial.Serial se.baudrate = 115200 se.bytesize = 8 se.stopbits = 1 se.xonxoff = 0 se.rtscts = 0 se.port = 0 # = COM1 parity=serial.PARITYNONE se.isOpen False se.open se.write('ATrn') Traceback (most recent call last). Raise SerialException('WriteFile failed (%s)'% ctypes.WinError) serial.serialutil.SerialException: WriteFile failed (Error 6 The handle is invalid.) Any ideas? PS Sorry re:format–May 17 '11 at 15:02.