Citect Aveva Plant SCADA - Display a variable from cicode on graphics page

plcplcplcplc

Member
Join Date
Jun 2023
Location
AUSTRALIA
Posts
5
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.
 
Create an OPC device, keep it memory mode(You won't actually be using any OPC at al)l. Add your variable using the new device, use it in the graphic and your Cicode. With the OPC driver, the address can be the same as the tag name...more convenient than a generic device. If you're using multi-process mode local variables are specific to the process. Don't use local variables for display.
 
Thanks LegacyLee, does it matter what OPC driver is used for the device, I tried OPC Foundation DA Client as that is the driver I had installed at the time but didn't seem to work, just got #COM on my graphic display.
 
Thanks LegacyLee, does it matter what OPC driver is used for the device, I tried OPC Foundation DA Client as that is the driver I had installed at the time but didn't seem to work, just got #COM on my graphic display.
Just use the generic OPC for the device but leave it in memory mode.
 

Similar Topics

We are trying to set up a newer generation Omron PLC (NX/NS Series) with Citect / Aveva Plant SCADA using the Ethernet/IP CIP Protocol to read...
Replies
2
Views
361
Hi All, I aim to use Aveva Plant SCADA 2020 to read and write data from/to Omron CJ2M CPU35 PLC using OMFINS protocol. However I have Bad Data...
Replies
1
Views
728
Some time back Citect users were discussing how bad the Aveva website is to navigate compared to the old Schneider one. if i remember correctly...
Replies
4
Views
2,335
Hello, i've been at this for months now, i tried creating accounts on the aveva website but it seems to never approve my accounts or at least when...
Replies
0
Views
28
Hello, I have a running project on Citect v5.42 and simatic net v6.4 I have created a new spare PC and loaded all software like Citect, station...
Replies
0
Views
70
Back
Top Bottom