Looking to display a variable from a cicode function on a graphics page? This function retrieves data from a SQL database. While the variable shows correctly on a diagnostic message, it's not appearing on the graphics page. Are you overlooking something obvious? Currently, I'm using a button with the UP Command "ReadData()" Input to manually trigger the function. Once I can successfully display the data, I'll set up an event for it. The data in the SQL column is of type DECIMAL (5, 2), defined as a REAL in the cicode function. I also tried defining it as a STRING in cicode and received the same correct data matching the SQL database row (e.g., "20.45" Amps). Here's the cicode snippet: ``` 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 WHILE SQLEnd(hSQL2); ELSE Message("Connect Error", SQLErrMsg(), 48); END IF SQLDisconnect(hSQL2); ELSE Message("Connect Error", SQLErrMsg(), 48); END IF END ``` In attempting to display the value on the graphics page, I've tried different expressions in the text properties: When the function was defined as a STRING: 1. APPEARANCE > DISPLAY VALUE > STRING > ReadData() - Displays: -1 2. APPEARANCE > DISPLAY VALUE > STRING > RealToStr(ReadData(), 5, 2) - Displays: -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: -1 2. APPEARANCE > DISPLAY VALUE > NUMERIC > ReadData(rDataQuery) - Compile Error E2022 - Invalid number of arguments for function I also created a local variable tag in the System Model named "Amps" using either REAL or STRING datatypes based on what was used in the cicode function. However, when placed in the graphics builder expression value, it displays as blank. Any assistance would be greatly appreciated.
To optimize your system's performance, set up an OPC device in memory mode (even if you won't be utilizing OPC). Incorporate your variable with the new device and integrate it into your graphics and Cicode. Utilizing the OPC driver allows for the address to match the tag name, making it more user-friendly than a generic device. Keep in mind that when using multi-process mode, local variables are unique to each process. Avoid using local variables for display purposes to enhance efficiency.
LegacyLee, it is important to note which OPC driver is compatible with your device. I attempted to use the OPC Foundation DA Client driver, which was installed at the time, but unfortunately, it did not work. Instead, I encountered the #COM error on my graphic display.
plcplcplcplc inquired about the importance of selecting the right OPC driver for their device. Despite using the OPC Foundation DA Client initially, they encountered issues with their graphic display showing #COM. It is recommended to opt for the generic OPC driver for the device while ensuring it is in memory mode for optimal performance.
Hey, let's approach this step by step. Firstly, it's important to note that a function call in the field "Display value" won't execute the operable functions like `ReadData()`. The -1 that you're getting is probably an error code for a non-operational function in that property field. Secondly, the local variable tag "Amps" won't return a value in the Graphic Builder since it's locally defined in the `ReadData` function and its scope is limited to this function only, hence it won't hold a value outside it. I suggest declaring "Amps" as a Global Variable outside the function to make it available in your whole project. Then you can assign the Global Variable tag in the Graphic Builder to display your value. To ensure that the Global Variable is updated when the SQL data changes, you might set up a periodic event to keep invoking your `ReadData` function to refresh the variable.
It seems like the function ReadData() isn't returning any value when it's called from your graphics page, hence the '-1'. The function is dealing fine with the SQL commands and running as expected when executed but after your WHILE loop you haven't defined a return in case SQLEnd() gets called, that's probably why nothing is shown and '-1' is returned. Try defining a return value at the end of your function. Also, please note that the 'Amps = rDataQuery;' statement won't have any effect outside the function scope, so it won't change your local variable 'Amps'. To modify the 'Amps' tag, you might want to use TagWrite. Hope this helps!
It sounds like you’re on the right track, but the issue could be related to how the variable is scoped or updated once you retrieve it from SQL. Since you're using the `ReadData()` function to get the value, make sure that the variable `Amps` is properly declared and updated in a way that the graphics page can read it in real-time. Instead of just returning `rDataQuery`, also set the `Amps` variable directly and make sure it's updated in a way that your graphics page refreshes to display the new value. You might want to ensure that the correct data binding is established in the graphics properties, so it picks up the value from `Amps`. Lastly, test to see if adding a refresh command to your graphics element after the function execution helps reflect the updated value.
It sounds like you’re on the right track with your code, but a couple of things might be going awry with how the data is being integrated into your graphics page. First, ensure that the variable "Amps" is correctly defined as a global or system variable that can be accessed outside of your function. If it’s scoped locally within `ReadData()`, it won't carry over to the graphics page. Additionally, instead of trying to call `ReadData()` directly in the display properties, consider assigning the retrieved value to your global variable "Amps" and then referencing that variable on your graphics page. This separation can help eliminate the errors and ensure that the UI updates correctly with the latest data. Lastly, after updating the variable, remember to refresh the graphics page or trigger a repaint to see the change reflected. Happy coding!
✅ Work Order Management
✅ Asset Tracking
✅ Preventive Maintenance
✅ Inspection Report
We have received your information. We will share Schedule Demo details on your Mail Id.
Answer: - Ensure that you are setting up the display value correctly in the graphics page properties. Check if the function return type and data type match the expected format for display.
Answer: - You can use expressions in the graphics builder properties to show the data, making sure the function call and data type conversion are handled correctly.
Answer: - Common issues include incorrect data type handling, mismatched function call parameters in the graphics page properties, and errors in data retrieval and conversion.
Answer: - The value "-1" typically indicates a possible error or issue in data retrieval or display setup. Double-check the function call, data conversion, and graphics page configuration for any errors.
Answer: - Ensure consistency in data types between the SQL database column
Join hundreds of satisfied customers who have transformed their maintenance processes.
Sign up today and start optimizing your workflow.