Is it possible to write a number of bits (up to 3) simultaneously to the PLC? I want to avoid using "read-modify-write" techniques and make the write as "atomic" as possible.
Can this be done using daveWriteBits() or do I have to use multiple write "items" within the same PDU?
Regards,
David
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
no, daveReadBits and daveWriteBits only accept a length of 1 (bit).
Yes, you could write multiple items with one PDU.
Why is there a length parameter to these functions? Because there is a field in the messages that is a bit count when reading/writing bytes. This field is currently always 1 when dealing with bits. But if Siemens would choose to support multiple bits here (with new CPUs or firmware), the number will most likely go there and libnodave will support unchanged and from the beginning. If Siemens won´t ask them what the field is for :-(
From my answer to another posting:
"Another thing is writing bits. If neighboured bits are used in the PLC program in write mode (i.e. there state is written by R, S or = operators) then daveWriteBits is the only way to change them
without affecting adjacent bits.
However, if you can modify the PLC program, and if you have a lot of bits to set, instead of writing to M6.5 and M45.3 using daveWriteBits, consider writing these bits to an unused byte, e.g. MB127 and then do
A M127.0
= M6.5
A M127.1
= M45.3
within the PLC program. This would allow to determine the state of 8*<max_byte_length> bits with a single with a single call to daveWriteBytes, where max_byte_length is e.g. 218 for 300/400 family and MPI-adapter. Other methods of transport may have higher limits."
Thomas
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
Is it possible to write a number of bits (up to 3) simultaneously to the PLC? I want to avoid using "read-modify-write" techniques and make the write as "atomic" as possible.
Can this be done using daveWriteBits() or do I have to use multiple write "items" within the same PDU?
Regards,
David
no, daveReadBits and daveWriteBits only accept a length of 1 (bit).
Yes, you could write multiple items with one PDU.
Why is there a length parameter to these functions? Because there is a field in the messages that is a bit count when reading/writing bytes. This field is currently always 1 when dealing with bits. But if Siemens would choose to support multiple bits here (with new CPUs or firmware), the number will most likely go there and libnodave will support unchanged and from the beginning. If Siemens won´t ask them what the field is for :-(
From my answer to another posting:
"Another thing is writing bits. If neighboured bits are used in the PLC program in write mode (i.e. there state is written by R, S or = operators) then daveWriteBits is the only way to change them
without affecting adjacent bits.
However, if you can modify the PLC program, and if you have a lot of bits to set, instead of writing to M6.5 and M45.3 using daveWriteBits, consider writing these bits to an unused byte, e.g. MB127 and then do
A M127.0
= M6.5
A M127.1
= M45.3
within the PLC program. This would allow to determine the state of 8*<max_byte_length> bits with a single with a single call to daveWriteBytes, where max_byte_length is e.g. 218 for 300/400 family and MPI-adapter. Other methods of transport may have higher limits."
Thomas