Extended FullDuplexSerial Object
Martin Hebel
Posts: 1,239
Hi All,
I have a lot of serial communication needs coming up between XBee and StampDAQ (and maybe a litte StampPlot), and while I appreciate FullDuplexSpin, it didn't have anything in place to accept alphanumeric strings or decimal strings directly, so I knew sooner or later I'd have to write those (hope they weren't already done and missed by me!) in my code or as a library.
So this object library, Extended_FDSerial, uses FullDuplexSerial and extends out those functions allowing reception of serial strings for decimal values, hex values, and alphanumeric, with and without timeouts.
From the documented part:
This object extends Chip Gracey's FullDuplexSerial to allow easy reception of
multiple bytes for decimal values, hex values and strings which end with carriage returns (ASCII 13)
Use as you would FullDuplex for Rx, Tx, Start, Stop, RxTime, RxCheck, RxFlush, DEC, HEX, BIN Str
Adds the following:
RxDec Returns decimal string as value
RxDecTime(ms) Returns decimal string as value with timeout
RxHex Returns received hex string value as decimal
RxHexTime(ms) Returns received hex string value as decimal with timeout
RxStr Passes received string
RxStrTime(ms) Passes received string with timeout
Hope it can help others, I'll see about getting it on the Object Exchange... if it hasn't been done already
-Martin
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Martin Hebel
StampPlot - Graphical Data Acquisition and Control
AppBee -·2.4GHz Wireless Adapters & transceivers·for the BASIC Stamp & Other controllers·
Post Edited (Martin Hebel) : 1/9/2007 3:47:27 AM GMT
I have a lot of serial communication needs coming up between XBee and StampDAQ (and maybe a litte StampPlot), and while I appreciate FullDuplexSpin, it didn't have anything in place to accept alphanumeric strings or decimal strings directly, so I knew sooner or later I'd have to write those (hope they weren't already done and missed by me!) in my code or as a library.
So this object library, Extended_FDSerial, uses FullDuplexSerial and extends out those functions allowing reception of serial strings for decimal values, hex values, and alphanumeric, with and without timeouts.
From the documented part:
This object extends Chip Gracey's FullDuplexSerial to allow easy reception of
multiple bytes for decimal values, hex values and strings which end with carriage returns (ASCII 13)
Use as you would FullDuplex for Rx, Tx, Start, Stop, RxTime, RxCheck, RxFlush, DEC, HEX, BIN Str
Adds the following:
RxDec Returns decimal string as value
RxDecTime(ms) Returns decimal string as value with timeout
RxHex Returns received hex string value as decimal
RxHexTime(ms) Returns received hex string value as decimal with timeout
RxStr Passes received string
RxStrTime(ms) Passes received string with timeout
Hope it can help others, I'll see about getting it on the Object Exchange... if it hasn't been done already
-Martin
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Martin Hebel
StampPlot - Graphical Data Acquisition and Control
AppBee -·2.4GHz Wireless Adapters & transceivers·for the BASIC Stamp & Other controllers·
Post Edited (Martin Hebel) : 1/9/2007 3:47:27 AM GMT
Comments
I too have plans to do a lot of serial input and this sounds just like what I was looking for. Now if that 6.5" sunlight viewable display would show up and my engine monitor w/ serial output would ship, I'd be happy!
--
Michael
-MH
Keep me posted please.
-Martin
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Martin Hebel
StampPlot - Graphical Data Acquisition and Control
AppBee -·2.4GHz Wireless Adapters & transceivers·for the BASIC Stamp & Other controllers·
- The recieved string terminated by ASCI 13, is the ASCII 13 passed as part of the string or is it stripped
- Separators/terminators of numbers (DEC or HEX) ... is it ASCI 13 also, or 'white space' (tab, space, comma)?
- "decimal numbers" ??? Actual decimals, or base-10 integer returned as a standard Propeller long?
- Say I have the string "... 072.4357, ..." how would your routine be used to input and parse this?
Inquiring mind wants to know <grin>!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
cheers ... brian riley, n1bq, underhill center, vermont
See the K107 Serial LCD Controller at
www.wulfden.org/k107/
Hi Brian,
It's not very sophisticated, but you are free to adapt to your own needs.
Q: The recieved string terminated by ASCII 13, is the ASCII 13 passed as part of the string or is it stripped
The ASCII 13 is not passed, it is stripped so you get only the string up to that point. Also, using StrTime, if the string reaches 15 characters, or the timeout is met, you get that portion of the string.
Q: Separators/terminators of numbers (DEC or HEX) ... is it ASCI 13 also, or 'white space' (tab, space, comma)?
Only ASCII 13 at this point, but it would be easy to add OR's for other delimiters. I guess a delimiter could have been passed, it would have been a nice addition.
Q: "decimal numbers" ??? Actual decimals, or base-10 integer returned as a standard Propeller long?
Working from the BASIC Stamp DEC, it refers only to integer values.
Q: Say I have the string "... 072.4357, ..." how would your routine be used to input and parse this?
Um.... I think it would give you a value of 724357 ignoring the decimal, but you could use a string to accept it instead then convert it to a float using another library object I think.
I wrote it to meet many needs I often have, so didn't think bigger picture.
-Martin
- Parsing based on defined delimiters. Default delimiter is ",",plus the CR is always used also.
- Returning from a string the integer or whole value ("-123.456") returns -123
- Returning from a string the fractional value ("-123.456") returns 456
I though about trying to incorporate the floating point library, but with an AND or two, values can be checked against a reference, and these values can be used to pass to the floating point library if need be.
The archived example included illustrates parsing a GPS string, such as: (·sent from the PC for testing):
$GPRMC,235255,A,3524.3873,N,11901.4907,W,001.1,155.3,250107,014.0,E,A*04
Not yet updated on the object Library.
-Martin
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Martin Hebel
StampPlot - Graphical Data Acquisition and Control
AppBee -·2.4GHz Wireless Adapters & transceivers·for the BASIC Stamp & Other controllers·
I'll be writing a version to support MaxStream's XBee's in API mode where I will implement their checksums, but again, that's a specific applications.
-Martin
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
StampPlot - GUI and Plotting, and XBee Wireless Adapters
Southern Illinois University Carbondale, Electronic Systems Technologies
1. Have CONstants at the top defining the size of the input and output buffer;
2. Have a flag indicating whether input overrun occurred.
I know at least (1) has been done by some people, but it would be nice to have it
folded into the standard release. As it is, it is very easy to overrun the input
buffer and not realize it.
1) Constants at the top to set buffer sizes - power of 2.
2) I use a·bigger buffer to avoid an input overrun - since my messages are a set length
3) Check for a stop bit!! If·a stop bit·is not present then·the received byte is dropped (but no flags of any sort are set) and it's up to a higher level of code to check the message for integrity.