Shop OBEX P1 Docs P2 Docs Learn Events
multiple variables in one UDP with pink — Parallax Forums

multiple variables in one UDP with pink

dwbowendwbowen Posts: 30
edited 2008-07-01 14:55 in BASIC Stamp
Hello all,

Does anyone out there know of a way to send multiple variable in a single UDP message using a pink module? I am using two sets of basic stamp and pink modules to send variables one direction between them. I am able to send and receive·a single variable using...

send:

SEROUT TX, Baud, [noparse][[/noparse]"!NB0WBI:192.168.1.82", CLS]
SEROUT TX, Baud, [noparse][[/noparse]"!NB0WBM:", l_values,CLS]
SEROUT TX, Baud, [noparse][[/noparse]"!NB0SB"]

receive:

SEROUT TX, Baud, [noparse][[/noparse]"!NB0RBM"]·········· ' Send Command To Read UDP Data
SERIN· RX, Baud, 100, timeout, [noparse][[/noparse]l_values]

I thought the logical way to do this is...

send:

SEROUT TX, Baud, [noparse][[/noparse]"!NB0WBI:192.168.1.82", CLS]
SEROUT TX, Baud, [noparse][[/noparse]"!NB0WBM:", l_values,r_values,u_values,d_values,CLS]
SEROUT TX, Baud, [noparse][[/noparse]"!NB0WSB"]

receive:

SEROUT TX, Baud, [noparse][[/noparse]"!NB0RBM"]·········· ' Send Command To Read UDP Data
SERIN· RX, Baud, 10, timeout, [noparse][[/noparse]l_values,r_values,u_values,d_values]

But with this I get communication timeout! on the receiving end. I am using BS2s so the baud is set at 2400 on the pinks. I have attempted to send each of the _values individually in a single program but the receiving end only recognizes the first one (l_values). I am curious, perhaps there is some way to bundle the variables into a single "packet" that can be opened on the receiving end?·Any ideas would be greatly appreciated.

cheers!

Comments

  • DgswanerDgswaner Posts: 795
    edited 2008-06-30 21:58
    I Don't have my stamp manual handy, but it seems like there was a way to append variables back to back, if you had specific lengths for each variable (pad with 0's if necessary) it would be easy to unpack on the receiving end. you could even employ a checksum to ensure you have received everything properly. you'll need to provide more specifics about your data know the best option.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster

    DGSwaner
  • dwbowendwbowen Posts: 30
    edited 2008-07-01 00:43
    DGSwaner,

    Thanks for the reply. I made a few adjustments since my last post. I attempted to define an array of variables. Here some examples of what I am trying to do.

    send:

    ' {$PORT COM13}
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    RX PIN 14
    TX PIN 15

    Baud CON 396

    counter VAR NIB
    nbvar VAR BYTE(16)
    l_values VAR BYTE
    r_values VAR BYTE
    IR_freq VAR WORD

    OUTPUT 3
    OUTPUT 1

    Main:

    FOR counter = 0 TO 4

    LOOKUP counter,[noparse][[/noparse]37500,38250,39500,40500,41500], IR_freq

    FREQOUT 1,1, IR_freq
    r_values.LOWBIT(counter) = ~IN0

    FREQOUT 3,1, IR_freq
    l_values.LOWBIT(counter) = ~IN2

    nbvar(0) = l_values
    nbvar(1) = r_values

    SEROUT TX, Baud, [noparse][[/noparse]"!NB0WBI:192.168.1.82", CLS]
    SEROUT TX, Baud, [noparse][[/noparse]"!NB0WBM:",nbvar,CLS]
    SEROUT TX, Baud, [noparse][[/noparse]"!NB0SB"]

    PAUSE 1

    DEBUG HOME, DEC3 ? nbvar(0)
    DEBUG DEC3 ? nbvar(1)

    NEXT

    GOTO main



    receive:

    ' {$PORT COM14}
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    RX PIN 14
    TX PIN 15

    Baud CON 396

    nbvar VAR BYTE(16)
    l_values VAR BYTE
    r_values VAR BYTE

    main:

    SEROUT TX, Baud, [noparse][[/noparse]"!NB0RBM"]
    SERIN RX, Baud, 100, timeout, [noparse][[/noparse]STR nbvar\16\CLS]

    DEBUG HOME, DEC3 ? nbvar(0)
    DEBUG DEC3 ? nbvar(1)

    PAUSE 1

    GOTO main

    Timeout:
    DEBUG "Communication Timeout!"
    END

    When running these at the same time on their respective stamps I get what I would expect in the debug window for the send: stamp. But on the receiving end I get only readings for nbvar(0). nbvar(1) registers 000. Apparently I do not understand how arrays work or I am missing something important. After checking out section on arrays in the stamp manual I remain confused. Could you explain what you mean by appending variables back to back?

    thank you,
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2008-07-01 07:03
    You have to be aware that CLS is ascii zero, the string terminator for the PINK variables. But your byte variables are in danger of being zeros. In this command,

    SEROUT TX, Baud, [noparse][[/noparse]"!NB0WBM:", l_values,r_values,u_values,d_values,CLS]

    if it happens that your byte variable r_values is zero, that will act not as data but as the string terminator.

    You could get around that by setting the high bit of all the variables. It looks like your program is just using the 5 lowest bits. Or, send the data as ascii HEX:
    SEROUT TX, Baud, [noparse][[/noparse]"!NB0WBM:",HEX2 l_values,HEX2 r_values,HEX2 u_values,HEX2 d_values,CLS]
    and on the receive side,
    SEROUT TX, Baud, [noparse][[/noparse]"!NB0RBM"] ' Send Command To Read UDP Data
    SERIN RX, Baud, 10, timeout, [noparse][[/noparse]HEX2 l_values,HEX2 r_values,HEX2 u_values,HEX2 d_values]

    With regard to arrays, this statement,
    SEROUT TX, Baud, [noparse][[/noparse]"!NB0WBM:",nbvar,CLS]
    does not send the entire array (if that is what you were expecting). It only sends the first element of the array. If you want to send all 16 bytes, this is the syntax
    SEROUT TX, Baud, [noparse][[/noparse]"!NB0WBM:",STR nbvar\16,CLS]
    That and the similar string array command receive will work too with PINK, but keep in mind here too that ascii zero in the string is the same as CLS.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • dwbowendwbowen Posts: 30
    edited 2008-07-01 14:55
    Thanks Tracy,

    That did the trick... I added 1 to each of the variables and used an array. The readings come out good on the receiving end.

    cheers!
Sign In or Register to comment.