Jump to content

Question about using unitronics PLC as Modbus TCP Master/Slave


Recommended Posts

 

So, I already have a "SCADA" like system pulling data to my PLCs over Modbus TCP , but I want to connect some devices to each PLC over Modbus too.

image.thumb.png.7c85bbe7726a6c5fef959dc340a3ffc2.png

 

Basically, I need to run the PLC as a master for a sub network, and as a slave for the other one. I was able to do it without problems testing with one slave, so far so good


Now, I require to add more slave devices to the PLC (Master) 

To communicate to other slaves, do I need then to close the socket I am using with device 1 and then open it again to connect to the IP of device 2?


If that is the case why do we have an option to add a list of slaves? is there a way to switch the communication or connect to multiple slaves at the same time?

image.png.47aa9653b1898e43b17f64de8b2718e2.png

so in the given scenario that I want to control 7 devices over Modbus TCP, will I need to connect and disconnect to each one of them? Or do I need to use one socket per device?.. 
I will need to implement the same logic for V700 and for V570, socket wise I feel like I am already short  😩 , I am using 1 for "SCADA", 1 for the remote operator, and 1 SD card explorer/debugging, but eventually I want to add an FTP client for data transfer and stop using the SD card explorer (which uses 2 sockets).

 

 

 

 

 

 

 

Link to comment
Share on other sites

  • MVP 2021
14 hours ago, Gabriel Franco said:

What I do is to use UDP instead of TCP (for the socket using Modbus).

That is something I've been wanting to look into, but I have little experience with UDP (as opposed to TCP that I use every day). Can you direct me to an overview or tutorial for UDP? Are there any issues with mixing UDP and TCP on the same network? What are the disadvantages to using UDP vs. TCP?

Link to comment
Share on other sites

Mod add, pinned in "topics almost worth pinning"

1. Initialize the socket as usual, but using UDP instead TCP.

image.png.982d48f18cb7d32a323221b49e478317.png

2. Configure Modbus TCP.

image.png.848a9c2cb0e247b2a64d86acba3eeda2.png

3.  Execute Modbus function. There is not need to open socket nor wait for open connection.  What I do here is to increase a pointer to read sequencialy all slaves.

image.png.b47b4aa8d30793b3b835d6075b8c7d89.png

4. Wait for response and process your data.

image.png.8aa7f85ad270e6f07b2e5dfc8e74f101.png

 

On 5/6/2022 at 11:30 PM, Flex727 said:

 Are there any issues with mixing UDP and TCP on the same network? What are the disadvantages to using UDP vs. TCP?

I´ve used up to 4 sockets mixing TCP, UPD and TCP_Raw with no problems at all. Keep in mind that each socket acts as a logical port, so you may use each one with its own port number and protocol.

UDP disadvantages:

1. Packages lost because of inherent lack of error check of UDP, but it´s compensated with more speed and less comms overhead. 

2. Some devices only accept TCP connections.

 

 

  • Thanks 1
Link to comment
Share on other sites

Thanks @Gabriel Franco  I think UDP will be my way to go for sending/recieving telegrams from/to PLC

 

image.thumb.png.5af5d136c49d611eca8d014340817545.png

 

the implementation was straight forward just open the socket and let it be. The PLC will be listening or sending whatever you throw to him no maters what
I don't know if it will work with the other Modbus devices, but sure I have an application for this.I needed to figure out how to broadcast messages to the PLC from a web interface and I was already using a Modbus TCP socket to collect data to another server. 

 

 

 

Link to comment
Share on other sites

Following up on this topic, does anyone know if or how to use the remote operator through an UDP connection?

 

I see that there is an option to use UDP, in my case If i could use an UDP connetion for multiple purposses it wil be awesome  because I no longer will need to keep switching the sockets

image.png.88444e40766d4135138c369e00b41851.png

Link to comment
Share on other sites

3 hours ago, Fernando Castro said:

