2012-02-27 84 views
2

我正在使用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

回答

0

我認爲Sirf的接收器默認處於二進制模式,你必須把它放在NMEA mode explicitly

0

嘗試使用NSData通過description方法將自身打印爲字節的功能。

[outputTextView insertText:[data description]];

0

我看不到您正在檢查端口設置。

默認設置爲NMEA通過串口是speed:4800stopbit:1 parity:none

在設備上檢查它。

相關問題