Closed JaxMcCleary closed 1 year ago
Can you check what happens if you read the DB until the first part in a non-nested way?
bool
byte
dword
string[20]
Does the string contain anything useful?
If that still leads to no useful string, as a next debug step, you could define the following class:
bool
byte
dword
byte[22]
And check what is in the first 2 bytes of the supposed string. My knowledge of S7 types is a bit rusty, but I think the first byte is supposed to be the capacity (should be 20), and the second byte is the runtime size of the string content (0 to 20).
What often happens is that PLC developers just initialize strings with something that just memsets everything to 0, creating a invalid string where the capacity does not match what it is supposed to be. I am not sure what S7Plus exactly does in that case, but it might just give you an empty string.
Sorry for the delayed answer and thank you for your input. Apparently there are some issues with the fact that the database is marked as "S7_Optimized_Access" flase. In the past days I've learned that if it is not optimized you can not read the variables externally by name. You need to read the variables with the offset and length. So I assume that's why I have some trouble with the function ReadClass and WriteClass. I assume the function takes the properties names and try to access the s7 variables with a combination of class name and property name.
The documentation for requiring unoptimized access is quite a bit hidden at https://github.com/S7NetPlus/s7netplus/wiki/S7-1200-1500-Notes#s7-12001500-notes
S7NetPlus can only work with unoptimized data blocks, as far as I know.
Yes, only non-optimized blocks can be used. When using ReadClass
or WriteClass
the fields or properties are read or written in order of declaration. There's no magic happening with member names, just concatenation of all the members to one byte array.
I'm in the midst of releasing 0.16.0, that will also support the string attribute on classes.
Hello,
I am pretty new to this sps subject. I used your library to read a database that contains 1 lifebit on the top level as well as 8 nested structures (4 for reading and 4 for writing). (Partial image of the database definition from the sps developer) The idea was to create a class with nested classes so i could use ReadClassAsync and WriteClassAsync. I am testing against snap7 right now and everything works except strings in the class.
This are the nested classes:
I wanted to use properties only but the attribute S7String is only valid for Fields so I had to change from property to fields for strings. The test was fairly easy:
When i read the written test data everything is correct except the strings. They are empty. I don't get any runtime exception while writing the database.
I am currently not sure what causes this issue.