plcplcplcplc
Member
I am trying to display a variable within a cicode function onto a graphics page. This function queries a SQL database. I can get the value onto a diagnostic popup msg reading correctly but cannot seem to display the value on the graphics page, am I missing something obvious here?
Currently I am using a button with UP Command "ReadData()" Input to manually call the function however once I can display the data ok I will create an event.
The SQL column data type is a DECIMAL (5, 2) which I have defined as a REAL in my cidode function. I also tried as a STRING in cicode and was able to receive the same data value which was correct and matched the sql database row e.g "20.45" amps.
Cicode below:
REAL
FUNCTION
ReadData()
INT hSQL2;
REAL rDataQuery;
INT Status1;
hSQL2 = SQLConnect("DSN=SQL_DB; Uid=abc; pwd=def;");
IF hSQL2 <> -1 THEN
Message("Connection Success", "Connected to SQL_DB database", 64);
Status1 = SQLExec(hSQL2, "SELECT amps FROM sql_db_table1 ORDER BY id DESC LIMIT 1");
IF Status1 = 0 THEN
Message("SQL Execution Success", "Query executed successfully", 64);
WHILE SQLNext(hSQL2) = 0 DO
rDataQuery = SQLGetField(hSQL2, "amps");
Message("Data Retrieved", "Amps value: " + RealToStr(rDataQuery, 5, 2), 64);
RETURN rDataQuery;
Amps = rDataQuery;
END
SQLEnd(hSQL2);
ELSE
Message("connect Error",SQLErrMsg(),48);
END
SQLDisconnect(hSQL2);
ELSE
Message("connect Error",SQLErrMsg(),48);
END
END
In my graphics page I have tried the following expressions in the text properties display the wanted value:
When function was defined as a STRING:
1.APPEARANCE > DISPLAY VALUE > STRING > ReadData() - Displays a -1
2.APPEARANCE > DISPLAY VALUE > STRING > RealToStr(ReadData(), 5, 2) - Displays a -1
3.APPEARANCE > DISPLAY VALUE > STRING > ReadData(rDataQuery) Compile Error E2022 - Invalid number of arguments for function
When defined as a REAL:
1.APPEARANCE > DISPLAY VALUE > NUMERIC > ReadData() - Displays a -1
2.APPEARANCE > DISPLAY VALUE > NUMERIC > ReadData(rDataQuery) Compile Error E2022 - Invalid number of arguments for function
Also created a local variable tag in System Model called "Amps" using either REAL or STRING datatypes depending on the type i used in my cicode function and placed in the graphics builder expression value but it would display as blank.
Any help would be appreciated.
Currently I am using a button with UP Command "ReadData()" Input to manually call the function however once I can display the data ok I will create an event.
The SQL column data type is a DECIMAL (5, 2) which I have defined as a REAL in my cidode function. I also tried as a STRING in cicode and was able to receive the same data value which was correct and matched the sql database row e.g "20.45" amps.
Cicode below:
REAL
FUNCTION
ReadData()
INT hSQL2;
REAL rDataQuery;
INT Status1;
hSQL2 = SQLConnect("DSN=SQL_DB; Uid=abc; pwd=def;");
IF hSQL2 <> -1 THEN
Message("Connection Success", "Connected to SQL_DB database", 64);
Status1 = SQLExec(hSQL2, "SELECT amps FROM sql_db_table1 ORDER BY id DESC LIMIT 1");
IF Status1 = 0 THEN
Message("SQL Execution Success", "Query executed successfully", 64);
WHILE SQLNext(hSQL2) = 0 DO
rDataQuery = SQLGetField(hSQL2, "amps");
Message("Data Retrieved", "Amps value: " + RealToStr(rDataQuery, 5, 2), 64);
RETURN rDataQuery;
Amps = rDataQuery;
END
SQLEnd(hSQL2);
ELSE
Message("connect Error",SQLErrMsg(),48);
END
SQLDisconnect(hSQL2);
ELSE
Message("connect Error",SQLErrMsg(),48);
END
END
In my graphics page I have tried the following expressions in the text properties display the wanted value:
When function was defined as a STRING:
1.APPEARANCE > DISPLAY VALUE > STRING > ReadData() - Displays a -1
2.APPEARANCE > DISPLAY VALUE > STRING > RealToStr(ReadData(), 5, 2) - Displays a -1
3.APPEARANCE > DISPLAY VALUE > STRING > ReadData(rDataQuery) Compile Error E2022 - Invalid number of arguments for function
When defined as a REAL:
1.APPEARANCE > DISPLAY VALUE > NUMERIC > ReadData() - Displays a -1
2.APPEARANCE > DISPLAY VALUE > NUMERIC > ReadData(rDataQuery) Compile Error E2022 - Invalid number of arguments for function
Also created a local variable tag in System Model called "Amps" using either REAL or STRING datatypes depending on the type i used in my cicode function and placed in the graphics builder expression value but it would display as blank.
Any help would be appreciated.