Do you understand the string
0x01 + "Z" + "00" + 0x02 + "AA" + 0x06 + "10" + "4500" + 0x01 + "MyData"+ 0x04
?
I mean, does
"00"
really mean two 0 characters, instead of
0x00
? Same for
"AA"
: are they really two A characters, or are they rather
0xAA
?
You may have to study and understand the difference between a char value (which is in fact a byte value, at least in ASCII) and its string representation. Example:
0xAA
is the number 170, i.e. a byte value expressed in its hexadecimal representation form;
"AA"
are two 'A' characters, and are stored in memory by the double-byte
0x4141
(because
0x41
is the ASCII code of the 'A' character). Both have not the same in-memory representation.
Same for
0x00
, which is, well, a single byte zero value;
"00"
is a string stored with the double byte
0x3030
(
0x30
is the ASCII code of the '0' character).
Maybe your method could be rewritten to:
private void SendData()
{
TcpClient l_Client = new TcpClient();
int port;
if (!int.TryParse(txtPortNumber.Text, out port) || (port < 0) || (port > 65535))
{
throw new ArgumentOutOfRangeException("txtPortNumber.Text");
}
l_Client.Connect(txtIPAddress.Text, port);
NetworkStream l_stream = l_Client.GetStream();
byte[] data = new byte[]{
0x01,
Encoding.ASCII.GetBytes("Z")[0],
0x00,
0x02,
0xAA,
0x06,
0x10,
0x45,
0x00,
0x01,
Encoding.ASCII.GetBytes("M")[0],
Encoding.ASCII.GetBytes("y")[0],
Encoding.ASCII.GetBytes("D")[0],
Encoding.ASCII.GetBytes("a")[0],
Encoding.ASCII.GetBytes("t")[0],
Encoding.ASCII.GetBytes("a")[0],
0x04
};
l_stream.Write(data, 0, data.Length);
}
(I included a basic port checking - never trust user inputs without checking)
BUT: it's just a guess; I do not have enough reliable information, as what is expected from the LED supplier needs to be clarified.
That's why you need to sort this out by understanding what the supplier really expects you to provide. Once you have understood it, your issue will be solved, because you will be able to provide it the right data structure.
Hope this helps. Good luck.