Shop OBEX P1 Docs P2 Docs Learn Events
serString byte selection from array — Parallax Forums

serString byte selection from array

Andy McLeodAndy McLeod Posts: 40
edited 2008-01-18 23:29 in BASIC Stamp
I am attempting to read a 9 byte response from a pressure sensor coming into a BS2pe at 9600 baud. The response is coming in at 10hz for 10 seconds for a total of 100 samples. I need to extract the 3rd, 4th, 5th and 6th byte. I have the following code:

' {$STAMP BS2pe}
' {$PBASIC 2.5}
' {$PORT COM1}


serinPin    CON    9
n9600       CON    16468   

reps    VAR     Byte
serString VAR   Byte(10)
serString(9) = 0

HIGH 3                      'triggers the 16F88 to send initialization pulse to Druck 33X sensor
PAUSE 10
LOW 3                      'resets trigger 16F88 pin

PAUSE 500               'waits for initialization response to pass

main:
  DO
    SERIN serinPin, n9600,[noparse][[/noparse]SKIP 2,STR serString\7]
    DEBUG DEC serString," ",DEC reps," ",CR
    reps = reps + 1
  LOOP UNTIL (reps >= 100)



I find that this only shows the 3rd byte and loses the other 3 desired bytes. By changing the SKIP and serString\n values in the SERIN line, I can grab the selected bytes. Can this be done in a command single line? Splitting it into 4 lines induces some serious delays and I miss most of the data I'm looking for.

How do I capture the desired bytes and put them into an array so that I may do math upon them?

Comments

  • skylightskylight Posts: 1,915
    edited 2008-01-18 21:00
    As you are performing math on the results have you thought about trying the free PLX-DAQ software download·from parallax's site, it puts the data into Excel where the maths could be done on it.

    you could take all the 100 results into excel but only use the data you need in a formula.
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-01-18 21:54
    Hi Andy, serString is a 10 byte array, if you use serString without an index it will display index 0 (serString(0)) which in this case is·the 3rd byte

    Your options are to iterate through serString(0) serString(1) serString(2) serString(3) or try

    DEBUG·STR·serString\4,"·",DEC·reps,"·",CR

    Jeff T.
  • Andy McLeodAndy McLeod Posts: 40
    edited 2008-01-18 23:28
    skylight-

    The device is running solely on the stamp, not connected to the computer. Therefore, I'll need a local math solution. i have used the PLX-DAQ software, though, and find it very useful. thanks for the response.
  • Andy McLeodAndy McLeod Posts: 40
    edited 2008-01-18 23:29
    Unsoundcode-

    That looks useful for me. I'll set up the hardware here at home tonight and give it a try.
Sign In or Register to comment.