Menu

Random missing decimal separator in REAL variables

2016-03-11
2016-03-11
  • Jesus Dominguez

    Jesus Dominguez - 2016-03-11

    I'm using Snap7 to read some variables from a Siemens PLC.
    Most of the REAL values are read fine, but randomly (1 in 1000), instead of getting, say, "23.4" I get "234". I'm still trying to figure out if the problem is somewhere else, but the code is pretty simple, and everything is pointing to the read function in Snap7.
    While I keep trying to find the culprit, I was wondering if anyone has had a similar problem, or if a problem like this sounds reasonable, or is definitely somewhere else.

    I'm really confused because as far as I understand, corrupt data wouldn't change the decimal separator in a float number (At least not in decimal, maybe in binary). But I don't know.

     
  • Davide Nardella

    Davide Nardella - 2016-03-11

    IMHO the problem is elsewhere.
    The S7 Protocol is heavy and a bit cumbersome but if a function returns 0 (result ok) you can feel comfortable that the transaction has been successfully completed ;)

    When you speak about 23.4 or 234 are you referring to real values ? i.e. that 234 is 234.0 ?
    The real value is 4bytes wide, are you reading it as 4 bytes or 1 doubleword (S7WLByte or S7WLDWord).
    The transaction is "claimed" by Siemens to be "telegram" consistent (but there are no public specifications about S7Protocol).

    Try to use S7WLReal or S7WLDWord.

     
  • Jesus Dominguez

    Jesus Dominguez - 2016-03-11

    Hello Davide,
    Thanks for the reply (and thanks for the great work!!).
    I'm measuring temperatures, so normally they are in the 20s.
    I'm doing double temperature1 = S7.GetRealAt(Buffer, 50);
    And saving them in a CSV. I know writing to CSV looks like the culprit, but I'm saving many more real variables and only the ones that come from Snap7 are behaving like this.
    So I'm expecting temperatures like 20.5ºC, and some times I get 205ºC.
    Honestly, I agree that it doesn't look like data corruption or anything, it's just that it's the first time that I see something like this with real numbers in C#.
    Anyways, thanks again! keep up the great work

     

Log in to post a comment.

MongoDB Logo MongoDB