Following up on this topic, does anyone know if or how to use the remote operator through an UDP connection?

 

I see that there is an option to use UDP, in my case If i could use an UDP connetion for multiple purposses it wil be awesome  because I no longer will need to keep switching the sockets

image.png.88444e40766d4135138c369e00b41851.png

Who would say, the answer was in the manual 🤣


image.png.e6a0748f96beda63d8ffa91728e3d02c.png

  • Thanks 1
Link to comment
Share on other sites

  • 2 months later...

So I finally have my Modbus slaves and then during my tests, I stumble across another estrange Unictronics thing.

Modbus master on v700 works fine I can read and write to a pneumatic valve terminal over Modbus TCP/IP, However when I ported the program to v570 that one can not connect to the same Modbus slave (Just for clarification, I am testing each PLC at the time. I am not trying to communicate 1 slave to 2 masters ).

All my PLCs are also Modbus slaves to collect data from another higher level master, so with the same setup I tried to test the communication between PLCs:

  • v700 as master can connect to v570 as a slave, but not the other way around. If I try to use v570 as a master to read from v700 as slave SB150 in v570 is always 0 (I'm using socket 3 port 502 for Modbus masters).
  • Funnier but estranger, a virtual plc on my computer as a slave does connect to v570 and SB150 sets to 1, and also v700 connects to the virtual PLC without problems

So, is the MODBUS implementation as master on v570 different from v700 somehow?

 

Link to comment
Share on other sites

  • MVP 2021
36 minutes ago, Fernando Castro said:

However when I ported the program to v570

V700 is not equal to V570. Then you must program different master code for this two PLC. Pease post ported to V570 communication code.

 

From help Vision700 - Using Ethernet

The V700 comprises a special Ethernet card that offers 8 sockets. Note that your V700 applications implement Ethernet differently from applications using other Vision controllers.

Certain Ethernet system operands are not relevant for the V700. The function of some system operands are replaced by a communication function located under the COM>TCP/IP menu, called V700: Read Socket Status.

The V700: Read Socket Status function checks the status of the selected socket according to the specified Socket Status requested, then saves the status indication into the linked operand.

Link to comment
Share on other sites

43 minutes ago, kratmel said:

V700 is not equal to V570. Then you must program different master code for this two PLC. Pease post ported to V570 communication code.

 

From help Vision700 - Using Ethernet

The V700 comprises a special Ethernet card that offers 8 sockets. Note that your V700 applications implement Ethernet differently from applications using other Vision controllers.

Certain Ethernet system operands are not relevant for the V700. The function of some system operands are replaced by a communication function located under the COM>TCP/IP menu, called V700: Read Socket Status.

The V700: Read Socket Status function checks the status of the selected socket according to the specified Socket Status requested, then saves the status indication into the linked operand.

OK, I forgot to mention that when porting I also took that in to consideration,  I checke the socket status responses on a custom addresses using the codes indicated I the manual. 

 

the SB150 is the way I am tracking specifically that v570  Is not connecting socket 3.  for v700 is entirely different. 

and the problem is that both systems connect and work with the virtual PLC but then using the actual devices v570  does not work

 

but again taking aside the specific SB /SI for each l d, the core logic is the same. 

 

 Card Init - > Socket Init - > Modbus Config - > Socket Connect - > MODBUS Read/Write -> Socket close. 

 

same IPs, same devices same ports, different results ussing v570 vs v700.

 

Link to comment
Share on other sites

This is a simplification but: on Main i have modbus config, after initialization.

image.thumb.png.b6fd23bb434a6bd1664088a519557b99.png

image.png.0d5764a863d8605ecd3775cd2928a023.png

Initialization sub calls Network

image.png.1275f933004430879bb4c43d3ec5c1a0.png

Network is just this, socket 3 Is what I care about right now:

image.png.7c8cc5846ffe25ad07fb509f0dcb01be.png

 

I already eliminated all the logic while I trying to troubleshoot. this just reads one MI, and write a single coil (on each press it toggles the value so on each press should be turning on /off the coil) connect, read, write  and close are triggered by on screen buttons. It can not be simplified more than this.

 

The modbus slave is configured without timeout  so, once TCP/IP connect has been activated, it will receive the read/write instructions until I disconnect.

 

image.thumb.png.59f6437930ec7f489c836646634ebdce.png

 

 

I pasted some screenshtots from the other project  by mistake, already fixed it

 

Link to comment
Share on other sites

  • MVP 2021

In Communication folder Sample code  for V280 Ethernet TCP (maybe for V570 also) we can see this comment

Below, both Ethernet card initialization and MODBUS Configuration are done as Power-up tasks.
Note that Socket 2 must be initialized, via the Socket Init FB, to function as a TCP Master. Network ID number MUST be 255!

Maybe it is mistake in sample code.... or maybe not....

But no sample code for V570 as Master pesent in Example (only for slave).

Link to comment
Share on other sites

6 minutes ago, kratmel said:

In Communication folder Sample code  for V280 Ethernet TCP (maybe for V570 also) we can see this comment

Below, both Ethernet card initialization and MODBUS Configuration are done as Power-up tasks.
Note that Socket 2 must be initialized, via the Socket Init FB, to function as a TCP Master. Network ID number MUST be 255!

Maybe it is mistake in sample code.... or maybe not....

But no sample code for V570 as Master pesent in Example (only for slave).

Interesting, I'm pretty sure that already tried ID as 255 but I'll give it another try .... I was under the impression that on ModbusTCP/IP the ID's are irrelevant but anyway I hope is something along those lines.

 

 

Link to comment
Share on other sites

  • MVP 2021

Maybe Creators know something about V570 as TCP master and do not place V570 master project to Examples :)

