Page 1 of 1

Extracting NMEA data from a USB port

Posted: Mon Mar 01, 2021 8:08 pm
by GoneToSail
I am trying to retrieve NMEA data (i.e. data built in accordance with a NMEA-0183 standard issued by National Marine & Electronics Association) through a USB connection, and ultimately to convert these data (which I believe are received as binary data) into text lines.
After conversion to ASCII text, each line is supposed to start with the $ char, followed by 5 letters, and to contain max 82 chars.

Here is a sample of the received data:
ˇRòßT»Rò'T–¢ÉN–Å —ÇTp&D≤¶¢¢—N˙""\O"®ßT»"¢#ˇ"ò'TƒRòßT»"ò'T–¢ÉfÿÈ QÇTp&D≤¢Ç˙"'F"\
Nˇ"òßT»¢ÜÚ√N–—ÉN–‡Å —N∫""\LR&N¿4FÚd䢅¢N ¡¢\ú#D"—L^ˇ"ò'TßRò7T»Rö'T–RäßT»*¢FQNò'T–"òßT»*£DL —OLNˇ"‡'T–R»ßV»Rò'D–"'F"\
NˇRòßT Rò'T–"6˙¢"+Ç˙"ËßT»¢ÉÆÓANëÉN‘¯¯˙¢ND—ND∏ ¡¢D¢\`&DÀ¡L ¡¢\ú"'F"\
^ˇ¢ÇD
DÚ{V∞‡ÉtÍPVN–∏ —N∫"¢\LQN–a¯"ò'T–™Ør¯RòßT»Rò7T–"&O‡F∏¯"7N"L
FˇRòßV»"ò'T–RòßT»Rò'T–"òßT»*/O"\
FˇRò'T–∏‡¯*ò;T ".N¿FÚlÜ≤…, …¢\úRò'T–N–‡x¯"£"LLû" "LL¸¢¶˙"òßT»Rò'V⁄¢N@»—N–‡8 —N∫""\LRäßT»"ò'Tƒ#D —LVˇ¢ÉNÿ QÇTp&D≤™Ü˙RòßT»Zò'V⁄ÇÉN–·"]ÇV~.G≤¢Ü˙RäßT»&NdGdÇ¢¡¢L¥@¡¢\úò'T‘¢D:DÚ+WˇRòØV»¢‡N—ãN–@ —N∫"¢\LQÉN–a —ÇTp&DÉ¢Ç˙Rò'T–RòßT»Rò'T⁄RòßT»"¶#ˇRò'T–¢ÉN\a QÇT&D≤¢Ç˙¢G\a QT&D≤¢Ç˙RòßV»&N¿FÚdÇ¢¡¢L A¢\ú"ò'T–¢N\a QT˛.D≤¢Ç˙R™ßT»Rò'V–"&O‡F∏¯¢ÇDGÚ@#ˇòßT»R™'T–¢N\·—ÇV˛.D≤¢ —N∫&"\NUN\· —T&D≤¢Ç˙RòßT»Rò'TßäßD¯Ròßd»R'F"\
^ˇRò'V–RòßT»&N¿FÚdÇ¢¡¢D!¡¢\ú#T —L^ˇÇßl¯"ò'T–RòßD» "LO¸¢¶˙ò'T–"&O‡N∏¯RòßT»¢ÉN\q—áN\‡≤¢Ç˙£DL ŸOtNˇRò'T–RòßV»¢ÉG\a QV˛&G≤¢Ü˙¢DLÚ#Fˇ&N¿;FÚdÇ¢¡éN ¡¢\úRò'T–™G\· —ÇD&t≤¢ä"—N∫&"\N"#D —L^ˇòßV»"'F*^
^ˇZò'T–¢ÇDLÚ#Fˇ¢ÉˆN—ãN\h‡∏ ’N∫&"^NRòßT»¢ÉN\a QT&D≤¶Ç˙Rò'T–RòßT»#D ALVˇ"¢#ˇ"ò'f–"òßT»™áN\aA—T&D≤ÆÇ"—N∫""\ORò'T–¢ÉN\a"]T¶D≤¶Ç˙&N¿FÚdÜ≤…¢N"…¢\úRòßT»RXO»&NRòßT»¢ÉN\· —T&D≤¢¢¢—N∫"¶\N¢ÉN∏a QTp¶D≤¢Ç˙Rò'T–"òßT»Rò'T–"'F"\NˇRòßT¡ÉNòa —tp¶D≤ƶ≤€
N∫"¶\OÇÉF∏· QT|ÆG≤¢Ç˙Rò'T–
I assume that I should use the binaryDecode function and I have tried several scripts similar to the example given in the LC dictionary (binaryDecode("a*",receivedData,textData) -- converts data to text) but without success as I'm not clear about the correct parameters to be used.
Anyone can help me to obtain the desired text lines ?

Using a MacBook with OSX 10.11.6 - LC Indy Edition 9.5.1

Re: Extracting NMEA data from a USB port

Posted: Mon Mar 01, 2021 9:21 pm
by PaulDaMacMan
I don't know anything about NMEA data, but I don't see a starting $ character in that sample at all. Are you sure you are receiving the message properly?
How about posting the code you used to receive this sample with?

Re: Extracting NMEA data from a USB port

Posted: Mon Mar 01, 2021 9:37 pm
by dunbarx
Hi.

Is this what actually comes over, verbatim, or have you done anything at all to it?

Craig

Re: Extracting NMEA data from a USB port

Posted: Mon Mar 01, 2021 11:21 pm
by GoneToSail
Thanks for your comments.
Here is the code that I'm using (actually in 2 btns "OpenDriver" and "ReadData"):

Code: Select all

on mouseUp
    open driver "/dev/cu.usbserial-FTH7S78S" for binary read-- "usbserial-FTH7S78S" is the device name
   if the result is "can't open that file" then
      answer "Can't open that file"
   else
      answer "Driver"&&quote&fld "DeviceName"&quote&&"is open !"
   end if
end mouseUp

Code: Select all

on mouseUp
   read from driver (fld "DeviceName") for 10 lines
   if the result is empty then put "Read OK" into fld "ReadResult" else put the result into fld "ReadResult"
   put it into fld "Data"
end mouseUp
The sample data quoted in my first message is exactly what I got !

Re: Extracting NMEA data from a USB port

Posted: Tue Mar 02, 2021 10:38 am
by richmond62
Have you any idea what the data should look like?

Re: Extracting NMEA data from a USB port

Posted: Tue Mar 02, 2021 12:04 pm
by GoneToSail
Here is an example of NMEA messages.
First char of each line is a $, first line herbelow reads: GP for Global Positioning, RMC is a message type, giving time, latitude (42°54'55.86"N) and longitude, speed (53.3 knots) and course (023°).
$GPRMC,104633.396,V,4254.931,N,07902.497,W,53.3,0.23,020321,,E*40
$GPGGA,104634.396,4254.931,N,07902.497,W,0,00,,,M,,M,,*53
$GPGLL,4254.931,N,07902.497,W,104635.396,V*32
$GPVTG,0.23,T,,M,53.3,N,98.7,K*52
$GPRMC,104637.396,V,4254.933,N,07902.496,W,17.9,0.30,020321,,E*4F
$GPGGA,104638.396,4254.933,N,07902.496,W,0,00,,,M,,M,,*5C

Re: Extracting NMEA data from a USB port

Posted: Tue Mar 02, 2021 12:48 pm
by richmond62

Re: Extracting NMEA data from a USB port

Posted: Tue Mar 02, 2021 5:10 pm
by stam
Would textDecode(binaryData, encoding) help?