I am trying to send commands to a machine
The machine accepts the packet with a byte array...
I need to build a form that will allow the user to enter the command in char format and then convert it to a byte array for example
I can send the machine
byte[] packet =
{
((byte) (0x02)),
((byte) (0x05)),
((byte) (0xFF)),
};
I need the user to be able to input for example "0x02 0x07 0x03 0xFF"
and the string from the textbox.text be converted into a byte array with the for 4 byte values that represent the ansi format
I tried without success:
byte[] packet =
{
((byte) (string1)),
((byte) (string2)),
((byte) (string3)),
OP's Answer moved to here:
tried to google it already and frustrating that I can't find anything.
if I use the code from the above link, it interprets each digit and letter with a value
for the example below the byte array had 14 items. I need to get the 3 values. I would probably deliminate the string by spaces and then get the values for each one
In this case
0x02= 2
0xFF = 255
0x03 = 3
or a way that I can get the string and convert the literal string "0x02" and add it to to a byte array with its byte value
System.Text.Encoding enc = System.Text.Encoding.ASCII;
byte[] myByteArray = enc.GetBytes("0x02 0xFF 0x03");