I am creating a logging table that will show real time data for selected values from a table. I have a 2 State Toggle button that is used as a trigger to start the data logging. The data does not need to be stored to review as historical data so the concept is that I give the engineer a button that will call a query to clear the data from the table.
Question:
How do I associate a simple query statement with the action of a button?
Right click the button and click “Configure Actions”. Under Actions select “Action Performed”, meaning the button was pressed. Enter your script under the “Script Editor” tab. Something like this:
fpmi.db.runUpdateQuery("DELETE FROM my_table")
I didn’t understand much of your first paragraph. To deal with “realtime” data, I would suggest always logging the data in FactorySQL, but selecting “Delete values older than…”. This automatically purges old records. Then you can use an Easy Chart or Table in FactoryPMI to display the data. I don’t think you should need to purge your data from a button press.
“old data” is a relative term. The table I am creating in PMI is for an engineer who wants to select 10 parameters from an available 100 and literally watch the values on the screen as the machine cycles. I have given him the option of exporting the info to Excel if he chooses. Most of the time he will see what he needs to see within the first few minutes and then move on. He may do this numerous times within the same day. Because of this last point, I need to make sure that the next time he goes to view his data, all of the older data is purged from the table; or at least, not visible for the new selected group. I do have to leave 1 row of data so the table does not error out.
fpmi.db.runUpdateQuery
(“DELETE
FROM sv3_machine_data
WHERE sv3_machine_data_ndx > 30”)
I tried the above code, but received an error. I have attached a screen shot of the error.
I don’t mind rethinking the whole thing if I have to, but because I cannot nail down the time frame between logging incidents, I cannot build the clear table into SQL.
The error is saying that it found a newline character when it shouldn’t have. Because of the way Jython gets parsed, you need to put that code all in one line. ie:fpmi.db.runUpdateQuery("DELETE FROM sv3_machine_data WHERE sv3_machine_data_ndx > 30")