Shop OBEX P1 Docs P2 Docs Learn Events
SEROUT and Word Array problem — Parallax Forums

SEROUT and Word Array problem

jan dekkersjan dekkers Posts: 11
edited 2009-07-06 15:55 in BASIC Stamp
I am having a weird problem. When I Send the data using a Array of word The data is garbled
When I pass them as bytes it comes true correctly.

IDEND·········· CON···· $FF
gForceArray···· VAR···· Word(3)
DO
··· gForceArray(0) = 10
··· gForceArray(1) = 20
··· gForceArray(2) = 30

··· 'NOT OK
··· SEROUT TX, T9600, [noparse][[/noparse]1,······
······························· gForceArray.BYTE0(0), gForceArray.BYTE1(0),· 'x
······························· gForceArray.BYTE0(1), gForceArray.BYTE1(1),· 'y
······························· gForceArray.BYTE0(2), gForceArray.BYTE1(2),· 'z
······························· 0,0,0,IDEND]
··· PAUSE 100
··· 'OK
··· SEROUT TX, T9600, [noparse][[/noparse]9,······
······························· 10, 0,· 'x
······························· 20, 0,· 'y
······························· 30, 0,· 'z
······························· 0,0,0,IDEND]
··· PAUSE 100
LOOP


The data received at a PC.

This is OK "Passed as Bytes" Note: 1st 9 is an indicator
9 10 0 20 0 30 0 0 0 0 255
This is not OK "Passed as BYTE 0 and BYTE 1 of the word array Note: 1st·1 is an indicator
1 10 0 0 20 20 0 0 0 0 255
and so on
9 10 0 20 0 30 0 0 0 0 255
1 10 0 0 20 20 0 0 0 0 255
9 10 0 20 0 30 0 0 0 0 255
1 10 0 0 20 20 0 0 0 0 255
9 10 0 20 0 30 0 0 0 0 255
1 10 0 0 20 20 0 0 0 0 255
9 10 0 20 0 30 0 0 0 0 255
1 10 0 0 20 20 0 0 0 0 255

Comments

  • dev/nulldev/null Posts: 381
    edited 2009-07-06 00:39
    I don't understand why you would send a number stored in a Word as two bytes...
    I'd rather use:
    gForce1 VAR Word
    gForce2 VAR Word
    gForce3 VAR Word

    SEROUT TX, T9600, [noparse][[/noparse]1,
    STR gForce1\2, 0 'x
    STR gForce2\2, 0 'y
    STR gForce3\2, 0 'z
    0,0,0,IDEND]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    /dev/null
  • jan dekkersjan dekkers Posts: 11
    edited 2009-07-06 03:15
    I want to send them as a byte and not as a String. The problem is that
    ·· SEROUT TX, T9600, [noparse][[/noparse]1,······
    ······························· gForceArray.BYTE0(0), gForceArray.BYTE1(0),· 'x
    ······························· gForceArray.BYTE0(1), gForceArray.BYTE1(1),· 'y
    ······························· gForceArray.BYTE0(2), gForceArray.BYTE1(2),· 'z
    ······························· 0,0,0,IDEND]
    is not working as expected and sending them as STR is not solving my problem.

    Why is this happening ?
  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-06 03:27
    When you use a suffix like BYTE0, any subscript is from the beginning of the variable and is in the units of the suffix. You need:

    gForceArray.BYTE0(0), gForceArray.BYTE1(0), 'x
    gForceArray.BYTE0(2), gForceArray.BYTE1(2), 'y
    gForceArray.BYTE0(4), gForceArray.BYTE1(4), 'z
  • jan dekkersjan dekkers Posts: 11
    edited 2009-07-06 03:42
    Thanks for the answer Mike, thats works great although I dont understand why:

    gForceArray(0) is a word so Byte0 and Byte1 gives me the low and high byte

    if I use

    gForceArray(4) isnt that out of the bounds of the Array of 3 "0 1 and 2" ?

    Jan
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2009-07-06 15:55
    No, when you write
    gForceArray(0)
    it is an array of 3 words, but
    gForceArray.BYTE(0)
    is an array of 6 bytes.

    You could also write it as
    FOR idx=0 to 5
       SEROUT TX, T9600, [noparse][[/noparse] gForceArray.byte0(idx)]
    NEXT
    



    or most concisely in the string form,
    SEROUT TX, T9600, [noparse][[/noparse] 1,STR gForceArray.byte0\6,0,0,0,IDEND]
    



    the same 6 bytes, the 3 word array least significant byte first.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.