Hi,
Glad the basic connection is working.
LDClient.SendMessage can take either a number or a string as input. The input is then converted into a string, then array of bytes (each byte is the ascii character code value) with trailing null terminator before sending.
I would recommend sending a string so it is clear what you are sending, e.g. LDClient.SendMessage("0030500000000"). If you send just a number LDClient.SendMessage(0030500000000) it would be interpreted as "3050000000" - conversion from number to string would loose the leading zeros. This is the extension code behind SendMessage.
Secondly, you say you want to send bytes - there is a distiction between byte values and their ascii representation. A byte is a number between 0 and 255 (in decimal and FF in hex), and each value represnets a character, so the character "0" is 48 (dec) or 30 (hex), see https://www.ascii-code.com. If you want to send pure byte numbers then you will have to form the string using Text.GetCharacter(code), where code is the byte value.
One suggestion is to try to read from the server first (if you know how to get it to send a message), and see what it looks like.
If you have a link to some documentation for the server device that you can share, there may be more detailed info on the data format required and some way to check what was received by the server.
Glad the basic connection is working.
LDClient.SendMessage can take either a number or a string as input. The input is then converted into a string, then array of bytes (each byte is the ascii character code value) with trailing null terminator before sending.
I would recommend sending a string so it is clear what you are sending, e.g. LDClient.SendMessage("0030500000000"). If you send just a number LDClient.SendMessage(0030500000000) it would be interpreted as "3050000000" - conversion from number to string would loose the leading zeros. This is the extension code behind SendMessage.
Code:
if (!tcpClient.Connected) return "NOT_CONNECTED";
Byte[] bytes = Encoding.UTF8.GetBytes(message + '\0');
NetworkStream networkStream = tcpClient.GetStream();
networkStream.Write(bytes, 0, bytes.Length);
return "SUCCESS";
Secondly, you say you want to send bytes - there is a distiction between byte values and their ascii representation. A byte is a number between 0 and 255 (in decimal and FF in hex), and each value represnets a character, so the character "0" is 48 (dec) or 30 (hex), see https://www.ascii-code.com. If you want to send pure byte numbers then you will have to form the string using Text.GetCharacter(code), where code is the byte value.
Code:
char = Text.GetCharacter(48)
TextWindow.WriteLine(char)
code = Text.GetCharacterCode("0")
TextWindow.WriteLine(code)
One suggestion is to try to read from the server first (if you know how to get it to send a message), and see what it looks like.
Code:
result = LDClient.Connect("192.168.2.20:15730", "False")
If (result = "SUCCESS") Then
msg = ""
LDClient.ServerMessage = OnServerMessage
While("True") 'Keep the program running - we would do more here later
If (msg <> "") Then 'We have a message
TextWindow.WriteLine("Client message received : "+msg)
msg = "" 'Message handled
EndIf
Program.Delay(10)' Don't mash cpu
EndWhile
EndIf
Sub OnServerMessage
msg = LDClient.LastServerMessage
EndSub
If you have a link to some documentation for the server device that you can share, there may be more detailed info on the data format required and some way to check what was received by the server.