如何通过可可应用程序从USB GPS设备读取NMEA数据

问题描述:

我正在使用USB GlobalSat(USG-MR350) GPS设备。我想从我的Mac可可应用程序中的设备获取位置数据(经度和纬度)。尝试运行AMSerialPort示例代码。它正在检测USB设备,但它给出的输出格式为,不可读格式。数据转换为可读format.This是源代码的一部分:如何通过可可应用程序从USB GPS设备读取NMEA数据

- (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]; 
} 
+0

在我真正了解Cocoa所做的事情之前,我开始为这个Looong开发了一个框架,但它可能有些用处:https://github.com/nall/GarminFramework – nall 2012-02-28 05:49:58

我认为Sirf的接收器默认处于二进制模式,你必须把它放在NMEA mode explicitly

尝试使用NSData通过description方法将自身打印为字节的功能。

[outputTextView insertText:[data description]];

我看不到您正在检查端口设置。

默认设置为NMEA通过串口是speed:4800stopbit:1 parity:none

在设备上检查它。