How can i transfer REAL numbers for example the value "5.32" through Modbus RTU ?
If you want to send scaled integers, multiply the real by a scaling factor BEFORE yoiu use the real_to_word.
If you want to send IEEE floating point numbers as 2 * 16 bit words then from the codesys forums ...
It depends on what you want to send. If the receiver expects a floating point variable, then it still doesn't work.
A floating point variable is stored according to the IEEE 754 standard which you can transfer as 4 bytes, but not by the REAL_TO_WORD conversion.
What you need to send is the "real binairy value" of the REAL.
This can be done with a trick to add a "Union" Data Unit Type (DUT) to the application. A Union shares the memory for different variables:
Code: TYPE unionDwReal :
dwDword : DWORD;
rReal : REAL;
When you declare this in your application as variable you can write your real to the real variable of the union, but then send the DWORD with the SDO. This off course only works correctly if the receiver also expects to receive a floating point variable according to the IEEE 754 standard (which almost all do).
Code: PROGRAM PLC_PRG
uDwR : unionDwReal;
dwSDO : DWORD;
Code: uDwR.rReal := 23.1234;
dwSDO := uDwR.dwDword;
PS, another similar method is by using pointers. This would be the way to do it with V2.3.
Here is one very old, simple and effective technique:
1. Decide how many digits after decimal point you will need to transfer. In your case 2
2. Multiply real value -> 5.32 x 100 = 532
3. Use Real_To_Int -> you will receive 532 as integer
4. Transfer this integer by means of Modbus
5. On the other side of transfer, make same in oposite order - Int_To_Real, then divide by 100 (532/100=5.32)