Writing to a COM port (windows)

Sam Schulenburg samschul at pacbell.net
Sat Feb 17 21:18:03 CET 2001


Get Mark Hammonds win32all
http://www.activestate.com/Products/ActivePython/win32all.html

Mark has a win32comport_demo.py in the win32\demos directory.

Sam Schulenburg

"Robert Gahan" <gahanr at gofree.indigo.ie> wrote in message
news:AhAj6.2566$r4.2220 at news.indigo.ie...
> 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