SEROUT and Word Array problem
jan dekkers
Posts: 11
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
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
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
·· 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 ?
gForceArray.BYTE0(0), gForceArray.BYTE1(0), 'x
gForceArray.BYTE0(2), gForceArray.BYTE1(2), 'y
gForceArray.BYTE0(4), gForceArray.BYTE1(4), 'z
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
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
or most concisely in the string form,
the same 6 bytes, the 3 word array least significant byte first.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com