F_SwapReal

F_SwapReal 1:

The way in which a REAL number is represented in the memory of a bus controller (165) is different from the way a REAL number is represented in the memory of an Intel system (PC). In order to represent a bus controller's REAL number correctly in a PC, it is necessary for the high and low words of the REAL number to be swapped. Under the programming environment this is already done in online or simulation mode.  To be able to request the REAL data of a Bus Controller via the network (ADS protocol, ADSDLL, AdsOcx etc.) and represent them properly on an Intel PC, the REAL data have to be converted into the correct format. This can either be done in the bus controller or in the PC. The function F_SwapReal can be used to convert the REAL variables (e.g. variables to be read by a VB application or recorded with TwinCAT Scope View) into a suitable format on the PC side. The fVal parameter that is passed is not affected by the conversion. The function returns a new REAL number with a modified representation in memory.

FUNCTION F_SwapReal : REAL

VAR_INPUT

VAR_INPUT
    fVal    :REAL;
END_VAR

fVal: the REAL value to be converted.

 

Sample in ST:

PROGRAM MAIN
VAR
    Real_165        : REAL;
    Real_i386 AT%MB0: REAL;
END_VAR

 

(* ADSREAD(.... ADR(Real_165), SIZEOF(Real_165)... );
...
...
...
*)
Real_i386 := F_SwapReal( Real_165 );
Real_i368 := Real_i368 + 0.001;

 

In the sample, a 4-byte REAL variable in the bus controller is converted into the 4-byte REAL Intel format. The Real_i386 variable can, for instance, be correctly displayed on a VB form.

 

Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT v2.7.0 Build > 518

TwinCAT v2.8.0 Build > 735

BCxxxx (165)

Standard.Lb6, PlcSystemBC.Lb6, TcPlcUtilitiesBC.Lb6