Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Serial Communication - Desperately Seeking...

 [1/10] from: webmaster::windsweptfarm::com at: 20-Oct-2001 11:08


Dear List, Does anyone have any experience opening a read only connection to a serial port through Rebol? I have thrashed around with this for many hours and have developed some code that is guaranteed to yield the blue screen of death but not a lot of serial communication. Basically I want to open com2 in the following configuration: Read only 4800,8,n,1 The device on the other end is a Garmin gps which is spitting out NMEA sentences that are comma delimeted. (see below for typical sentence) I have succesfully changed the communications parameters but I have been unable to "effectively" capture the output. I have opened and closed the port succesfully according to my breakout monitor chained into the serial cable. I clearly see the DTE led come on and off when issuing open and close commands. The close command does not clear the RTS led when executed. I assume that the port has been opened in Read/Write mode and is waiting for an RTS acknowledgement. Given that I do not want to write to the serial port at this time I would prefer to open the port in read only mode. My re-entry time after crashing the machine is excessive to say the least. Loading all the docs, editor, rebol, etc. is a cruel punishment for not knowing the ins and outs of Rebol. It is most discouraging to say the least. If someone could take pity on me and my plight I would be most appreciative. Please don't write me an application, (I blush at "excessive" charity) just a quick snippet to generate a stream of data from the gps hanging on the serial port. Once I can get some data flowing properly I will attempt to rise to the next challenge on my own wobbly Rebol legs. Thanks in advance, Jim Typical data stream from GPS: $GPGGA,092204.999,4250.5589,S,14718.5084,E,1,04,24.4,19.7,M,,,,0000*1F Some basic types of NMEA sentences: Description $GPGGA Global positioning system fixed data $GPGLL Geographic position - latitude / longitude $GPGSA GNSS DOP and active satellites $GPGSV GNSS satellites in view $GPRMC Recommended minimum specific GNSS data $GPVTG Course over ground and ground speed

 [2/10] from: greggirwin::mindspring::com at: 25-Feb-2002 13:54


Hi Jim, << Does anyone have any experience opening a read only connection to a serial port through Rebol? >> I don't have much experience, and I'm not sure what you're doing so far, but you should be able to use the /read refinement with OPEN. (this code is totally untested!) p: open/read serial://port2/4800/8/none/1 forever [ ready: wait [p] if ready [ data: parse/all copy ready "," ; Process data ] ] close p --Gregg

 [3/10] from: gscottjones:mchsi at: 25-Feb-2002 15:26


Hi, Jim, ----- Original Message -----
> From: Jim
...
> Basically I want to open com2 in the following configuration: > > Read only > 4800,8,n,1
Are you opening the port using something like: serial-port: open/read/lines serial://port2/4800/8/none/1 --Scott Jones

 [4/10] from: dlhawley:attbi at: 25-Feb-2002 13:44


your port open command should look like: com1: open/mode/with serial://port1/4800/none/8/1 [read direct lines <other mode stuff>] "^M" while [0 <> (length? (line: first com1))] [ print line ] You don't say what line termination is - so change ^M as needed. for modes. You might play with binary and no-wait also. no-wait if you need todo other things besides wait blocked on reading the port. I was a couple of months ago that I did something similar - it was a binary protocolbut it workedOK. I seem to remember that the program would sometimes "run ready"- eating all CPU time, but don't remember crashing. Dave [webmaster--windsweptfarm--com] wrote:

 [5/10] from: ronald:free at: 25-Feb-2002 22:37


Hi, don't know if it will help you, but i found these refinements searching for your pb in Core's dictionary : 8<--------------- open open Summary: Opens a new port connection. Synopsis: open spec Arguments: spec The spec argument. (must be: file url port object block) Refinements: /binary Preserves contents exactly. /string Translates all line terminators. /direct Opens the port without buffering. /new Creates a file. (Need not already exist.) /read Read only. Disables write operations. /write Write only. Disables read operations. /no-wait Returns immediately without waiting if no data. /lines Handles data as lines. /with Specifies alternate line termination. end-of-line The end-of-line argument. (must be: char string) /allow Specifies the protection attributes when created. access The access argument. (must be: block) /mode Block of above refinements. args The args argument. (must be: block) /custom Allows special refinements. params The params argument. (must be: block) /skip Skips a number of bytes. length The length argument. (must be: number) Description: Opens a port for I/O operations. The value returned from OPEN can be used to examine or modify the data associated with the port. The argument must be a fully-specified port specification, an abbreviated port specification such as a file path or URL, or a block which is executed to modify a copy of the default port specification. autos: open/new %autos.txt insert autos "Ford" insert tail autos " Chevy" close autos print read %autos.txt Related: close load do send 8<--------------- Cheers, Ronald

 [6/10] from: webmaster::windsweptfarm::com at: 21-Oct-2001 17:44

Serial Communications - SUCCESS!!!


