Jump to content

Reuse Socket


Javier Camusso

Recommended Posts

Hi everyone!

I´m using the four sockets in a Vision 130, and I need more!

So, I tried to redifine a socket in run time according to some conditions, but I find out that once the socket was defined,  I can´t redefine it.

The socket is first initialized as TCP / Port 502 / Server. A Modbus IP configuration is attached to this socket, and running as Modbus IP Slave.

 FirstDefintion.PNG.95321219ee44a9a90485ac9ef7a3b37b.PNG

Then, I close the socket...

ReDefine1.PNG.444833b3b27e1ffdc9ba21b12c6bd87c.PNG

...and redefine it as UDP

ReDefine2.PNG.f18c1fe88a7dc1d43ee7cc7bd38c05a5.PNGReDefine3.PNG.23318ff8cb2d81e497a72f071b9bd295.PNG

The result is that the socket never loose the Modbus definition, and can´t connect via UDP.

SocketState.PNG.9a5d85236fc1b42db1a6c8a7a5c229b7.PNG

When the second socket definition is executed, the socket state goes from 20 to 34.

 

If I insert a reset of the PLC before the second definition, all runs correctly.

So, I think that the only way to "release" the socket definition is restarting the PLC. Is this right? Or (more likely) I am doing something wrong?

 

Thank you very much!!

ReDefine.PNG

Link to comment
Share on other sites

  • MVP 2023

I've done this many times. All you need to do is Close the Socket, re-execute the MODBUS IP Configuration with the new attributes, then re-connect the Socket with the new attributes. I've never had any problem as long as I allow the few seconds if takes perform all the tasks. There is no need to restart the PLC.

 

Edit: I see you're actually redefining the Protocol also. I've never tried that, but I suspect re-initializing the Socket and re-executing the Configuration block should work. The guys at support@unitronics.com should be able to give you a definitive answer on this.

Link to comment
Share on other sites

  • MVP 2023

Flex says:  "allow the few seconds" and I think this is your error.  Either implement the stages via timers, or create an incremental counter using compares that does the same thing triggering actions a few seconds apart.  You could even perhaps use a drum sequencer for this, but as it's not many steps it's a tossup as to the mechanics of how you do it.

Edit:  Forgot to add that it looks like you are doing the close and init in the same scan, which is the likely main cause.  I'd trial my "seconds apart" method first, then work backwards.  Load up the buffer to your maximum and find the shortest time possible for your system, for what I suggest, that works reliably. 

Pls let us know how you go.

cheers,

Aus

Link to comment
Share on other sites

Flex: Thanks for your answer!

Going a little deeper, the application normaly uses this socket for modbus comm as slave. In some conditions, I need to use this socket for a time synchronization. For this second use, I need the connection as UDP, and don´t have any modbus config to define.

All I can do is stop the modbus listener rung...

MBlistener.png.1725c34669ce4a4d60b5b47706c79ee1.png

...close the socket...

ReDefine1.PNG.d5bb6d405a6c91b6d675caa62e99c876.PNG

...and initialize as UDP.

ReDefine2.PNG.6625030af4681b1e21db8bb1e9f117d0.PNG

 

Link to comment
Share on other sites

Aus: Thanks for your answer!
You are right on this. I normally play with instruction orders, or I use a label to go to end of ladder when launching or modifying a connection. The PLC executes the communications at the end of ladder scan. So, I force it to do this before evaluating any connection condition.
In this case, I am in test stage, so I´m using manual flags to run any single rung. This assures to avoid any timing trouble.

Link to comment
Share on other sites

SOOLVED!!!

Looking to the problem, I've tried to set the protocol type manually, and YES! It works!

After initializing the socket, I set the socket protocol manually in 0.

Starts the synchronization, and it works.

There is no need to close the socket. I think that closing the socket only got effect on TCP MASTER connections.

If you are interested, you can find the details attached.
Thanks everyone!

Solved.pdf

  • Like 1
Link to comment
Share on other sites

  • 8 months later...

Hello,

I'll revive this topic because I ran into a similar problem and seek advice.

Does anyone know what are the codes for socket states?

I also have to reuse a socket but protocol remain the same (0=PC applincation). Socket 3 at the beginning is TCP / Port 20259 / Server, then, at 4 o'clock every night, initialized to UDP / Port 123 to update the time and after that reinitialized back to TCP.
It works fine for the first time (after PLC restart), but every try after is unsuccessful. Socket 3 state is 34 and there's no explanation in help files about socket states that I could find. When RFC function runs, Tx counter increments by 1, Rx remains the same for Socket 3.

Other controllers that have UDP port dedicated for this purpose (no init block after startup) don't experience this problem.

I'll fiddle with troubleshooting some more to find a workaround if possible in the meantime.

Update time.PNG

Link to comment
Share on other sites

This is what I found:

It will work normally as long as no TCP connections take place on Socket 3, like accessing from VisiLogic or Remote Operator. As soon as PC connects at least once it will not work until PLC restarts. It doesn't matter if PC-PLC connection disconnects normally or it is violently broken.

I don't know how to clear  whatever PLC set in its memory. I tried closing the socket and then initializing it to other TCP and even this Modbus workaround Javier did but it doesn't work.

Link to comment
Share on other sites

Hello Aus,

I also set SB168 at power up, I tried messing with system bits but that didn't work.

What I found to work is next sequence:

- Init Socket 3 to TCP master (port as before 20259)
- Delay 2 seconds
- TCP connect on Socket 3 to timekeeper Server on port 123
- Delay 2 seconds
- Init Socket 3 to UDP, port 123
- Delay 2 seconds
- Whole update sequence
- After 1 minute Init block to restore Socket 3 to original settings

I don't know why it works, but it works. Hope this helps someone.

Link to comment
Share on other sites

  • MVP 2023
19 hours ago, Isakovic said:

- Init Socket 3 to TCP master (port as before 20259)
- Delay 2 seconds
- TCP connect on Socket 3 to timekeeper Server on port 123
- Delay 2 seconds
- Init Socket 3 to UDP, port 123
- Delay 2 seconds

I didn't remember (my brain plate is slippery sometimes these days) but we found a similar solution switching a port between Modbus Master and Slave using the same socket.

The key is to insert timers between Socket commands to let the system catch it's breath.  We found 0.5 seconds works OK.

Good job!

Joe T.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...