Connecting Tech Pros Worldwide Forums | Help | Site Map

Accessing Windows Serial Port

George T.
Guest
 
Posts: n/a
#1: Feb 6 '06
I need to access the serial port via python on a windows machine.
Reading on the web, there are three solutions: pyserial, siomodule and
USPP. pyserial seems to be the best option since the other two are
tested with Windows 95 and older versions of python. Would you agree
with this or have I missed an option?

Can anyone provide me an example of how to access the serial port with
pyserial?

Thanks
George T.


Roel Schroeven
Guest
 
Posts: n/a
#2: Feb 6 '06

re: Accessing Windows Serial Port


George T. schreef:[color=blue]
> I need to access the serial port via python on a windows machine.
> Reading on the web, there are three solutions: pyserial, siomodule and
> USPP. pyserial seems to be the best option since the other two are
> tested with Windows 95 and older versions of python. Would you agree
> with this or have I missed an option?[/color]

I hadn't even heard of siomodule and USPP; pyserial is what I use when I
need to read/write from/to the serial port.
[color=blue]
> Can anyone provide me an example of how to access the serial port with
> pyserial?[/color]

It's quite simple; there are a number of examples on pyserial's website.
Here's a small quick and dirty script that reads data from a serial port
and broadcasts it as UDP over the network to make the incoming data
available to other computers in the office:

import socket
import sys

import serial

ser = serial.Serial('COM1', 38400, timeout=1)
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
while True:
msg = ser.readline()
sock.sendto(msg, ('<broadcast>', 5000))
sys.stdout.write(msg)


Basically you can use the objects like other file-like objects.


--
If I have been able to see further, it was only because I stood
on the shoulders of giants. -- Isaac Newton

Roel Schroeven
Grant Edwards
Guest
 
Posts: n/a
#3: Feb 6 '06

re: Accessing Windows Serial Port


On 2006-02-06, George T. <georgetoffer1@yahoo.com> wrote:
[color=blue]
> I need to access the serial port via python on a windows machine.
> Reading on the web, there are three solutions: pyserial, siomodule and
> USPP.[/color]

You can also just use win32 stuff directly (CreateFile et al).
[color=blue]
> pyserial seems to be the best option since the other two are
> tested with Windows 95 and older versions of python. Would you agree
> with this or have I missed an option?[/color]

I've used PySerial and win32 system calls. I've never used the
other two. Try pyserial first. If you need lower level
control than that gives you, use win32 calls.
[color=blue]
> Can anyone provide me an example of how to access the serial port with
> pyserial?[/color]

http://pyserial.sourceforge.net/

--
Grant Edwards grante Yow! Is this "BOOZE"?
at
visi.com
malv
Guest
 
Posts: n/a
#4: Feb 7 '06

re: Accessing Windows Serial Port


Hi All,
Would anybody know whether PySerial would work over an usb/serial
adapter?
(what about usb/parallel adapters?)
Thx.
malv

Roel Schroeven
Guest
 
Posts: n/a
#5: Feb 7 '06

re: Accessing Windows Serial Port


malv schreef:[color=blue]
> Hi All,
> Would anybody know whether PySerial would work over an usb/serial
> adapter?[/color]

If the driver for the adapter creates a virtual COM-port (i.e. it shows
up as a serial port in Windows' device manager), it works. The software
sees no difference between a real port and a fake one.
[color=blue]
> (what about usb/parallel adapters?)[/color]

Never tried it, but I guess it will work too.

--
If I have been able to see further, it was only because I stood
on the shoulders of giants. -- Isaac Newton

Roel Schroeven
Grant Edwards
Guest
 
Posts: n/a
#6: Feb 7 '06

re: Accessing Windows Serial Port


On 2006-02-07, malv <malvert@telenet.be> wrote:[color=blue]
> Hi All,
> Would anybody know whether PySerial would work over an usb/serial
> adapter?[/color]

Yes.
[color=blue]
> (what about usb/parallel adapters?)[/color]

Don't know.

--
Grant Edwards grante Yow! I'm an East Side
at TYPE...
visi.com
Closed Thread