Tag Change script trouble shooting

Hello all

I am using Tag Change scripts on my ignition client to store some real time values from PLC to SQL database.
Earlier I used to get proper data log to SQL. But I don’t know what went wrong and suddenly it stopped. Although I checked manually to insert data in SQL database and its working.
I wanted to log data only when my tag bit is HIGH.
Below is my script.
import system
import app

SQLtrigger = system.get.tagValue(xxxx)

If SQLtrigger == 1:
app.datalog.sqlupload()

Above function in if statement works fine if I call it on button event.

Can anyone help me with this?

Thanks
Ashish

is this in a client or gateway tag change?

id add some print statements.

some thing like this:

import system
import app
print 'start script'
SQLtrigger = system.get.tagValue(xxxx)
print SQLtrigger

If SQLtrigger == 1:
    print 'trigger = 1 send to app'
    app.datalog.sqlupload()
    print 'sent to app'
else:
    print 'trigger = 0 do nothing'

Hello,

try it:

import system
import app

SQLtrigger = system.tag.getTagValue(xxxx)

If SQLtrigger == 1:
app.datalog.sqlupload()

regards

Hi
I am using this script in client tag change menu.

If this is a client tag change script then you should do it like this

if newValue.value == 1: app.datalog.sqlupload()

What I’ve found helpful when troubleshooting client and gateway scripts is to wrap the whole thing in a try/except loop and then write the error string to a different SQL table if it finds an exception.

Something like:

try:
     #your code here

except Exception, e:
     sqltxt="INSERT INTO tblEventLog (eventDate, eventDescription, eventLocation) VALUES(GETDATE(),?,?)
     system.db.runPrepUpdate(sqltxt,[str(e),"Some Locating info"],"yourservername")

Including str(e) in your upload will give you the error message about what is going wrong. It doesn’t have the exact line it faulted on, but it helps more than anything else. I usually throw in a tag referencing the client name or hostname as well.

If the tag change script is not running you can also look in the gateway console to see if there is an error logged.