I have used Sharp7 for a few years and everything was fine except for some problems on my side. However, I wasn't having a need to read strings till now so I went ahead and implement it in my helper classes. Doing that I encountered some strange problems which most probably aren't caused by the Sharp7, but I guess that someone here will be able to help.
Let me start with the first one...
On the PLC I have a DB that looks like:
If I read the DB using the Sharp7 I get:
All the variables are fine except for the second string. As you can see the first string has both of the header values set to 8 and is read fine, but the second string has a max. length set to 8 and the actual length to zero, which causes the GetStringAt function to return an empty string. As you can see the actual data is there if decoded it's "123" Please ignore the default value and current value in the DB screenshot from Simatic. I can read the first string just fine, no matter the value. Am I doing something wrong?
The second problem that I encountered is about the actual positions of the variables in the PLC memory. On the image you can see the test DB.
I have implemented the code that reads an awl file and calculates the locations for each variable. As far as I know if you put a bool variable in the data block there are always 2 bytes reserved for additional bool variables. You can see that position 12.0, however, not at the position 19.0 and then again at position 22.0.
The problem is solved. After thinking for a while I managed to solve a problem with a help from my colleagues.I was using Sharp7 to write into DB, then clone some of the variables to another DB and then read them, so that I can check if everything works fine. The problem was that I was cloning only the string data without the headers, because of that the actual length has a value, that was there before.
I also solved the problem with addresses. I didn't know that word, dword, dint... starts addresses are even, and that's not the case for byte and a bool. There are probably some exceptions but I don't use variables like time, date and so on.
Last edit: Primož Žufič 2019-06-17
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I have used Sharp7 for a few years and everything was fine except for some problems on my side. However, I wasn't having a need to read strings till now so I went ahead and implement it in my helper classes. Doing that I encountered some strange problems which most probably aren't caused by the Sharp7, but I guess that someone here will be able to help.
Let me start with the first one...
On the PLC I have a DB that looks like:

If I read the DB using the Sharp7 I get:

All the variables are fine except for the second string. As you can see the first string has both of the header values set to 8 and is read fine, but the second string has a max. length set to 8 and the actual length to zero, which causes the GetStringAt function to return an empty string. As you can see the actual data is there if decoded it's "123" Please ignore the default value and current value in the DB screenshot from Simatic. I can read the first string just fine, no matter the value. Am I doing something wrong?
The second problem that I encountered is about the actual positions of the variables in the PLC memory. On the image you can see the test DB.

I have implemented the code that reads an awl file and calculates the locations for each variable. As far as I know if you put a bool variable in the data block there are always 2 bytes reserved for additional bool variables. You can see that position 12.0, however, not at the position 19.0 and then again at position 22.0.
Thank you very much in advance.
Primož
Last edit: Primož Žufič 2019-06-17
The problem is solved. After thinking for a while I managed to solve a problem with a help from my colleagues.I was using Sharp7 to write into DB, then clone some of the variables to another DB and then read them, so that I can check if everything works fine. The problem was that I was cloning only the string data without the headers, because of that the actual length has a value, that was there before.
I also solved the problem with addresses. I didn't know that word, dword, dint... starts addresses are even, and that's not the case for byte and a bool. There are probably some exceptions but I don't use variables like time, date and so on.
Last edit: Primož Žufič 2019-06-17