[Tutor] how to read over serial port
shawn bright
nephish at gmail.com
Sun Nov 2 18:50:45 CET 2008
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.
thanks
shawn
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
>
> try:
> ser.open()
> except:
> sys.stderr.write("Error opening serial port %s\n" % (ser.portstr) )
> sys.exit(1)
>
> ser.setRtsCts(0)
>
> 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)
>
> sys.stdout.write(data)
>
>
>
> - --
> - ---[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!
>
> iD8DBQFJDcl3Iftj/pcSws0RAs2+AJ91ynHgzdXDfVpbh37iM7XITnDI7wCeNON8
> qxyWcuc5opuOpeRCJ6cWr+o=
> =fPs4
> -----END PGP SIGNATURE-----
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list