In V280 example used Socket 3 but in comments quoted Socket 2.... Strange...

I found JT sample Master code for Samba - Network ID 255 used.

Link to comment
Share on other sites

9 minutes ago, kratmel said:

Maybe Creators know something about V570 as TCP master and do not place V570 master project to Examples :)

In V280 example used Socket 3 but in comments quoted Socket 2.... Strange...

I Hope Not!. We already purchased a lot of modbus capable devices because was easier to install... assuming modbus works hahaha. seriously I had a problem because some PLCs didn't had enough outputs available and I will require expansion modules, then the wiring on some of the cabinets will be slightly different wich is no good for standarization... the modbus option gives me more flexibility

  • Upvote 1
Link to comment
Share on other sites

  • MVP 2021
2 hours ago, Fernando Castro said:

I was under the impression that on ModbusTCP/IP the ID's are irrelevant

I am under that same impression.

2 hours ago, kratmel said:

Maybe Creators know something about V570 as TCP master and do not place V570 master project to Examples :)

I have programmed Vision PLCs using MODBUS TCP maybe a couple hundred times. I mostly use V570, V1210, & V700 in various combinations. I have never had an issue with MODBUS TCP not working properly in any scenario.

Link to comment
Share on other sites

  • MVP 2021
2 hours ago, Fernando Castro said:

I already eliminated all the logic while I trying to troubleshoot. this just reads one MI, and write a single coil (on each press it toggles the value so on each press should be turning on /off the coil) connect, read, write  and close are triggered by on screen buttons. It can not be simplified more than this.

You're welcome to post a simplified program here for master & slave that you are unable to get to work properly and I'll load them up on my test bench to see what I find. I have several V570s, V1210s, and V700s that I can set up any way needed. You can also PM me if you prefer and I'll give you my email address.

Link to comment
Share on other sites

  • MVP 2021

Further to all the good help Flex and Kratmel are doing....

15 hours ago, Fernando Castro said:

Funnier but estranger, a virtual plc on my computer as a slave does connect to v570 and SB150 sets to 1, and also v700 connects to the virtual PLC without problems

