Reading multiple bytes

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
MJU
Posts: 502
Joined: Wed Nov 07, 2007 6:51 pm
Location: Antwerp Belgium
Has thanked: 121 times
Been thanked: 108 times

Reading multiple bytes

Post by MJU »

When I read a device sometimes it sends multiple bytes back (serial protocols).
But what is the best way to receive and store all the data that is send back?

Sometimes a 1-wire device sends it 64bits code, sometimes a I2C device sends 3 byte and so on.
How can I make sure I can receive them, and use the data bytes in a Flowcode?

Do I need to make a loop for the amount of bytes I will receive and make store each received byte in a variable?

Any help is welcome..

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Reading multiple bytes

Post by Benj »

Hello,

A good option is sometimes to use an array.

For example here is a receive loop for a RS232 data receive.

idx = 0
rx = 0
while rx < 255
{
rx = RS232 readbyte (10)
decision (rx < 255)
yes: data[idx] = rx
no: data[idx] = 0
idx = idx + 1
}

It is basically loading each byte into the byte array or string variable data.

When a timeout is received (255) a 0 is added to the end of the array to signify the end of the data.

The idx byte is used as the array pointer and once outside the loop can also be used for the number of bytes that were received.

Post Reply