[Tutor] how to read over serial port
nephish at gmail.com
Mon Nov 3 15:14:54 CET 2008
Hey all, sorry, but am i supposed to be using 'rb' to read this?
On Sun, Nov 2, 2008 at 11:50 AM, shawn bright <nephish at gmail.com> wrote:
> Thanks all,
> Yeah, checked the settings, and when i have the thing talk to a
> program that just prints out whatever the serial port reads, It was
> looking fine.
> Incorrect baudrate was my first problem, and did cause weirdness,
> escpeially on the latter end of the message, but this isn't the same
> problem. Just don't know how to read it.
> On Sun, Nov 2, 2008 at 9:38 AM, Brian C. Lane <bcl at brianlane.com> wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>> shawn bright wrote:
>>> Hey there all,
>>> I have a gps device that talks to the computer over a serial port.
>>> i am using the pyserial module and getting values in.
>> Here are the relevant bits of a serial to tcp/ip app that I use. Most
>> likely you have the wrong baudrate set. If it is an older GPS device the
>> baudrate will be 4800, newer devices allow you to set it to higher
>> speeds, 9600 being standard. Check the device settings to make sure that
>> it doesn't have any weird parity settings too. 8 bits, No Parity, 1 stop
>> bit is common.
>> import sys
>> import serial
>> port = "/dev/ttyS0"
>> baud = 9600
>> ser = serial.Serial()
>> ser.port = port
>> ser.baudrate = baud
>> sys.stderr.write("Error opening serial port %s\n" % (ser.portstr) )
>> while 1:
>> # Read from serial port, blocking
>> data = ser.read(1)
>> # If there is more than 1 byte, read the rest
>> n = ser.inWaiting()
>> if n:
>> data = data + ser.read(n)
>> - --
>> - ---[Office 68.7F]--[Outside 51.0F]--[Server 103.2F]--[Coaster 70.0F]---
>> - ---[ TACOMA WSF (366772760) @ 47 36.3260 -122 23.1697 ]---
>> Software, Linux, Microcontrollers http://www.brianlane.com
>> AIS Parser SDK http://www.aisparser.com
>> -----BEGIN PGP SIGNATURE-----
>> Version: GnuPG v1.4.8 (Darwin)
>> Comment: Remember Lexington Green!
>> -----END PGP SIGNATURE-----
>> Tutor maillist - Tutor at python.org
More information about the Tutor