469,327 Members | 1,337 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,327 developers. It's quick & easy.

Accessing Windows Serial Port

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.

Feb 6 '06 #1
5 24668
George T. schreef:
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?
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.
Can anyone provide me an example of how to access the serial port with
pyserial?


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
Feb 6 '06 #2
On 2006-02-06, George T. <ge***********@yahoo.com> wrote:
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.
You can also just use win32 stuff directly (CreateFile et al).
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?
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.
Can anyone provide me an example of how to access the serial port with
pyserial?


http://pyserial.sourceforge.net/

--
Grant Edwards grante Yow! Is this "BOOZE"?
at
visi.com
Feb 6 '06 #3
Hi All,
Would anybody know whether PySerial would work over an usb/serial
adapter?
(what about usb/parallel adapters?)
Thx.
malv

Feb 7 '06 #4
malv schreef:
Hi All,
Would anybody know whether PySerial would work over an usb/serial
adapter?
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.
(what about usb/parallel adapters?)


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
Feb 7 '06 #5
On 2006-02-07, malv <ma*****@telenet.be> wrote:
Hi All,
Would anybody know whether PySerial would work over an usb/serial
adapter?
Yes.
(what about usb/parallel adapters?)


Don't know.

--
Grant Edwards grante Yow! I'm an East Side
at TYPE...
visi.com
Feb 7 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by ^CeFoS^ | last post: by
2 posts views Thread by fdunne2 | last post: by
6 posts views Thread by Jeff | last post: by
13 posts views Thread by Al the programmer | last post: by
1 post views Thread by henrycortezwu | last post: by
38 posts views Thread by shussai2 | last post: by
3 posts views Thread by naveen.sabapathy | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by listenups61195 | last post: by
reply views Thread by Purva khokhar | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.