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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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...
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
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...
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
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.
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
??? What are you using for Modbus communication? Is this something PI specific?
Did you see this?
http://forum.codesys.com/viewtopic.php?f=11&t=6049
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
Did you see the
Checkbox in the ModBus TCP Slave device, ModbusTCP tab / Data model?
Yes, but i don't really get it how it works All my tests fail.
/U
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...
ModbusMasterSlaveDemo.project [167.45 KiB]
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.
Thanks Strucc for the sample program.
I had the same problem.
I have expanded your idea and written a FB to handle synchronism.
FB_ModbusIO.zip [2.33 KiB]