WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #1  
Old 06-17-2010, 08:31 AM
nige777 nige777 is offline
Member
 
Join Date: Nov 2007
Location: UK
Posts: 78
wow, thanks for the reply Wayne, thats great to know

-not at the office today which is where the GPS unit is however I have a quick question about implimenting readSerial - I know its my lack of OO know-how but I am a little confused as to how to pass the open serial port to the function
In my first attempts I did something like this:
Code:
ser = serial.Serial(0, 4800, timeout=1)
- I'm now aware that the timeout parameter was incorrect and neither is this:-
Code:
readSerial(ser)
Sorry for my n00bishness but I'd be very grateful for any pointers you could give me
??
Reply With Quote
  #2  
Old 06-17-2010, 02:22 PM
nige777 nige777 is offline
Member
 
Join Date: Nov 2007
Location: UK
Posts: 78
I think I should clarify - my last post was as clear as mud! - what I meant to say is that I am also aware that I can't just call the function with
Code:
readSerial(ser)
Reply With Quote
  #3  
Old 06-18-2010, 07:54 AM
nige777 nige777 is offline
Member
 
Join Date: Nov 2007
Location: UK
Posts: 78
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()
"line" is then passed to a parser which has been developed with the aid of a text file of a GPS output (NMEA).
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
Attached Files
File Type: txt GPS_DUMP.txt (29.3 KB, 6241 views)
File Type: txt GPS_TXT_DMP.txt (2.2 KB, 5185 views)
Reply With Quote
  #4  
Old 06-21-2010, 05:54 PM
wayne wayne is offline
Member
 
Join Date: May 2008
Location: Santa Barbara, CA
Posts: 9
Thumbs up

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:
Originally Posted by nige777 View Post
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()
"line" is then passed to a parser which has been developed with the aid of a text file of a GPS output (NMEA).
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
Reply With Quote
  #5  
Old 06-22-2010, 01:04 PM
nige777 nige777 is offline
Member
 
Join Date: Nov 2007
Location: UK
Posts: 78
Thumbs up

Thanks for the heads up there Wayne, as you suspected my serial settings were wrong however readline() would still not work correctly with 'NMEA out' enabled but work fine with 'Text out'!
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
which is working pretty much how I want it to

Last edited by nige777; 06-22-2010 at 01:08 PM.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
serial port with vizard Moh200jo Vizard 3 03-13-2009 04:21 PM
A simple Plug_in for reading data from serial port sled Plug-in development 0 08-12-2003 10:52 AM


All times are GMT -7. The time now is 12:21 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC