Bit Addressing using the S7 MPI Driver
When trying to read specific bits within an S7-400 PLC, I am receiving incorrect data. Also, when writing to these bits, the values end up in the wrong bit locations.
While the driver allows you to read words and access the bits as if the data were in word format, the S7-300 and S7-400 addressing is based on bytes instead of words. This can be confusing because the MW0 and MW1 are 8 bits apart, and if you format these as a words, the last 8 bits of MW0 are the first 8 bits of MW1. To avoid this confusion, you can use even or odd addresses to prevent overlap when formatting the data as a word.
To access Data Block 2 as boolean at byte offset 20 and bit 7 declare an address as follows:
To access Data Block 2 as boolean at byte offset 20 and bit 7 declare an address as follows:
DB2.DBX20.7