So your virtual PLC is communicating slightly differently to what the Unitronics stuff is doing.  Perhaps wireshark on the line in different scenarios might give you a further clue?

cheers, Aus

Link to comment
Share on other sites

5 hours ago, Ausman said:

Further to all the good help Flex and Kratmel are doing....

So your virtual PLC is communicating slightly differently to what the Unitronics stuff is doing.  Perhaps wireshark on the line in different scenarios might give you a further clue?

cheers, Aus

Maybe, since it worked on all the scenarios I tried, I do believe that it ignores something within the protocol itself.

 

I finally was able to solve the issue and use both PLCs as masters and slaves at the same time.
I am 99% sure that the problem was with the sockets, it seems that v570 does Modbus master properly only on with socket 0.

I have for testing purposes the following devices: Unitronics v570, Unitronics v700, Modbus pneumatic valve manifold, codesys control win V3 (virtual plc).

V570 as Modbus master on socket 0 port 502 TCP client protocol Modbus Network ID1 can communicate with the 3 slaves with no problem.

V570 as Modbus master on socket 3 port 502 TCP client protocol Modbus Network ID1 can communicate with the virtual PLC but not with the other two.

V700 as Modbus master on socket 0 port 502 TCP client protocol Modbus Network ID1 can communicate with the 3 slaves with no problem.

V700 as Modbus master on socket 3 port 502 TCP client protocol Modbus Network ID1 can communicate with the 3 slaves with no problem.

 

I m attaching the simplified versions of the program if anyone else wants to test my theory

570modbussimplified.vlp 570modbussimplifiedNOTWORKING.vlp 700modbussimplified.vlp 700modbussimplifiedREVERSEDSOCKETS.vlp

  • Thanks 1
Link to comment
Share on other sites

  • MVP 2021
16 hours ago, Fernando Castro said:

it seems that v570 does Modbus master properly only on with socket 0.

I have not found this to be true in my experience. The Vision PLCs do not care which socket is used as long as they are initialized properly and port numbers are not duplicated (which can easily happen if you only initialize the socket you are using and forget about another socket's default configuration).

Link to comment
Share on other sites

3 hours ago, Flex727 said:

I have not found this to be true in my experience. The Vision PLCs do not care which socket is used as long as they are initialized properly and port numbers are not duplicated (which can easily happen if you only initialize the socket you are using and forget about another socket's default configuration).

Now that you mention that, I was using port 502 on both sockets master and slave (sockets 3 and 0) however it did work fine🤔.
 
Just changed to port 20000 as Modbus TCP master, and 502 as Modbus TCP slave. the results were similar but now I am not able to use v700 as Modbus master on socket 3 too, independently of which port I set... I am confused I swear that it used to work on socket 3 v700 no problems at all, I'm "flushing it" with a new project to see.
 
Don't get me wrong, I already have the communications working as I wanted to just stick with the specifics sockets (0 for master 3 for slave) … but I am not satisfied without knowing what is going on I don't see why this should be socket specific if you can initialize the sockets ad use as you want.

 

Edit: @Flex727 you were right

Link to comment
Share on other sites

My original project for v700 works ok as modbus master on both sockets, but the simplified version doesn't.... I am not sure why 😵 

Maybe I am testing with too many devices and connections/disconnections and somehow one or the other device stays with the connection stuck to the previous test... at this point who knows

 

EDIT Never Mind ,I forgot to swap the socket on modbus config. V700 works on whatever socket as long  you configure it properly 🤣

EDIT 2: Same for v570.

 

 

 

 

Link to comment
Share on other sites

  • MVP 2021

I often run into the problem you're having. There are so many different items that must be configured, and they must all be configured exactly right, and it's very easy to get a bit confused as to what's what. Even after hundreds of projects using MODBUS TCP I still have to stop and go through it all very carefully before it works perfectly.

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...