![]() |
|
#1
|
|||
|
|||
I think I should clarify - my last post was as clear as mud!
![]() Code:
readSerial(ser) |
#2
|
|||
|
|||
Ok, I am back in the office.
The code I have been using to connect to the GPS is as follows: Code:
while 1: ser = serial.Serial(port=0, baudrate=4800, timeout=0) line = ser.readline() print line #DEBUG ser.close() I've included two text files - GPS DUMP is what is received when the GPS is outputting NMEA sentences and the TXT file shows what is received when the GPS unit is outputting text only. I really like your buffer method but am at a loss on how to implement it ![]() I am off to pour over the documentation for PySerial again as I am sure I'm missing something obvious ![]() |
#3
|
|||
|
|||
![]()
I had a look at your code below. The problem is that you are opening up the serial port, reading a line, and then closing the port. Then it is reopened when you go through the while loop. You should not repeatedly open and close a serial port, it should just be opened once, and then you can call readline() within the while loop.
Also, the readSerial() code I included earlier was cut and pasted out of a class that I had written for myself. So it defined a method called readSerial(), but if you fix up your previous code with the suggestion I made then it should work well. Quote:
|
#4
|
|||
|
|||
![]()
Thanks for the heads up there Wayne, as you suspected my serial settings were wrong
![]() ![]() However I have ended up using the following approach - Thanks StackOverflow ![]() Code:
buffer = '' while True: buffer = buffer + ser.read(ser.inWaiting()) if '\n' in buffer: lines = buffer.split('\n') # Splits buffer block into lines last_received = lines[-2] buffer = lines[-1] print last_received ![]() Last edited by nige777; 06-22-2010 at 12:08 PM. |
![]() |
Thread Tools | |
Display Modes | Rate This Thread |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
serial port with vizard | Moh200jo | Vizard | 3 | 03-13-2009 03:21 PM |
A simple Plug_in for reading data from serial port | sled | Plug-in development | 0 | 08-12-2003 09:52 AM |