Maria Abdullah
Maria Abdullah

Reputation: 55

How to convert Data types of array in Codesys

I am receiving data into an array from the energy meters which is of REAL datatype. My array: ARRAY[0..49] OF Real; I want to convert this data into string data type like i want all the values enclosed in commas "" separately.

Waiting for your kind responce.

Upvotes: 0

Views: 2429

Answers (1)

Filippo Boido
Filippo Boido

Reputation: 1206

(*Declaration part*)

aMyStringArray  : ARRAY[0..49] OF STRING;
aMyRealArray    : ARRAY[0..49] OF REAL;
i               : INT;
sMyLongString   : STRING(50*255);

(*Implementation part*)

sMyLongString := '';
FOR i:=0 TO 49 DO
    aMyStringArray[i] := REAL_TO_STRING(aMyRealArray[i]);
    sMyLongString := CONCAT(sMyLongString,'"');
    sMyLongString := CONCAT(sMyLongString,aMyStringArray[i]);
    sMyLongString := CONCAT(sMyLongString,'"');
    sMyLongString := CONCAT(sMyLongString,',');
END_FOR

Upvotes: 1

Related Questions