Toggle Switch Question... Best Practice?

Good morning Team,

I have a table that holds a value that allows a user to disable/enable a crane. The table updates and writes to the PLC. I am unable to change how this is setup so I am looking for the best way to do create a switch for the users.

Here is the query for the table.

SELECT
    Clemens.storage.data
FROM
    Clemens.storage
WHERE
    Clemens.storage.attribute = 'Crane2_Putaway_Enable' 

Currently I am using a toggle switch. This was working from what I understand but recently it is "acting up". Meaning that if I enable/disable the crane it does not always "update" the table with the desired action. Sometimes, when they enable/disable it looks like it works then when they leave the screen and come back it has reverted back to the original state before they clicked the toggle swith.

Can anyone suggest a better option or maybe a reason why they are seeing a delay or it not working?

Here is the code that I use when the toggle is clicked:

UPDATE storage
SET data = :data
WHERE attribute = 'Crane2_Putaway_Enable'
def runAction(self, event):
	# implement your handler here
		
	data = self.props.label.text
	category = "HMI"
	source = "ASCADA Client"
	usr = self.session.props.auth.user.id
	message = str(usr) + " Changed Crane 2 Putaway to   " + str(data)
	data9 = usr 
					
					
				# Update Crane Putaway mode.
	system.db.runNamedQuery("CFG Queries/crane2_putaway_mode",{
				"data": data
					})
					
				#Update Syslog		
	system.db.runNamedQuery("Tables/syslog_update",{
				"category": category,
				"source": source,
				"message": message,
				"data9": data9
					})

You should check the return value of the Named Query. As an update query you should get a integer representing the number of rows affected by the query. If it returns 0, then you would know that something happened.

It appears that you have the script in an event script?

You should add some logging so that you know how many times the query is being called and what data it is being called with.

I have a sneaking suspension that the query is being called more than you are expecting, and the second time is with data that you're not expecting. Or possibly even being called from multiple sessions.

2 Likes