Writing to a COM port (windows)

Robert Gahan gahanr at gofree.indigo.ie
Sat Feb 17 14:12:57 EST 2001


Hi all,

I'm reasonably new to Python and very much a novice as far as windows
programming is concerned.

I am looking to write to a device which is connected to my COM1 port and am
looking for an
appropriate python method. (effectively looking to write to the device
driver)

The "C" equivalent for doing this is:

 hCom = CreateFile(szPort, GENERIC_READ | GENERIC_WRITE,
  FILE_SHARE_READ, NULL, OPEN_EXISTING,
  FILE_ATTRIBUTE_NORMAL, NULL);

 // setup device buffers
 SetupComm(hCom, 4096, 4096 ) ;

Is there any way of doing this from Python ???.

import os
f = open("COM1", 'w')
f.write("at012345678")
print f
f.close()

Traceback (innermost last):
  File "C:/Python20/smpp1", line 2, in ?
    f = open("COM1", 'w')
IOError: [Errno 13] Permission denied: 'COM1'

Thanks again,
Rob.





More information about the Python-list mailing list