Store PLCnext CommunityPLCnext on LinkedInPLCnext on Instagram  PLCnext on YouTube Github PLCnext CommunityStore PLCnext Community

  1. Dan Clark
  2. PLCnext Engineer
  3. Wednesday, 01 May 2019
I am working on a project where I need to create an IP socket to connect to another device to PLCnext to send and receive XML data. In PCWorx there are function blocks called IP_Connect, IP_USEND, and IP_URCV which was used previously to do this operation. A library from a previous version of PLCnext Engineer (PCworx Engineer), has these function blocks in a library called "Standard Controller", but it is not compatible with 2019.3. Are these blocks going to be available in a new library?
Accepted Answer
Martin PLCnext Team Accepted Answer Pending Moderation
0
Votes
Undo

Hello,

In your code, you need to pass the value from "UDP_SOCKET1.HANDLE" in to the "UDP_RECEIVE1.HANDLE" parameter. It looks like you are instead passing a different variable which has the value zero, which is probably why the RECEIVE FB is complaining that the port is not connected.

The video below shows a UDP Socket receiving data OK. In this example the "TC Router" is simulated by a Linux shell on another machine that sends a UDP message to the PLC. 

Phoenix Contact Electronics Headquarters - PLCnext Runtime Product Management and Support
  1. more than a month ago
  2. PLCnext Engineer
  3. # Permalink
Martin PLCnext Team Accepted Answer Pending Moderation
0
Votes
Undo
Hello,
In the PLCnext Engineer "Programming" branch (in the Components window on the right), there's a set of function blocks in the folder Extended -> Functions ... -> Ethernet.
I think these FBs are what you need?
- Martin.
Phoenix Contact Electronics Headquarters - PLCnext Runtime Product Management and Support
  1. more than a month ago
  2. PLCnext Engineer
  3. # 1
Dan Clark Accepted Answer Pending Moderation
0
Votes
Undo

Martin,

These blocks do work, but there is a function on IP_connect to create a passive socket that listens for traffic on a specific port. This functionality is not possible with the TCP_Socket blocks, because it requires the device to request a socket from the PLC. The device I am connecting to does not request for a socket, it only sends data to a specific IP and port when received.

  1. more than a month ago
  2. PLCnext Engineer
  3. # 2
Martin PLCnext Team Accepted Answer Pending Moderation
0
Votes
Undo

Hi,

I'm afraid I don't understand the problem ... on the TCP_SOCKET block, you should set the following input parameters:

ACTIVATE = TRUE (starts listening for the remote device to connect)

IS_SRV = TRUE (the function block creates a listening (server) socket).

BIND_IP = the ip address of your PLC. (The server listens at this IP address for incoming connections. Clients, which want to connect to this server, have to specify this IP address)

BIND_PORT = The port number you want the remote device to connect to.

DEST_IP  - Only requests from the client with this IP address are accepted. If the string is empty or contains the value 0.0.0.0., any client IP address is accepted.

DEST_PORT  - Only requests from the client with this IP port are accepted.If the string is empty, any client IP port is accepted.

The remote device simply needs to connect to the PLC using the BIND_IP and BIND_PORT that you specified above.

You can then use the HANDLE output from the TCP_SOCKET FB in your TCP_RECEIVE function block, to receive messages from the remote device.

Your remote device doesn't need to do anything differently.

Perhaps I am misunderstanding something about your application?

- Martin.

Phoenix Contact Electronics Headquarters - PLCnext Runtime Product Management and Support
  1. more than a month ago
  2. PLCnext Engineer
  3. # 3
Dan Clark Accepted Answer Pending Moderation
0
Votes
Undo

Martin,

For the application, I am connecting to the TC router and using the SMS forwarding function. This function does not create a TCP socket with the controller, it only sends an xml code to the specified IP and port in the TC router's settings. For a TCP port to become active, the TC router needs to send a request to open a socket; which is not possible. The IP_Connect block does not require a socket to be created and active, it listens for traffic on the specified IP address and port. Hopefully this makes more sense as to what I am looking for.

  1. more than a month ago
  2. PLCnext Engineer
  3. # 4
