Shop OBEX P1 Docs P2 Docs Learn Events
Serin with decimal point — Parallax Forums

Serin with decimal point

Eric REric R Posts: 225
edited 2006-04-17 03:33 in BASIC Stamp
I have a serial string that I need to parse and extract the following variable that will range from 00.0 to 99.9, how does one handle the decimal point? For now I have entered a static·74.8 for testing but get an error as expected.
I assume I will need to parse the string twice and place a static decimal point thus creating two variables. Does anyone know of a better way to handle this?


test·VAR Word

test·= 74.8

SEROUT 15,84, [noparse][[/noparse]2,"L,H07,D11,391100801500850·Test #" ,32,DEC test,13,69]



·

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-04-11 02:04
    First, you can't have fractional numbers in PBASIC, so you'd multiply test by 10 to get 748. Now you would send it like this:

    SEROUT pin, baud, [noparse][[/noparse]DEC (test/10), ".", DEC1 test]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Eric REric R Posts: 225
    edited 2006-04-11 02:51
    Jon,

    That solved the second half of the problem that I had yet to get to.

    The first problem was that the serin data is formatted as 74.8

    Here is the actual serin string:

    #··· 00 XXX 74.8·YYY CR LF ESC·T· ESC D CR CR LF CR LF



    #·· 00 Is a variable sequential number

    XXX Is a label

    74.8 Is the data needed

    YYY is a label

    ESC T was print time

    ESC D was print date

    Your solution will work provided I can parse the decimal point in the serin string. I was looking for the best way to handle this.

    ·Re reading my initial post, I neglected to say the origin of the 74.8 was from a serin string, sorry blush.gif

    Thanks



    Post Edited (Eric R) : 4/11/2006 2:55:54 AM GMT
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2006-04-11 03:49
    In some cases you can capture the number before and after the decimal point and then combine them:
    DEBUGIN before,after
    N = before*10 + after
    The decimal point acts as a terminator.

    In the string you are dealing with, the critical thing will be syncing up with the number to the left of the decimal point. How you do that, and if it is possible at all, may depend on the baud rate, and which Stamp you are using. Is "#" actually in the string as a symbol? Is XXX a constant, non-numerical label?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Eric REric R Posts: 225
    edited 2006-04-11 04:26
    Tracy Allen said...
    In some cases you can capture the number before and after the decimal point and then combine them:
    DEBUGIN before,after
    N = before*10 + after
    The decimal point acts as a terminator.

    In the string you are dealing with, the critical thing will be syncing up with the number to the left of the decimal point. How you do that, and if it is possible at all, may depend on the baud rate, and which Stamp you are using. Is "#" actually in the string as a symbol? Is XXX a constant, non-numerical label?

    Baud is 4800 N81 and I planned on the BS2E.
    The # is a symbol·to indicate "number".
    This is a old printer data string and below is the actual "DataBoy" capture
    The square does not copy properly into this thread but it denotes Line Feed.
    The only variables in the string are 56 and 11.5, it is possible that the 56 could grow to 3 digits.
    # 56 FAT 11.5 PCT ♪◙←T ←D♪♪◙♪◙
    Is it possible to·[noparse][[/noparse]WAIT ("FAT"),DEC2 set1, SKIP 1, DEC1 set2] ? If so, how would one assemble the variables to equal the sum?
    Possibly, SEROUT pin, baud, [noparse][[/noparse]DEC2 set1, ".", DEC1 set2]?
    I would sure like to try it but the printer I am sending to is at work.
    ·

    Post Edited (Eric R) : 4/11/2006 4:29:45 AM GMT
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2006-04-11 16:23
    At 4800 baud it is on the edge of being possible with a BS2e. It would be easier with 4800 N82 than with N81.

    You can try,
    [noparse][[/noparse]WAIT ("FAT"),DEC2 set1, DEC1 set2]

    My earlier point was that you do not need the SKIP 1. The decimal point itself will demark the two parts. Once you have them, you convert to a single number with
    set = set1 * 10 + set2.
    Or, if you don't need to manipulate the value as a single number, the SEROUT command you wrote would work.

    The thing about 4800 baud is that the WAIT command takes some time to set up, and while that is happening, the data can arrive too fast and the Stamp gets out of sync and you get garbage data. Try it though, and see. Sometimes there is enough interbyte space to allow it to work.

    Another approach is to use the scratchpad RAM and the SPSTR or STR modifier to input the data string, and then parse off the numbers you need after. Once synchronized, that can capture data at a faster rate. You see that technique with a lot of GPS capture programs.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Eric REric R Posts: 225
    edited 2006-04-17 03:33
    Thanks Jon and Tracy

    It is working well with debug. Sorry for the delay but I finished my RFID project before getting back on this one.·The 4x20 lcd and MemKey should show up this week so I can finish this project and test it in real time. For now I will stick with the wait command as all data will be entered before the equipment is started. Once started it will take a minimum of 10 seconds for the equipment to settle and spit out the data string. This should do the trick!

    Thanks again
Sign In or Register to comment.