DKrohn

Stralert For Messaging And Alarming

Recommended Posts

I am using DF standard on a stand alone non network attached project that measures length and diameter of a product. I have run into a number of instances where errors have caused many samples data to not be exported. I have set up 3 variable value component lines to display stralert[0], stralert[1], and stralert[2], as well as a page with a table to display all the stralerts. While this works to display the messages it still does not capture the operators attention, espesially when the same message is repeated several times. I am looking for a way to alert the operator of a repeated error as well as critical errors while giving them the ability to quiesce the warning until a new critical error arrises.

 

Is there a way to capture only new stralert messages with timestamp and write them to a variable? All the posts I have been able to find have related to messaging only available in the DFpro version.

 

Thanks for any help,

Dave

messaging.ctl

Share this post


Link to post
Share on other sites

You can use the OnAlert() system event to capture all alert messages and do whatever you want with them.  See section 5.28 in the user's guide.

 

However, in an app such as yours you really want to try and create scripts that capture the errors themselves and respond appropriately.  You do this using try/catch blocks.  Just letting DAQFactory handle the errors can have  less predictable results, since it will simply throw up its hands and stop the sequence.  With appropriate placed try/catch blocks you can respond more specifically to errors.

Share this post


Link to post
Share on other sites

pardon my ignorance but reading the manual did nothing for me. I do not understand how to use the OnAlert() or the try/catch blocks. Can someone give me examples of how to use these?

Share this post


Link to post
Share on other sites

Well, try/catch is the better option, so I'll stick with that for now.  Let's say you have some code that does a few different things.

 

... do something

... do something else

... do a third thing

 

Now, if you just try and only use strAlert, or even OnAlert(), then if an error occurs in any of these 3 tasks, the error will be thrown, strAlert will be updated and OnAlert called (if it exists).  The problem is you have no idea which one of these tasks actually caused the error, and you can directly act on it inside that sequence.  If instead you did:

 

try

   ...do something

catch()

   ... got an error, do something with that error.  Message is in variable "strLastError"

endcatch

try

  ... do something else

catch()

   .. got an error doing something else, do something different (or the same) with the error

endcatch

try

   ... do a third thing

catch()

   .. got an error doing the third thing, but the first two things were successful

endcatch

 

So here I surround each of my tasks with try/catch().  Then if an error occurs in any statement between the try and the catch(), DAQFactory will jump to the statement right after the catch(), initializing a local variable called strLastError with the message that would have otherwise gone into the strAlert global (it won't anymore, nor will it show up in command/alert unless you explicitly print it out using ? strLastError).  If no error occurs in the block, once it gets to catch(), it will jump to the statement after endcatch.

 

This allows you to do different things depending on where the error occurred, and probably better recover from the error.  You might create a function called logError() that takes strLastError and does the display/logging you described in the beginning, and that will certainly do what you originally wanted.  But now you can also add other script to better react and recover from the error.  For example, if the error is in a task that reads from a device, maybe you can reinitialize the device if an error is detected in that code block.  

 

There is a lot more you can do with it, such as nesting try/catch, catching only certain errors, doing something then rethrowing the error (useful if you want to make sure a file is closed properly for example), but I'll keep things simple here.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now