Open dhullett08 opened 3 years ago
If you have the ability to modify the PLC DataBlock, I would suggest defining all your bools at the top/front.
The minimum size for any is PLC element/tag is 2 bytes, which you can see by the 'Offset' value of the real that is immediately following the first bool. Therefore, when you define bools separated in this way, you are not reading/writing a single BIT, you are actually writing 2 bytes (16-bits), hence why the Class Size calculates a bool as 0.125 of the entire property size.
Are you using ReadClass/WriteClass or are you performing ReadBytes/WriteBytes?
ReadClass WriteClass Is what I'm using, but I hit another issue with not being able to read a Date And Time type with the ReadClass method. ReadMultipleVars works fine for this but I may just go the ReadBytes and parse the bytes into a class myself for now.
Actually, if you want to check-out my branch, I have just completed the Class type modifications to support variable length strings and DateTime. I have verified on S71500 & S71200 with going 3 levels of class nesting deep. It is working quite well.
So I have the scenario where I have an array of user defined types in a datablock and I need to read and write them for managing recipes. The first member of this plc type is a bool followed Reals then another bool lower in the structure. Since the GetClassSize method only adds 0.125 to the numBytes variable, I was getting the wrong size for my class. I worked around thyis by making the bool properties in my class Int16 to get 2 bytes per bool. I'm not sure if this is due to how the PLC is aligning bytes to even numbers even on Bool's or what? Maybe this should be configurable via an attribute on the Bool property?