CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Sun Dec 16, 2018 6:42 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Thu Feb 19, 2015 10:05 am 
Offline

Joined: Mon Feb 17, 2014 12:05 pm
Posts: 26
Hi!

I don't quit get it how to use the PI as an modbus slave.

For example

I want the master to read/write the bit 40000.00 in the PI, but i want the PI to be able to change the 40000.00 also.

Lets say I want 40000.00 to toggle every time a usere pushes a button connected to the master, but at the same time I want the PI-runtime to toggle the 40000.00.
I have no problem toggling the 40000 in the master, but it can't read back the actuall status of 40000.00 so if the runtime toggles it, the master doesn't know that and all gets out of controll.

/U


Top
   
PostPosted: Thu Feb 19, 2015 11:50 am 
Offline

Joined: Mon Dec 27, 2010 2:35 pm
Posts: 71
It's not really a PI, nor Modbus specific problem, but a common issue with data synchronization.

Try to design your system according to the following rules:
- Every piece of data has one, and only one source (it does not matter if it's the master or the slave)
- The data source (physical input, analog, digital, or output of some calculations) is updated regularly
- Any number of consumers can receive, use that data

IF you need the data to be modified by any external source, then you have to program it around your data source: It will be using an external data source as a consumer, and decide - it really depends on the nature of the data you'd like to synchronize - when to update local data. In some cases, locking mechanisms has to be used, what is quite hard to do with modbus, you can only rely on timing.

Another model is a "token" based data synchronization: you pass a "token" around the data producers, and they can only update the common data, when they have the token. It can be time based, counter based, etc...


Top
   
PostPosted: Thu Feb 19, 2015 11:55 am 
Offline

Joined: Mon Feb 17, 2014 12:05 pm
Posts: 26
The problem isn't data sync, it's that I'm used to slaves that can both read and write to there own modbus registers, the PI only can read from 40000, it can't write to it.

So it can't be used both for input and output.

/U


Top
   
PostPosted: Thu Feb 19, 2015 2:35 pm 
Offline

Joined: Mon Dec 27, 2010 2:35 pm
Posts: 71
It should be possible with holding registers...
Just "map" it to a variable, that you can read and write. The variable will be updated, if it's updated by the master.
I didn't try with PI, but I think Modbus TCP and RTU functionality is common for all platforms.


Top
   
PostPosted: Thu Feb 19, 2015 2:39 pm 
Offline

Joined: Mon Feb 17, 2014 12:05 pm
Posts: 26
You only have input and outregister, no comboregister,

runtime can read from 40000 and write to 30000, and there is som function called input and output registers overlay, but I don't get it to work as I want and are used to.

/U


Top
   
PostPosted: Thu Feb 19, 2015 2:49 pm 
Offline

Joined: Mon Dec 27, 2010 2:35 pm
Posts: 71
??? What are you using for Modbus communication? Is this something PI specific?

Did you see this?
Image

http://forum.codesys.com/viewtopic.php?f=11&t=6049


Top
   
PostPosted: Thu Feb 19, 2015 2:55 pm 
Offline

Joined: Mon Feb 17, 2014 12:05 pm
Posts: 26
Yes i'm using the slave as your screendump, and there are only inputs AND output registers, no combo-register (eg 40000 to 49999 in "normal" modbus),
the runtime can't alter the variables mapped to modbus inputs.

/U


Top
   
PostPosted: Thu Feb 19, 2015 3:09 pm 
Offline

Joined: Mon Dec 27, 2010 2:35 pm
Posts: 71
Did you see the
"Holding and Input register data areas overlay"
Checkbox in the ModBus TCP Slave device, ModbusTCP tab / Data model?


Top
   
PostPosted: Thu Feb 19, 2015 3:10 pm 
Offline

Joined: Mon Feb 17, 2014 12:05 pm
Posts: 26
Yes, but i don't really get it how it works :( All my tests fail.

/U


Top
   
PostPosted: Thu Feb 19, 2015 3:59 pm 
Offline

Joined: Mon Dec 27, 2010 2:35 pm
Posts: 71
I get it now... :)

Yep, it's a typical synchronization issue.
I created a sample project (running on CodeSys Control WinV3), I hope it helps.
Monitor the GVL_MASTER, and GVL_SLAVE variable lists. You can overwrite slave data from the Master, by changing wToSlave...

Attachment:
ModbusMasterSlaveDemo.project


You do not have the required permissions to view the files attached to this post.


Top
   
PostPosted: Sun Feb 22, 2015 8:53 pm 
Offline

Joined: Mon Feb 08, 2010 9:22 am
Posts: 1
I have the same problem when IP is Modbus slave, the holding register values do not change whether in writing from the Modbus master or from the slave. I use the demo.
Best regards.


Top
   
PostPosted: Tue Oct 02, 2018 12:23 pm 
Offline

Joined: Tue Sep 25, 2018 7:32 pm
Posts: 8
Thanks Strucc for the sample program.
I had the same problem.

I have expanded your idea and written a FB to handle synchronism.


You do not have the required permissions to view the files attached to this post.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 12 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited