Jump to content

Recommended Posts

Hello, all first let me start off by saying I suck at modbus comms with unitronics and have always been a little intimidated by them and would like to put an end to that. With that out of the way what I am trying to do is communicate with three 570's over modbus tcp ip. My setup would be a master and 3 stand alone slaves. These slaves are in different locations so a central master that can monitor start/stop and change a few set points on each is the goal.

I have read about all I can and looked at the help files/examples over the last few days. Thanks to Flex and Joe T. 's previous posts ad nauseam I am going to utilize 3 of the 4 sockets and configure for Modbus IP that matches the slaves. Of course for Joe I will utilize the available port for programming. In my mind my tactic was to get 1 machine talking and then just copy it 3 times and change port settings and locations where its writing. How hard is that right?? I am starting from the beginning trying to talk to one PLC and working my way but am really struggling. Right now I am trying to get it set up to where I can set a bit high and continuously cycle through reading and writing until i stop it. (Which is the next step past having to press a button to read or write like in the example file) . I have attached my code and a screenshot of my slave settings. Am I on the right track or not even close?

 

 

Capture.PNG

Share this post


Link to post
Share on other sites

If you would add comments to the rungs telling us what you're trying to do it would help immensely. Your code doesn't really match that well with your post and there is no way to tell if what you're doing is right if I don't know what you're trying to do.

A few small items:

1) You do not need a ladder rung to set SB 168. Just the Power-Up as Set is sufficient (which you have done).

2) Try to avoid using Port 502 for this (just as a convention) as that is normally used for communicating with SCADA and other Ethernet connected devices. To help with identification, use Port 20261 for Slave 1, 20262 for Slave 2, etc. (just a suggestion, the PLC doesn't care what port numbers you use).

3) You don't really need to perform reads and writes separately since you have the handy Unitronics function for R/W.

4) If you have separate sockets for each slave there is no need to disconnect the socket, ever.

5) What is Socket 3 being used for?

6) Name your MODBUS_IP Configs to match the slave it will be used for.

Share this post


Link to post
Share on other sites

I am really having a hard time with this and I don't know why.

I cleaned up some things you mentioned and came up with this basic skeleton. I am still having trouble getting it to cycle through once I start the sequence. Is this appropriately sequenced? Do you see any issues with it?

 

Forgot to add this..but socket 3 is just for programming the screen so I don't have to program over serial..

 

 

Share this post


Link to post
Share on other sites

1) When commenting, use full sentences.

2) Use the port numbers I suggested, Leave Socket 1 as 20256 for PC-PLC comms.

3) You cannot initialize more than one socket to the same port number.

4) Don't try to initiate a MODBUS command immediately on the heels of the previous one. Give it a little delay (maybe 20-50ms)

You seem to be confusing local ports and remote ports. For simplicity, and to avoid confusion, I always use the same port number for master and slave, that way it's impossible to confuse them. Same port number for master and slave means the following:

Master PLC: S0=20261, S2=20262, S3=20263

Slave 1 PLC: S2=20261

Slave 2 PLC: S2=20262

Slave 3 PLC: S2=20263

Share this post


Link to post
Share on other sites

I apologize for not answering in complete sentences.

I corrected the issues as you suggested and I think I have all my ports/setup correct. With that being said I made a few edits to the sequence but I'm not getting what I need out of it. I'm going to have to revisit this tomorrow but here is what I have. I also attached a screenshot of the 3rd slave setup just to be sure it's correct.

 

 

Capture.PNG

 

Share this post


Link to post
Share on other sites

Right before I left I went online and observed the comms, my total sessions and acknowledgements weren't incrementing correctly on all 3 R/W Mixed FB's. I left assuming I still had some work to do. Does it appear as if it would work as expected? 

Share this post


Link to post
Share on other sites
12 hours ago, dhuggins88 said:

my total sessions and acknowledgements weren't incrementing correctly on all 3 R/W Mixed FB's

What does this mean?

12 hours ago, dhuggins88 said:

Does it appear as if it would work as expected?

I didn't see any glaring problems, but the issue with comms is that every single detail must be exactly right in order for everything to work. It requires going through every entry of every FB, loading into the PLCs, and observing operation - something I didn't have time to do.

Share this post


Link to post
Share on other sites
33 minutes ago, Flex727 said:

What does this mean?

I was just saying my total sessions weren't incrementing the same as my acknowledgements.

I did see where I had one socket connected contact assigned wrong and fixed that.

However, the problem I am seeing is none of the sockets are staying connected. I am also getting status messages of 4 then 6 on all the Modbus Read/Write FB's

4 is "Master Timed Out"

6 is "Data synced incorrectly"

I went in to all the Socket Parameters on the slaves and everyone of them show socket 0 and port 20000 which is not even close to being correct. I think I need to download a blank program in all screens and start with a clean slate to see what I come up with.

 

Share this post


Link to post
Share on other sites
21 minutes ago, dhuggins88 said:

I went in to all the Socket Parameters on the slaves and everyone of them show socket 0 and port 20000 which is not even close to being correct.

What does "I went in to all the Socket Parameters" mean?

In my post above I was suggesting you use Socket 2 in the slaves and initialize to 20261 - 20263. It doesn't matter which socket you use as long as the port number is correct. Also make sure they're all initialized to TCP Slave. The default for Socket 0 is UDP.

My other suggestion is to limit your code to a single slave and get that working properly before trying to tackle communicating with 3 slaves simultaneously.

Share this post


Link to post
Share on other sites
On 8/9/2019 at 8:55 AM, Flex727 said:

My other suggestion is to limit your code to a single slave and get that working properly before trying to tackle communicating with 3 slaves simultaneously.

+1 to that

If you want to upload your program we can have a better look at it.

Joe T.

Share this post


Link to post
Share on other sites
On 8/8/2019 at 5:21 PM, dhuggins88 said:

I apologize for not answering in complete sentences.

I just caught this. Sorry, I was referring to your rung comments in the PLC program.

Have you had any luck in getting a single slave to communicate?

Share this post


Link to post
Share on other sites
On 8/10/2019 at 10:06 PM, Joe Tauser said:

+1 to that

If you want to upload your program we can have a better look at it.

Joe T.

 

16 hours ago, Flex727 said:

I just caught this. Sorry, I was referring to your rung comments in the PLC program.

Have you had any luck in getting a single slave to communicate?

Guys thank you for the responses. I took advice and opted to just attack 1 slave and got the other mess out of the way.

I had to take a step back and think about each process and what was exactly going on. It's actually pretty straight forward now that I see it.

I have attached my code and it works great. I had a little bit of issue getting it to establish a connection after a power cycle but I think I have it resolved. Going to use SB3 to constantly try to connect no matter what. Do ya'll see a problem( or future problems) with how I did all of this?

 

Master1.vlp Slave1.vlp

Share this post


Link to post
Share on other sites

-You don't need anything in the bottom part of the MODBUS Configuration in the slave.

-You really don't need anything gating your SCAN_EX FB in the Slave. Just hang it directly on the left rail.

-Place your MB 0 (Ready to connect) after you MODBUS Configuration, not before. You're NOT ready to connect until you've configured your MODBUS communications. It doesn't really matter since the config does occur before MB 0 gets used, but it's the principle of the thing.

-Use a Direct Contact of SB 13 instead of a Positive Transition of SB 3.

-You don't really need the delay timer TD 0.

None of these things would stop your program from working, but I'm trying to help you with best programming practices.

58 minutes ago, dhuggins88 said:

It's actually pretty straight forward now that I see it.

MODBUS is simple and straightforward. It's also very universal. I use it whenever possible. The only thing you have to watch for is getting all the details right. Once you've done that it's smooth sailing.

Feel free to ask about any of these suggestions if you're curious.

Share this post


Link to post
Share on other sites

Ok I cleaned up what you said then downloaded and all is good. Now that brings me to the next issue. (which I'm sure you saw where this was headed with the machine start stop and the integers) I cannot figure this one out. When I try to write to the slave I immediately get overwritten which is obvious from the way it's coded. However, I did figure out a way to successfully start and stop it from the master with a rudimentary time off delay but there has to be a better way...but it works. The writing from the master to the integer on the slave  is the one I'm stumped on.

I did get it the integer written from the master to the slave to work somewhat by using sb16 (screen touched). Basically stop the reading and write based on sb16. There has got to be a better way for this one as well.

 I figure I can probably store MI 20 from the master somewhere else in the slave compare the 2 then store the changed value to MI20 (set point.)

I have found this thread which is exactly what I'm trying to do.

http://forum.unitronics.com/topic/3849-v570-2-modbus-ports/?tab=comments#comment-14018

Capture.PNG

Capture1.PNG

Share this post


Link to post
Share on other sites

The top picture in the above image is in the master. Bottom is slave.

I'm writing MB12 to the slave and leaving it longer than the scan to give it time to update. Then after a second resetting it. My touch property is linked to MB10 in the master and the link is MB 11.

Below are my links in the master.

Capture3.PNG

Share this post


Link to post
Share on other sites

I haven't had time to review your code yet, but I'll make a general statement. Typically there isn't an easy or elegant way to have a master control in two different places. In any system there can only be one master if you want straightforward code, at least in my experience. If you need two different masters controlling the same thing you generally have to think it through very carefully and the algorithm will have to be tailored to the exact situation. You have to deal with communication timing and register overwrite. It can easily become a mess, especially if you don't fully understand the underlying mechanics.

If someone smarter or more experienced than me comes along with elegance, I am definitely interested in learning along with you.

Share this post


Link to post
Share on other sites

For now I have accomplished what I need and I greatly appreciate your help. I know I was going all over the place but I was just trying to show you guys I was trying on my end not just try and have you all do it for me. Thanks for your patience!

I hope Joe T or Aus comes by and chimes in.

Share this post


Link to post
Share on other sites
6 minutes ago, Flex727 said:

Me too. Their input is the best on this forum.

Yours ain't too shabby either, Flex! I have noticed that you like to have more of a bread crumb approach..but all you gotta do is follow em!

Share this post


Link to post
Share on other sites
48 minutes ago, dhuggins88 said:

Yours ain't too shabby either, Flex! I have noticed that you like to have more of a bread crumb approach..but all you gotta do is follow em!

You're too kind. My approach, as is most of the other experienced members on this forum, is not just to answer questions, but to teach. More education helps the user and anyone else browsing these boards. I could have written your program for you in about 2 minutes flat, but you would not have benefited as much. We all learn best while doing, not watching.

Share this post


Link to post
Share on other sites
42 minutes ago, Joe Tauser said:

I need to light a smoke and take a look.

I've been meaning to ask you, Joe. Do you have a preferred cigar brand?

Share this post


Link to post
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...