Crazy base number

Hello guys,

I'm trying to send data from Simulink to an MKR1000 board using a TCP/IP Send block. I can send the data just fine, but when I read it using the client.read() function on arduino IDE, the value doesn't make any sense and I can't figure out what is happening.

I know the value is supposed to be a byte, but the format I'm getting is weird and I can't figure out if it's a mysterious baseWhatever number or something else. Here's the data I'm reading (on the right) for sent numbers from Simulink (on the left):

0 - 0 0 0 0 0 0 0 0
1 - 63 240 0 0 0 0 0 0
2 - 64 0 0 0 0 0 0 0
3 - 64 8 0 0 0 0 0 0
4 - 64 16 0 0 0 0 0 0
5 - 64 20 0 0 0 0 0 0
6 - 64 24 0 0 0 0 0 0
7 - 64 28 0 0 0 0 0 0
...
25 - 64 57 0 0 0 0 0 0
26 - 64 58 0 0 0 0 0 0
27 - 64 59 0 0 0 0 0 0
28 - 64 60 0 0 0 0 0 0
...
45 - 64 70 128 0 0 0 0 0
46 - 64 71 0 0 0 0 0 0
47 - 64 71 128 0 0 0 0 0
48 - 64 72 0 0 0 0 0 0

If it's a byte isn't it supposed to be only 1s and 0s? It seems like I'm getting a byte made of other bytes.

Does anyone know how I can convert these values to int? I've searched for hours but couldn't find a solution. I've already tried all of the Arduino data type conversion functions.

Thanks

What are you sending?

Can we see the tx and rx code (in code tags)…

all data is sent as binary. ascii is binary but represents digits and characters individually. the received data can be "printed" in various ways.

can't say for sure without seeing how the data is sent (binary/ascii) and printed

post the code using </>

Could it be that for some reason the first line starts with a question mark and all the other lines start with an @ character?

Just a guess!

Thanks for the replies. After trying a few things I was able to figure out what the problem was:

The value I was sending from Simulink was a double, which size is 8 bytes (or 64 bits), and it was supposed to have the size of 1 byte (or 8 bits). The client.read() function from the WiFi101 library reads sent bytes, one at a time. After I added a data conversion block in Simulink from double to int8 type I was able to read the right values.

Another info in case someone struggles with a similar problem is that the client.read() function only works with unsigned integers. Negative numbers are represented as positive, starting from 255. So for example, if you send -1, the function will output 255; -2 will be 254, etc

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.