Closed Mallowan closed 6 years ago
Hi @Mallowan,
Perhaps you have Optimize block access turned on for DB2? I recommend reading a single variable at a known address, but honestly it shouldn't matter much since we're just reading bytes. If the type in C# doesn't match the type in the PLC, you'll just get garbage data, but it doesn't really change the ability to read or write values.
Hi mycroes, I studied "Optimize Block Access" feature, like nobody else. ) That's not a culprit! I agree, not matching of data types causes a mess. But, at the moment, I have "0" during the reading of DB2.
@mycroes, you wrote: If the type in C# doesn't match the type in the PLC, you'll just get garbage data, but it doesn't really change the ability to read or write values.
Now, I don't agree.
I think something like a mismatch in types or so, completely halts reading of particular DB. I did some study on that (now I would say an issue). In other words, it seems I've found out where the library failed. For some reason the library doesn't like to read Integer itself or Integer in company with Reals. An usage of Int halts completely reading process, and there are not any exceptions there. Compare both screenshots (above). If I change in DB2, in third line, an Int to DInt - a reading will go.
class DB2
{
public double M_0 { get; set; }
public double M_1 { get; set; }
public int M_2 { get; set; }
public bool M_3 { get; set; }
public bool M_4 { get; set; }
public bool M_5 { get; set; }
public bool M_6 { get; set; }
public bool M_7 { get; set; }
public bool M_8 { get; set; }
public bool M_9 { get; set; }
public bool M_10 { get; set; }
}
Note, that both values are within Integer (16 bit) range (reffering to TIA docs).
Also, the library reads entire Byte only, or two Bytes and so on, it never reads a Byte + 1bit or 2 bits. It must be a number of whole Bytes always. Otherwise there will come an exception, as follows.
Mallowan
HI @Mallowan
Now, I don't agree.
I think something like a mismatch in types or so, completely halts reading of particular DB. I did some study on that (now I would say an issue). In other words, it seems I've found out where the library failed. For some reason the library doesn't like to read Integer itself or Integer in company with Reals. An usage of Int halts completely reading process, and there are not any exceptions there. Compare both screenshots (above). If I change in DB2, in third line, an Int to DInt - a reading will go
I'm guessing the issue is with offset calculation. Probably if you extend your datablock at the end, you can read just as well (with incorrect values though!). There have been other reports about issues with offset calculation, but I've never been given a reproducible example. This might actually do though, so I'll see if I can find some time to test this.
@mycroes, FYI, a concrete example of the issue.
here, DB2 is being read normally.
here, DB2 isn't being read at all. Just it doesn't exist for a project. It doesn't cause any exceptions, as well. As you can see I did nothing wrong. Just had swapped a DInt to Int. Tha's a normal way, because a value 223 is within Integer(16) range, reffering to TIA portal docs. Moreover, pay attention that DB2 always contains a whole number of Bytes.
P.S. did a check-up on 0.1.8; 0.1.9 versions.
Mallowan
Hi @Mallowan
Im my opnion your class should be changed:
instead of
public int M_2 { get; set; }
you should use
public Int16 M_2 { get; set; }
or
public short M_2 { get; set; }
Jürgen
Juergen, are you developer of mentioned library? Aren't it? I would say that pretty useful stuff you invented. I will try that. Hope it will help!
Yes, confirm that. It became readable. Just VStudio always offers a simplification of types... Juergen , give me some advice on whole Byte +1bit + 1bit reading.
Hi @Mallowan
No I'm not the developer of this library. Just a happy user.
You need to use the exact type of variable corresponding to the used type in the DB.
S7netplus just reads bytes from the plc and maps it later to to the used variables.
So if the types don't match, you'll get an different offset.
Jürgen
Hi @Mallowan No I'm not the developer of this library. Just a happy user. You need to use the exact type of variable corresponding to the used type in the DB. S7netplus just reads bytes from the plc and maps it later to to the used variables. So if the types don't match, you'll get an different offset.
Jürgen
Yes, you are right. I did check-up on your advice. By default VStudio offers an Int as Int(32) so that didn't match with Step7's Int that is to be 16 bit. So I had an issue.
Juergen , give me some advice on whole Byte +1bit ... + 1bit reading.
Mallowan
Yes, you are right. I did check-up on your advice. By default VStudio offers an Int as Int(32) so that didn't match with Step7's Int that is to be 16 bit. So I had an issue.
Not by default, by specification. I'm kinda pissed that again (#139) you're filing an issue and wasting my time because you don't know what you're using. You're also editing the comments here all the time, which makes it impossible for anyone to see if your code matches the PLC data (because I had actually seen the usage of int
in your DB2
class, which was in line with the datablock change to DINT).
I do however accept the fact that you can't verify what the internal calculations are, which makes it impossible for you to check if you're doing the right thing, so I'll try to make improvements in that area.
Juergen , give me some advice on whole Byte +1bit ... + 1bit reading.
Stop multi-purposing issues. I don't mind if you file a new issue on byte + bit reading (even if it's just a matter of getting advice rather than an actual problem in the S7NetPlus code itself), but keep issues separate.
@mycroes , I think you need to reread the title of my post more carefully.
thanks to Juergen, he realized my mistake on the first try.
@Mallowan
I think you need to reread the title of my post more carefully.
I'm not sure why you keep thinking for others. I have read your issue title, that doesn't change a thing about my comment. And with regards to reading titles, you are posting this in the issue tracker for S7NetPlus. I honestly think you are being disrespectful (by actions, and sometimes slightly by what you type because you don't consider the position of the person you're addressing) to this project. If you keep that up I might act on that.
Hello, It's getting to be ridiculous, however, I always get in trouble when I'm going to add next DB which I want to read. For example, I have DB1 that is being read excellently. I added DB2 (did everything in the same way). Tried to read. I've got a strong sense, as though being read DB2 is not existing at all. At the same time DB1 is being read normally.
DB1 DB2
Also, such features as Optimized Block Access and option Offset are irreconcilable in TIA Portal.