I am trying to get user loaded text from PMI inserted into a db. I need it to write to the db on a change in a sensor value ( on/off ). I have created the table and have written the attached script:
if event.source.value == '1':
fpmi.db.runUpdateQuery("INSERT INTO Shower_Data (description, date_lot, t_stamp)
VALUES (event.source.parent.getComponent('Inflator Desc Sensor 1').text,
event.source.parent.getComponent('Date_Lot Sensor 1').text,
GETDATE())", 'Automation_Eng_Group')
I am trying to assign this to a number label on a property change action.
You are really close! If you want to capture those values when the numeric label changes, you want something like
[code]#It’s less confusing if you pull out the variables
desc = event.source.parent.getComponent(‘Inflator Desc Sensor 1’).text
dateLot = event.source.parent.getComponent(‘Date_Lot Sensor 1’).text
#only execute the code if the value property changed
if event.propertyName == “value”: #only execute if the newvalue is 1
if event.newValue == 1:
fpmi.db.runUpdateQuery(“INSERT INTO Shower_Data (description, date_lot, t_stamp) VALUES (desc, dateLot, GETDATE())”, ‘Automation_Eng_Group’")
[/code]
There’s a button in the lower right of the event configuration screen that looks like two stacked “^”. If you click it, you can see all the values you have available for that event (ie propertyName and newValue).
Keith,
Do you need to store this in a specific database location, or just in the database? Are you using FactoryPMI 3.0.x?
With SQLTags you can just create a db tag and bind the numeric label and input to it. In fact, just drag the tag to the window and it will do that for you.