serial comm with GPS, not quite an NMEA sentence

  • 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
  • On Oct 2, 2006, at 8:58 PM, Gonzalo Castro wrote:


    That code appear to have a memory leak (or two) in it but back to
    your question... It sounds like the serial port is set to the wrong
    speed or data format which is likely causing you to read bad
    information. You likely need to set the correct port speed, etc. and
    it should work.

    I am attaching some code that I wrote over a weekend a few years back
    while out boating with my dad.. it may help you. I never did get a
    chance to test it heavily (beware) or make much use of it... feel
    free to pick it over for information.

    
    -Shawn _______________________________________________
    Do not post admin requests to the list. They will be ignored.
    Cocoa-dev mailing list      (<Cocoa-dev...>)
    Help/Unsubscribe/Update your Subscription:
    http://lists.apple.com/mailman/options/cocoa-dev/<cocoa...>

    This email sent to <cocoa...>
  • On Oct 2, 2006, at 11:58 PM, Gonzalo Castro wrote:

    > 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.

    From the docs link above:

    3.2  "Complex" data format

              The complex format consists of a data block of 37 bytes of
               (mostly) readable ASCII text giving cross-track error, bearing
              to waypoint, present Lat/Long, and a binary status byte.  The
               data block shall be sent at intervals of 2 to 8 sec. All bytes
              in the complex format have bit 7 = 1 to distinguish them from
              the simple format.

    Note that last sentence - what you get is almost but not quite ASCII
    text, although it looks like it can be easily converted to ASCII.
    You'll need to look for, and strip out if necessary, the high bits.

    sherm--

    Web Hosting by West Virginians, for West Virginians: http://wv-www.net
    Cocoa programming in Perl: http://camelbones.sourceforge.net
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today