You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 28, 2019. It is now read-only.
In the last days my colleague and I tested the communication between my C#-Application using this library and his C++-Application using lib60870-5 (http://libiec61850.com/libiec61850/). During our tests we got problems with receiving values of type M_ME_NA_1 (normalized value / IeNormalizedValue). Every time he sends me negative values this results in exceptions.
After some debugging I was able to figure out what's the matter. I think there is a bug in IeNormalizedValue (Line 22): Value = reader.ReadByte() | (reader.ReadByte() << 8);
The code handles two bytes (16 bit) and calculates an int (32 bit) where only 16 bits are used. The problem is that negative values in 16 bit representation are not handled correct this way - the result of negative 16 bit values is a number > 32767 in 32 bit (caused by the sign at the first bit).
I was able to fix it by replacing the line with the following code using BitConverter to create a short from the two bytes. This short has the correct value and sign an can be casted to int:
byte[] bytes = { reader.ReadByte(), reader.ReadByte()};
Value = BitConverter.ToInt16(bytes,0);
I tested it with QTester104 (https://sourceforge.net/projects/qtester104/) and lib60870-5 and it seems to work so I hope that this is correct. Please check it - hope that my code helps!
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
In the last days my colleague and I tested the communication between my C#-Application using this library and his C++-Application using lib60870-5 (http://libiec61850.com/libiec61850/). During our tests we got problems with receiving values of type M_ME_NA_1 (normalized value / IeNormalizedValue). Every time he sends me negative values this results in exceptions.
After some debugging I was able to figure out what's the matter. I think there is a bug in IeNormalizedValue (Line 22):
Value = reader.ReadByte() | (reader.ReadByte() << 8);
The code handles two bytes (16 bit) and calculates an int (32 bit) where only 16 bits are used. The problem is that negative values in 16 bit representation are not handled correct this way - the result of negative 16 bit values is a number > 32767 in 32 bit (caused by the sign at the first bit).
I was able to fix it by replacing the line with the following code using BitConverter to create a short from the two bytes. This short has the correct value and sign an can be casted to int:
I tested it with QTester104 (https://sourceforge.net/projects/qtester104/) and lib60870-5 and it seems to work so I hope that this is correct. Please check it - hope that my code helps!
The text was updated successfully, but these errors were encountered: