Skip to content

Commit

Permalink
fixed double implementation in S7
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Jul 26, 2018
1 parent d7159aa commit 810d649
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public static byte[] encodeData(Object[] values) throws PlcProtocolException {
throw new PlcNotImplementedException("calender not yet implemented in s7");
} else if (valueType == Float.class) {
result = encodeFloat(values, length);
} else if (valueType == Double.class) {
result = encodeDouble(values, length);
} else if (valueType == String.class) {
result = encodeString(values, length);
} else {
Expand Down Expand Up @@ -89,6 +91,24 @@ public static byte[] encodeFloat(Object[] values, int length) {
return result;
}

public static byte[] encodeDouble(Object[] values, int length) {
byte[] result;
result = new byte[length * 8];
for (int i = 0; i < length; i++) {
double doubleValue = (double) values[i];
long longValue = Double.doubleToLongBits(doubleValue);
result[(i * 8)] = (byte) ((longValue & 0xFF000000_00000000L) >> 56);
result[(i * 8) + 1] = (byte) ((longValue & 0x00FF0000_00000000L) >> 48);
result[(i * 8) + 2] = (byte) ((longValue & 0x0000FF00_00000000L) >> 40);
result[(i * 8) + 3] = (byte) ((longValue & 0x000000FF_00000000L) >> 32);
result[(i * 8) + 4] = (byte) ((longValue & 0x00000000_FF000000L) >> 24);
result[(i * 8) + 5] = (byte) ((longValue & 0x00000000_00FF0000L) >> 16);
result[(i * 8) + 6] = (byte) ((longValue & 0x00000000_0000FF00L) >> 8);
result[(i * 8) + 7] = (byte) (longValue & 0x00000000_000000FFL);
}
return result;
}

public static byte[] encodeInteger(Object[] values, int length) {
byte[] result;
result = new byte[length * 4];
Expand Down

0 comments on commit 810d649

Please sign in to comment.