Not sure if I am doing this correctly. I created a variable such as "data_string[14]" to send 14 bytes of data via UART to another MCU using a circular buffer to receive the data. The data is organized as:
data_string[0] = byte1
data_string[1] = byte2
.
.
.
data_string[13] = byte14
If I send the string "data_string" NumBytes returns only 1. While if I send data_string[0] to data_string[13] individually, all bytes are received. I can post examples tonight when I get home.
Sending a byte array as a string?
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: Sending a byte array as a string?
Hello,
Are any of your byte values 0?
For a string variable the data bytes usually contain ASCII values e.g. 32 is a space, 48 is a '0' character etc. The 0 tells the function where the string data ends so we don't go off into an uninitialised part of the string variable or even worse off into uninitialised memory or other variables.
So if one of the data bytes is a 0 and you call the send string function then it will only send out data bytes until it hits the 0 and then it will end.
What might be better is to send the data using the send byte function in a loop and this way you know how many bytes you wish to send.
bytestosend = 15
counter = 0
while counter < bytestosend
{
sendbyte string[counter]
counter = counter + 1
}
Are any of your byte values 0?
For a string variable the data bytes usually contain ASCII values e.g. 32 is a space, 48 is a '0' character etc. The 0 tells the function where the string data ends so we don't go off into an uninitialised part of the string variable or even worse off into uninitialised memory or other variables.
So if one of the data bytes is a 0 and you call the send string function then it will only send out data bytes until it hits the 0 and then it will end.
What might be better is to send the data using the send byte function in a loop and this way you know how many bytes you wish to send.
bytestosend = 15
counter = 0
while counter < bytestosend
{
sendbyte string[counter]
counter = counter + 1
}
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
-
- Posts: 170
- Joined: Sat Dec 10, 2011 7:21 pm
- Location: Canada
- Has thanked: 20 times
- Been thanked: 52 times
- Contact:
Re: Sending a byte array as a string?
Thanks Benj. That is basically what I am doing. Just thought I would give it a try with sending as a single string. It is possible that the values of some of the bytes are 0, as they are derived from 10 bit values that are split into high and low bytes. So a variable with a current value under 256 will have a high byte of 0.
-
- Posts: 128
- Joined: Wed Jul 04, 2012 11:21 pm
- Location: Greece
- Has thanked: 51 times
- Been thanked: 19 times
- Contact:
Re: Sending a byte array as a string?
This topics and your answers generally from all the Matrix Team but especially from you BEN are "treasures". The only thing is that you have to dig a lot to find what you are after. But that is ok.Benj wrote: ↑Mon Mar 21, 2016 6:02 pmHello,
Are any of your byte values 0?
For a string variable the data bytes usually contain ASCII values e.g. 32 is a space, 48 is a '0' character etc. The 0 tells the function where the string data ends so we don't go off into an uninitialised part of the string variable or even worse off into uninitialised memory or other variables.
So if one of the data bytes is a 0 and you call the send string function then it will only send out data bytes until it hits the 0 and then it will end.
What might be better is to send the data using the send byte function in a loop and this way you know how many bytes you wish to send.
bytestosend = 15
counter = 0
while counter < bytestosend
{
sendbyte string[counter]
counter = counter + 1
}
Thank you is the minimum i can say for your support efforts.
George