Hi all,
I am trying to use REAL_TO_DWORD in a codesys project, but when the data from the modbus slave is setup wrong (byte order), the PLC is stopping and say: FPU overflow.
How to handle this?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Real to dword tries to PUT the real value inside a dword value, meaning it is trying to get the same values on your two variables.
So, if the real value is outside the dword value range, this will produce an error.
Online help states :
If the operand value for a type conversion operator is outside of the value range of the target data type, then the result output depends on the processor type and is therefore undefined. This is the case, for example, when a negative operand value is converted from LREAL to the target data type UINT.
Information can be lost when converting from larger data types to smaller data types.
Back to your issue, as your cpu stop may not be configurable easily, I would try using a union datatype instead. Union will use the bits to read the value AS a dword or AS a real. This will prevent your cpu stopping, but you will need to change how you send your value with the master.
Hi all,
I am trying to use REAL_TO_DWORD in a codesys project, but when the data from the modbus slave is setup wrong (byte order), the PLC is stopping and say: FPU overflow.
How to handle this?
Real to dword tries to PUT the real value inside a dword value, meaning it is trying to get the same values on your two variables.
So, if the real value is outside the dword value range, this will produce an error.
Online help states :
Back to your issue, as your cpu stop may not be configurable easily, I would try using a union datatype instead. Union will use the bits to read the value AS a dword or AS a real. This will prevent your cpu stopping, but you will need to change how you send your value with the master.
You may prefer just checking the real value before converting it.
So you would check if your real is in between these two constants, and then convert it if true.
Edit: Added some better formating
Last edit: dFx 2021-02-01