I'm writing some binary protocol messages in .Net using strings, and it mostly works, except for one particular case.
The message I'm trying to send is:
String cmdPacket = "\xFD\x0B\x16MBEPEXE1.";
myDevice.Write(Encoding.ASCII.GetBytes(cmdPacket));
(to help decode, those bytes are 253, 11, 22, then the ASCII chars: "MBEPEXE1."
).
Except when I do the Encoding.ASCII.GetBytes
, the 0xFD
comes out as byte 0x3F
(value 253 changed to 63).
(I should point out that the \x0B
and \x16
are interpreted correctly as Hex 0B
& Hex 16
)
I've also tried Encoding.UTF8
and Encoding.UTF7
, to no avail.
I feel there is probably a good simple way to express values above 128 in Strings, and convert them to bytes, but I'm missing it.
Any guidance?