How to read NMEA data from USB GPS device through cocoa application

时间秒杀一切 提交于 2020-02-19 07:02:14

问题


I am using USB GlobalSat(USG-MR350) GPS device. I want to get location data (latitude and longitude) from the device within my mac cocoa application.Tried to run the AMSerialPort sample code.It is detecting the usb device but it is giving output in nonreadable format.How can this data be converted to readable format.This is a part of the source code:

- (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 *text = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
        [outputTextView insertText:text];
        [text release];
        // continue listening
        [sendPort readDataInBackground];
    } else { // port closed
        [outputTextView insertText:@"port closed\r"];
    }
    [outputTextView setNeedsDisplay:YES];
    [outputTextView displayIfNeeded];
}

回答1:


I think that Sirf receiver is by default in binary mode, and that you have to put it in NMEA mode explicitly.




回答2:


Try using the NSData's ability to print itself as bytes via the description method.

[outputTextView insertText:[data description]];




回答3:


I don't see you are checking port settings.

Default settings for NMEA over serial port is speed:4800stopbit:1 parity:none.

Check it on the device.



来源:https://stackoverflow.com/questions/9462538/how-to-read-nmea-data-from-usb-gps-device-through-cocoa-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!