In Unity Pro XL, the following steps are required to read floating-point data when using the Read Var function block for Modbus communication. Read var reads the register of the remote device to get the floating-point value represented by an integer. If you have a block of conv real to int function, you can use it directly to convert integer values to floating-point numbers.
If there is no conv real to int, manually convert the integer to a floating-point number. For example, use the int to real function to convert a 32-bit integer to a 32-bit floating-point number. Make sure to adjust these steps to the specific PLC configuration and communication protocol, paying attention to factors such as byte order. Check out the Unity Pro XL documentation for more details.
When using the Read Var function block for modbus communication in Unity Pro XL, there are a few steps to convert the read int value to the value of the floating-point data type. Here are the general steps:
Read integer values:Use the read var function block to read the register of the remote device, which contains an integer representation of floating-point data. Make sure that the register address and other communication parameters are set correctly.
Convert to floating-point:Use the conversion feature provided by Unity Pro XL to convert the read integer value to a floating-point number. In general, one of the following methods can be used:
conv real to int function block:If you have a block of the Conv Real To Int function in Unity Pro XL, you can use it to convert integer values to floating-point numbers. Connect the integer value read by read var to the input of conv real to int, and then connect the output to where floating-point numbers are needed.
Manual Conversion:If you don't have a conv real to int function block, you may need to do the conversion manually. For example, a 16-bit or 32-bit integer that is read is interpreted as a floating-point number. This usually involves the floating-point representation of the IEEE 754 standard, which can be converted to a floating-point number using an appropriate algorithm.
Here's an example, let's say you have a floating-point number represented by a 16-bit integer:
var
intvalue: int;(Read integer value *).
realvalue: real;(Converted floating-point value *).
intvalue := read_var(……Use read var to read integer values *).
(* Convert using the conv real to int function block).
conv_real_to_int(
in := intvalue,
out := realvalue
Make sure to adjust these steps to your specific PLC configuration and Modbus communication protocol. In the Unity Pro XL manual and documentation, you can find more detailed information and examples.
If the Conv Real to Int function block is not provided in Unity Pro XL and you need to manually convert an integer to a floating-point number, you can use the rules of the IEEE 754 standard to do so. Here's a simplified example, let's say your PLC uses a 32-bit integer to represent floating-point numbers:
intvalue: dint;(32-bit integer *).
intvalue := read_var(……Use read var to read 32-bit integer values *).
(Manually convert integers to floating-point numbers).
realvalue := int_to_real(intvalue);
In this example, the int to real function is used to convert a 32-bit integer to a 32-bit floating-point number. Note that this is just a simplified example and may require more complex processing in real-world situations, depending on how the PLC is represented and the implementation of the IEEE 754 standard.
Consult the documentation and manuals for Unity Pro XL to learn more about the functions and features used. Depending on the situation, you may also want to consider factors such as the byte order of the data (big-endian or little-endian).