serial comm with GPS, not quite an NMEA sentence
serial comm with GPS, not quite an NMEA sentence
- Subject: serial comm with GPS, not quite an NMEA sentence
- From: Gonzalo Castro <email@hidden>
- Date: Mon, 2 Oct 2006 23:58:58 -0400
Hello,
I'm learning how to get data from a serial device, specifically a GPS
set to use NMEA protocol. I came across the following sample code, at
http://www.harmless.de/cocoa.html#serialport.
The method below seems to be called when receiving data. Should I
expect the NSData *data to contain an NMEA formatted string? Eg, "RMC,
225446,A,4916.45,N,12311.12,W,000.5,054.7,191194,020.3,E*68" (clipped
from http://www.eoss.org/pubs/nmeafaq.htm). If so, then I'm not
getting such a string. Instead, dataStr looks like garbage.
- (void)serialPortReadData:(NSDictionary *)dataDictionary
{
// this method is called if data arrives
// @"data" is the actual data, @"serialPort" is the sending port
AMSerialPort *sendPort = [dataDictionary objectForKey:@"serialPort"];
NSData *data = [dataDictionary objectForKey:@"data"];
if ([data length] > 0) {
NSString *dataStr = [[NSString alloc] initWithData:data
encoding:NSASCIIStringEncoding];
NSLog(@"dataStr = %@", dataStr);
[outputTextView insertText:dataStr];
// continue listening
[sendPort readDataInBackground];
} else { // port closed
[outputTextView insertText:@"port closed\r"];
}
[outputTextView setNeedsDisplay:YES];
[outputTextView displayIfNeeded];
}
Thanks for any pointers.
Gonzalo
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden