Skip to content

Commit 9c19713

Browse files
authored
Merge pull request #241 from TomMuehlegger/master
Fix: Handle Min/Max values for REAL (Step7) accordingly
2 parents 1d24b2d + 5b9dbbd commit 9c19713

File tree

1 file changed

+4
-1
lines changed
  • LibNoDaveConnectionLibrary/PLCs/S7_xxx/MC7

1 file changed

+4
-1
lines changed

LibNoDaveConnectionLibrary/PLCs/S7_xxx/MC7/Helper.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ public static object StringValueToObject(string Value, S7DataRowType DataType)
107107
else if (DataType == S7DataRowType.DINT)
108108
return Int32.Parse(Value.Replace("L#", ""));
109109
else if (DataType == S7DataRowType.REAL)
110-
return float.Parse(Value.Replace('.',','));
110+
// Handle Max/Min REAL values accordingly (e.g., "-3.402823e+038" or "3.402823e+038")
111+
return float.TryParse(Value.Replace(".", ","), out float result)
112+
? result
113+
: Value.StartsWith("-") ? float.MinValue : float.MaxValue;
111114
else if (DataType == S7DataRowType.S5TIME)
112115
return Helper.GetTimespanFromS5TimeorTime(Value);
113116
else if (DataType == S7DataRowType.TIME)

0 commit comments

Comments
 (0)