serial port - Printing Hexadecimals as Hexadecimals in C#? -
i need send array of bytes hardware (sdz16 matrix) using serial port. trick in fact that hardware expects strings of hexadecimal , ascii characters.
when assigning values array of bytes, if set bytes explicit hexadecimal value (bytes[0] = 0xf2
, instance), print equivalent decimal value (242 instead of f2).
i suspicious problem in console.writeline();
when printing each byte sets them default integers(?) how c# keep track there hexadecimal value inside int?
if assign bytes[0] = 0xf2;
hardware understand in hexadecimal if console.writeline();
shows differently testing?
if want string representation in hex format can using corresponding numeric format string:
byte value = 0xf2; string hexstring = string.format("{0:x2}", value);
note console.writeline
has overload takes format string , parameter list:
console.writeline("{0:x2}", value);
update: had glimpse @ documentation here, , seems need send commands providing corresponding ascii representation in form of string. can ascii representation using:
byte value = 0x01; string textvalue = value.tostring().padleft(2, '0'); byte[] ascii = encoding.ascii.getbytes(textvalue)
my tip check documentation of equipment find out exact format expected.
Comments
Post a Comment