¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

Simpl+ MAKESTRING sends characters of the bytes and not the bytes


 

Guys, I have this weird problem with Simpl+. I have posted the same to the FB group also so sorry if you see it again.
?
I want to send a string to a device through UDP. The string consists of 10 bytes.
The first 4 bytes are always the same like "\x02\x50\x32\xB7".
The last 2 bytes are always the same like "\x04\x0D".
The 4 bytes in the middle (byte5, byte6 and byte7,byte8) are calculated each time and added to the string and essentially they represent a 32bit long integer.
So I am creating a string like this:
MAKESTRING(command,"\x02\x50\x32\xB7%08lX\x04\x0D",createBytes());
The problem is that the long integer is not received as 4 bytes. It is received as characters resulting in different bytes, as you understand.
For example
if the calculated long integer is 0xFFAABBCC, I am getting \x46\x46\x41\x41\x42\x42\x43\x43, instead of \xFF\xAA\xBB\xCC.
What can I do to fix this? Is there another way to create the string?(btw, concatenation did the same).
I want to send bytes, and not the ASCII values of the characters of the bytes. Any help would be greatly appreciated.


 
Edited

Its not sending ascii, its sending hex.?

In your makestring you are using?\xB7%08lX

l: Specifies a LONG_INTEGER or UNSIGNED_LONG_INTEGER will follow, and is followed by d, u, x, or X.

X: ?Specifies an ANALOG_INPUT, ANALOG_OUTPUT, or INTEGER to be printed as an uppercase hexadecimal number.

The last time I did this I used setbyte()

string tempString[4];
setbyte(tempstring,1,firstbyte);
setbyte(tempstring,2,secondbyte);
setbyte(tempstring,3,thirdbyte);
setbyte(tempstring,4,fourthbyte);

MAKESTRING(command,"\x02\x50\x32%s\x04\x0D",sendstring);

There is most likely a better way to do it, this what I figured out.


 

setbyte did its job. thank you very much!