AVEVA Plant SCADA Forum
A support forum for AVEVA Plant SCADA (formerly Citect SCADA). Share new and exciting product information, connect, learn, and collaborate with the ecosystem of Plant SCADA Users. AVEVA Plant SCADA a reliable, flexible and high-performance Supervisory Control and Data Acquisition software solution for industrial process customers. This forum is to connect, share, learn and collaborate new and exciting product information. Feel free to join and share to your Ecosystem of Plant SCADA Users.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2024-02-24 02:08 PM
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.
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2024-04-22 07:05 PM
I believe the problem is that Cicode on a page is a blocking function (has to be non-blocking to work on a page). You need to decide where this Cicode will run (as in an event on Client process) or on the Report Server (which can act as a redundant capable event engine) or elsewhere.
Another option could also be to use Calculated Variables (see online help for more info on this) which was introduced in Citect SCADA 2016. This would allow you to only execute the function "ReadData()" when the tag is displayed (it is executed within the IO Server process not on the actual page). Hope this information helps. I would be interested to hear back with which approach you take.
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2024-04-22 07:05 PM
I believe the problem is that Cicode on a page is a blocking function (has to be non-blocking to work on a page). You need to decide where this Cicode will run (as in an event on Client process) or on the Report Server (which can act as a redundant capable event engine) or elsewhere.
Another option could also be to use Calculated Variables (see online help for more info on this) which was introduced in Citect SCADA 2016. This would allow you to only execute the function "ReadData()" when the tag is displayed (it is executed within the IO Server process not on the actual page). Hope this information helps. I would be interested to hear back with which approach you take.
Link copied. Please paste this link to share this article on your social media post.
Create your free account or log in to subscribe to the board - and gain access to more than 10,000+ support articles along with insights from experts and peers.