Dear List, Many warm thanks to those who responded with such speed and charity to my plight. I could go on about the silly little stuff that made this minor exercise a pain, but I won't. I had the port command and related parameters when I put out my plea to the list, but thanks for confirming by findings. Many thaks to Dave Hawley for the while block. As feeble as it may seem that was my brick wall so to speak. So this little creation generates a stream of NMEA sentences when you hook a GPS to com2. For now they scroll down the console on a line by line basis. I assume the /lines refinement obviated the need for tracking the "^M" line terminator. Thanks for the heads up on that regardless. It was on my list anyway. TO DO: My next hurdle is to create a loop to identify the specific NMEA sentences. That funny stuff that looks like [$GPGLL] is what defines a particular data sentence in NMEA. Once I can identify a sentence by the first few characters (in this case a $ sign followed by five letters I can shunt them off for processing. Any pointers in this regard will not be spurned given my recent experience. The first pitfall I see is having Rebol mistake this $ sign for a money token and wrap me up in some data type dungeon. In any event thanks again. CODE start----> close gps_stream gps_stream: open/read/lines serial://port2/4800/8/none/1 while [0 <> (length? (line: first gps_stream))] [print line] close gps_stream CODE stop----> ; This is the data stream cut from console $GPGLL,4330.038,N,08030.681,W,220800,A*3B $PGRMZ,865,f,3*10 $PGRMM,WGS 84*06 $GPBOD,251.5,T,261.3,M,GARMIN,*5C $GPRTE,1,1,c,0,GARMIN*35 $GPWPL,3851.333,N,09447.941,W,GARMIN*49 $GPRMC,220801,A,4330.029,N,08030.719,W,086.9,251.5,260202,009.8,W*75 $GPRMB,A,0.00,R,,GARMIN,3851.333,N,09447.941,W,703.5,251.5,086.9,V*2F $GPGGA,220801,4330.027,N,08030.725,W,1,09,2.0,263.5,M,-35.4,M,,*75 $GPGSA,A,3,01,04,05,06,07,10,13,24,30,,,,1.8,2.0,3.0*3D $GPGSV,3,1,09,01,08,033,32,04,38,068,44,05,36,247,43,06,17,308,38*7D $GPGSV,3,2,09,07,10,133,34,10,50,204,46,13,23,062,40,24,72,014,49*79 $GPGSV,3,3,09,30,33,286,43,,,,,,,,,,,,*48 $PGRME,15.0,M,22.5,M,15.0,M*1B

 [7/10] from: brett:codeconscious at: 27-Feb-2002 12:20


Hi,
> Any pointers in this regard will not be spurned given my recent > experience. > The first pitfall I see is having Rebol mistake this $ sign for a money > "token" and wrap me up in some data type dungeon.
A couple of pointers. --> FIND/MATCH Will allow you to match the beginning of the line. --> PARSE Is I think possibly a better solution for dealing with the lines. If line is one of your example lines (of type string!) then you could try: parse line none parse line "$," parse next line none If these work in all cases (you'll need to check if all the possible characters output by the GPS are handled by these lines correctly), then you might be able to SELECT a block of variable names by using the first code. Then you might be able to SET them all at once with the result from "parse next line none". Or alternatively define some parse rules that "recognise" the various actual line formats. Just ideas, maybe one will be useful :) Brett

 [8/10] from: greggirwin:mindspring at: 26-Feb-2002 17:48


<< TO DO: My next hurdle is to create a loop to identify the specific NMEA sentences. That funny stuff that looks like [$GPGLL] is what defines a particular data sentence in NMEA. Once I can identify a sentence by the first few characters (in this case a $ sign followed by five letters I can shunt them off for processing. Any pointers in this regard will not be spurned given my recent experience. The first pitfall I see is having Rebol mistake this $ sign for a money token and wrap me up in some data type dungeon. >> Well, we can do some simple things to start with. First, you can split the data string up into fields, assuming that's helpful:
>> b: parse/all {$GPGLL,4330.038,N,08030.681,W,220800,A*3B} ","
== ["$GPGLL" "4330.038" "N" "08030.681" "W" "220800" "A*3B"] Next, you could see if the first field starts with "$", and chop the "$" off of it:
>> if b/1/1 = #"$" [b/1: next b/1]
== ["GPGLL" "4330.038" "N" "08030.681" "W" "220800" "A*3B"] Now, you can look at the first field (i.e. b/1) to see what your code is so you can branch and process accordingly. HTH! --Gregg

 [9/10] from: petr:krenzelok:trz:cz at: 27-Feb-2002 16:46

Re: Serial Communication - Desperately Seeking...


Sorry for being off-topic, but I remember there was some nice explanatory talk about serial port usage in Rebol on this ml in the past, but I can't find it now. Any pointers? Thanks, -pekr-

 [10/10] from: dlhawley::attbi::com at: 26-Feb-2002 21:41

Re: Serial Communications - SUCCESS!!!


I'd start by putting something like: while [0 <> length? (line: .... ] [ switch (first parts: parse line ",") [ "$GPGLL" [ handle-gpgll parts] "$PGRMZ" [ ... ] ..... ] ] you can ignore the strings you don't want and you have blocks of data split up in usable parts. Dave