Thanks Jerson! Here's some more to chew on.
Arrays within Arrays
Along with BYTEs and WORDs, you can have Arrays as part of the "Packet". It's just up to you to make sure that everything fits properly.
Perhaps you need to send a series of A/D samples along with the previous Packet to a VB program on a PC.
By Mapping a WORD Array inside the BYTE array, the Sample data automatically becomes part of the Packet.
This adds a 10 WORD array to the previous Packet. And just for good measure I'll put another BYTE variable after it for a CheckSum.
Code:
MyArray VAR BYTE[29] BANK0
ASM
Arg0 = _MyArray ; word
Arg1 = _MyArray + 2 ; byte
Arg2 = _MyArray + 3 ; word
Arg3 = _MyArray + 5 ; word
Arg4 = _MyArray + 7 ; byte
Samples = _MyArray + 8 ; 10 WORD array (20 bytes)
ChkSUM = _MyArray + 28
ENDASM
Arg0 VAR WORD EXT
Arg1 VAR BYTE EXT
Arg2 VAR WORD EXT
Arg3 VAR WORD EXT
Arg4 VAR BYTE EXT
Samples VAR WORD EXT ; 10 WORD array
ChkSUM VAR BYTE EXT
Note here that you don't need to specify the array size for the Samples variable. But you do have to leave enough room for it in the array.
And if you get an "Unable to fit variable ____ in requested bank x" warning, change the BANK0 modifier to BANK1 or another bank that has room.
The entire array must be in a single bank for this technique to work.
Now you can just take the A/D samples and store them in the WORD array...(which is really in the MyArray).
Code:
FOR X = 0 to 9
ADCIN 0, Samples(X)
NEXT X
Calculate a CheckSum for the whole Packet...
Code:
ChkSUM = 0
FOR X = 0 to 27
ChkSUM = ChkSUM ^ MyArray(X)
NEXT X
And with very little program space used, you have a Complete Packet with 5 WORD or BYTE variables, 10 word sized A/D samples and a checksum for data integrity, ready to send with ...
Code:
HSEROUT ["Header", STR MyArray\29]
And, once again, it's bi-directional. You can receive the Packet of Samples just as easily, with ...
Code:
HSERIN [wait("Header"), STR MyArray\29]
Bookmarks