Martin PLCnext Team Accepted Answer Pending Moderation
0
Votes
Undo

UPDATE - Read the next message (I will leave this one here as a reminder that 99.9% certainty is still enough to be wrong    :-)

======================

I don't have a PLC with me to test this, but I am 99.9% sure that this statement is not correct:

"For a TCP port to become active, the TC router needs to send a request to open a socket".

While the ACTIVE input on the TCP_SOCKET function block is TRUE, the PLC will be listening for unsolicited messages from the TC Router. You can even set the ACTIVE input to TRUE unconditionally, so the PLC will always be listening (just make sure all the other parameters are set on the one scan cycle when ACTIVE transitions to TRUE, because that's the only time these parameters are considered by the FB).

Then, when an unsolicited message arrives from the TC Router, the PLC will be listening, and the TCP_RECEIVE block that has the TCP_SOCKET handle will receive the message.

If you have tried this and cannot get it working, please let me know and we will set it up here.

- Martin.

Phoenix Contact Electronics Headquarters - PLCnext Runtime Product Management and Support
  1. more than a month ago
  2. PLCnext Engineer
  3. # 5
Martin PLCnext Team Accepted Answer Pending Moderation
0
Votes
Undo

OK, so I have just checked the manual for the TC Router and it uses UDP to send messages, not TCP. In this case, the PLC must use the UDP function blocks instead of the TCP function blocks. The UDP function blocks look and behave similar to the TCP blocks, so pretty much everything in the discussion above will be relevant for these blocks too (and I'm 99.9% sure this will work   :-)

Sorry for the detour through TCP-world ... I should have clarified "TCP or UDP?" from the start.

Let me know how you get on with the UDP function blocks.

- Martin.

Phoenix Contact Electronics Headquarters - PLCnext Runtime Product Management and Support
  1. more than a month ago
  2. PLCnext Engineer
  3. # 6
Dan Clark Accepted Answer Pending Moderation
0
Votes
Undo

Martin,

Thank you very much for the explanation! Is this the case only for the SMS forwarding function? I have had success with the TCP blocks for other functions with the TC router.

  1. more than a month ago
  2. PLCnext Engineer
  3. # 7
Martin PLCnext Team Accepted Answer Pending Moderation
0
Votes
Undo

You need to check the device manual to see which what IP communication interfaces it has, and what IP protocol(s) each interface supports (e.g. TCP, and/or UDP).

The TC Router, has at least three IP comms interfaces, which are described in the sections of the manual shown below. You can see that they explicitly mention whether each interface uses TCP or UDP ... this is very important information!

 

1. TCP Socket server for receiving and responding to commands from a client.

 Snag 44c1cf7

 

2. UDP client that sends incoming SMS messages to UDP listener(s).

Snag 44c3dae 

 

3. UDP client that sends log files to a server.

 Snag 44c70e4

Snag 44c55da

 

Hope this helps.

Phoenix Contact Electronics Headquarters - PLCnext Runtime Product Management and Support
  1. more than a month ago
  2. PLCnext Engineer
  3. # 8
Dan Clark Accepted Answer Pending Moderation
0
Votes
Undo

Martin,

I tried using the UDP socket and still have no connection with the socket. I have attached screenshots from my test project and the TC Router logs. The error code on the UDP socket block is "The application tried to send or receive data, and the socket is not connected." and on the TC Router the log shows that the connection was refused when trying to forward a SMS. 

Attachments (2)
  1. more than a month ago
  2. PLCnext Engineer
  3. # 9
Oliver PLCnext Team Accepted Answer Pending Moderation
0
Votes
Undo

Hello dclark3774,

Can you attach the TC Router settings?

You could create a tcpdump recording on your PLC to see what happens with the connection attempt of the client.

Also it might be usefull to record the Status of your UDP Socket FB.
You could use the Logic Analyser for that or create a ring buffer that stores the status whenever it changes.

 

Phoenix Contact Electronics Headquarters - PLCnext Runtime Product Management and Support
  1. more than a month ago
  2. PLCnext Engineer
  3. # 10
  • Page :
  • 1


There are no replies made for this post yet.
However, you are not allowed to reply to this post.