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..
Reading multiple bytes
Moderator: Benj
- 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
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel