Jump to content

Recommended Posts

  • MVP 2023

I've got a programming methodology question. We have a project where a single V570 is connected to all the I/O for the system and runs the process. The problem comes in where we have two additional V570's on a CANbus network using UniCAN that need to duplicate the screens and allow the user to change many parameters on any screen. I am broadcasting the data via timers from each screen to the others, but as you can image we are getting into a data race and the logic is starting to look like a big rat's nest trying to keep the data updated based on who entered what last.

I am doing this wrong. I can feel it. Can anyone suggest a structure that will bring order and serenity to a multiple-master system? How do you tokenize an n-order CANbus network?

Joe T.

Link to comment
Share on other sites

  • MVP 2014

I am currently working on an application with a main Unitronics PLC and a single slave Unitronics PLC. The slave is mainly an HMI slave. So this issue has been fresh in my mind, as it still is relevant even in the case of only two devices.

It sounds like you are transmitting the data cyclically, which would be necessary if you were using a strict master/slave protocol like Modbus. Even with two devices, this raises the question of who gets the data first, the master or the slave?

However with UniCAN, the programming can be more like a peer to peer architecture.

I would suggest an event-driven approach, at least in regard to the human input data. So you only transmit data to the all the PLCs if someone makes a change on one of the screens. This is similar to the way the EX-RC1 example program is written. There can still be a small chance of conflct if two people happen to try making changes to the same object at the same time on different screens. But, since UniCAN can be quite fast, the chances are small.

If you really want it bullet proof, I would probably go with an explicit "token passing" structure. That is, the user has to request control at a particular station before being able to change data. While the user has control at that station, all others are locked out of edit mode, but still receive updates of the data.

I hope this helps.

  • Upvote 1
Link to comment
Share on other sites

  • MVP 2023

Simon-

Thanks for the feedback. I posted at 2:45 in the morning and my frustration was just peaked out. If you have an Aussie slang term for this feeling I would be interested in knowing it.

I had already tried the event-driven approach by creating a local buffer and triggering a Send to the others when it changed, but this triggered Sends based on change of the "new" data from the receivers so I had to figure out how to prevent that. One of the problems is the CANbus "Message Received" block is kind of dumb - all it tells you is that you got a message from a particular node. There is no "message number" or anything else that allows a programmer to make a decision on what to do with the received data. You're totally on your own to come up with an encoding/decoding scheme. I added this "message number" to the front of my CANbus data block I'm sending and then called different Struct blocks based on the message number. The code is not very pretty and a layman will have a hard time figuring out what I'm doing. Plus it gets increasingly complex as you add more separate blocks of user data.

I also think there may be a bug in the Struct block if you use multiple instances of it operating on the same block of MI's separated only by a few nets. For testing, I have two V570's and a V350. When I changed a value on V570 #1, V570 #2 and V350 followed perfectly. When I changed the value on V570 #2, V570 #1 followed and V350 #3 somehow received 0s in the block and zeroed out the data. The transmit / receive code is identical in all three. I beat my head on this for two hours and couldn't figure it out. It seemed like the one of the Struct blocks was grabbing the MI's and not letting go. I was able to watch this happen online.

I'll try to strip down the programs and remove the customer's data so I can post them.

That's when I gave up and posted. I think you and I are on the same track with the token-passing idea, I've just never done it before. The trick is to communicate to the "locked out" units that they are receiving new data from the token holder and not to confuse that with a local edit. I'm going to do some research on this and I'll keep everybody posted - this problem will come up again. From time to time there are posts on the forum from users who want remote screens like this and I've never seen a solid answer on how to do it.

I'm looking to generate something that is small, adaptive to multiple blocks, and elegant. If anybody has some thoughts or examples I'm all ears.

Joe T.

Link to comment
Share on other sites

  • MVP 2014

Hi Joe,

I think the term "going birko" could describe your state of mind. I am unsure of the history of that term, but there is a brand of electric urns (protable water heater) called Birko, so imaging one of those with the thermostat stuck on, boling like cray and steam flying out.

Good point about the slaves receiving data and that then triggering an event to send the data back out. I guess you could interlock the send activity with a touchscreen bit, so it only sent if the changes was in conjunction with touchscreen activity.

As you say, it would be handy to have a "best practice" example of how to do this.

  • Upvote 1
Link to comment
Share on other sites

  • 4 weeks later...

Just a side note on using Unican broadcasts. I have been using the Unican broadcast in several project now and have been having problems with the integrity of the broadcast. For example in a 8 node network of V1210 & Ex-Rc1, each unit broadcasts a unique programmer assigned constant integer every 30 seconds. However quite frequently the data integer received in SI200 does not come from the CANbus id in SI201.

For example if the following CANbus IDs broadcast the integers as follow

ID Integer

2 200

3 300

4 400

5 500

At the receiver almost all of the time for ID 2 (Si201) we get integer (Si200) 200, however sometimes we will get ID 4 and integer 200, or ID 5 and integer200, or ID 3 and integer 500, or any combination of CANvus ID and integers.

Looks like Si200 and Si201 are not updating at the same time.

In the logic I am doing two consecutive stores, in the same net for Si200 and Si201, so it seems that logic would be fast enough.

We also have this issue in a smaller network of one V1210 and two Ex-Rc1.

Seems like a bug to me.......

I see you are using broadcasts, and if you have multiple stations issuing broadcasts, just wondering if you are experiencing this issue?

Thanks

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