Write byes with SerialConnection? Including values of 0?

Trying to write data out to a serial port. This is on Pi but that shouldn’t matter. It is related to this other topic (Is Pi GPIO Support Dead?) but that part has been settled.

Let’s say I have some Uint8 data that is in an array and some of the values are zero. Many of them are actually. I want to write this out to my SerialConnection. Xojo can only write out strings to a SerialConnection? Can strings contain zero’s? Not the character zero… the value zero like chr(0)?

I have

Var data(14) as UInt8

Where some of the values are zero and other things. This gives a type mismatch:

for i as integer = 0 to 14
next i

And byte by byte was how the code I’m porting from did it. Seems janky to covert it to a string and send it that way. And can a string even have 0’s in the middle of it? Isn’t that a string termination?

Sorry a bit of a noob question but here we are.

Have a look at MemoryBlock, you can load your data into one then write it out using SerialConnection.Write as MemoryBlocks convert automagically to strings.

1 Like

or use ChrB(anybytevalue)


This is the one I’m going with as it was the simplest change to my code:

for i as integer = 0 to 14
next i