Communicate like a telnet connection

Hi everyone,

i want to communicate with an external partner like telnet.

  1. open a coummunication like Telnet (ip: 10.10.10.1 port 4500)
  2. when cennection is open i want to send a command
  3. now I`m waiting for answering.
  4. close communication.

What I tryed till now: a client connection to this hardware,
but its not working like server client.
Have anyone a idea or an example ?

thanks a lot…

Hi,

should be possible in general, I did something similar in the past also.

If the 3rd party device acts like a common unencrypted telnet server, the connection is TCP based and you need to use AsTcp library and act as a TcpClient.

It’s hard to say if it’s really a common telnet server and how to implement without knowing more about the device itself. But I try to give you some general information about telnet.

Telnet itself has no special protocol headers / fields, it’s more or less designed to be a remote console only and is ASCII based.
That means, that a telnet command normally has to end with a carriage return and/or line feed (depends on the servers implementation if CR+LF is needed, or LF only), because that’s normally the way a user finishes his command line input via a keyboard.
From the PLC side that means, that a command sent to a telnet server via TcpSend has to have the command itself as ASCII string followed by CR+LF inside the the send data, for example like ‘myTelnetComnand$r$n’ when using IEC programming languages.

If the telnet server sends some “welcome message”, wants authentication, or similar, then maybe you have to receive first after connecting as client, and check what the server has sent to prepare the right answer (for example, some servers send some information followed by a “login:” prompt, then you have to respond with a user name, and so on - all this also depends on the servers implementation, there’s no strict protocol behind).

I also would suggest to try first to communicate with a terminal program to the device, like TeraTerm, PuTTY or the telnet command (if installed).
This would help to understand what data has to be sent to the device, what end sequence characters are needed, how long it takes until getting a response and how the response looks like.

Best regards!

1 Like

Thank you for this idea!
I tryed the connection with a client program. The only important thing is,
that i have to send the information to the server in a whole String - then it’s
working! (example see above)

MyData[0] := 36; //$
TestString ACCESS ADR(MyData);
brsstrcpy(ADR(s_StringTemp1),ADR(TestString));
brsstrcpy(ADR(s_StringTemp2),ADR(‘A01’));
MyData[0] := 13; //CR
TestString ACCESS ADR(MyData);
brsstrcpy(ADR(s_StringTemp3),ADR(TestString));
brsstrcat(ADR(s_StringTemp1), ADR(s_StringTemp2));
brsstrcat(ADR(s_StringTemp1), ADR(s_StringTemp3));
LibAsTCP1_ST.send_data := s_StringTemp1;
1 Like