Alerts


Recommended Posts

Hi,

I have two questions:

1. When Runtime is working there is no any Command/Alerts, even there is.

I read datas from Modbus Device, starting Mysequence.

If there is any fault with connection or loss, Mysequence stops and we dont realize it.

I would like to put an Alert that there is no connection with Modbus device and also show that sequence stoped.

How can I do that?

2. In the manual, there is a system event OnAlert(). How can use it?Could you give me an example?

Thank you,

Link to comment
Share on other sites

There are three ways to do error handling. You can use all three in development and #2 and #3 in runtime:

1) See the errors in the command/alert window. This is really only useful for debugging, as you cannot do anything automatically from this. It is also not available in runtime.

2) Use try/catch blocks in your script to catch errors as they occur and do something specific. For example, you could use a try/catch block to catch a modbus error, set a variable that displays on the screen to tell the user there is an error, delay a few seconds and then try again. The code might look like this (I skipped a few parts, marked with ...):

private datain
global string errormessage
while(1)
   try
	  datain = device.mydevice.readholding(...)
	  ...
   catch()
	  errormessage = strLastError
   endcatch
   delay(1)
endwhile

This loop will query a modbus device every second and if there is an error, set the errormessage global to the error message, wait a second and try again. The sequence will not stop on the error.

3) Use the OnAlert system event. This doesn't give you as much control. It won't, for example, prevent the sequence from stopping. It is designed for two things: a) allowing you to create a display of errors in runtime where command/alert is not available, and B) more importantly, to allow you to catch asynchronous errors, for example streaming errors on a LabJack, or Email errors. Using OnAlert is simply a matter of creating a sequence called "OnAlert". This sequence is called whenever an Alert / Error occurs that isn't trapped by #2. A private variable parameter called strAlert is passed in that you can use to determine what the alert is, or simply display it. It is private, so you would have to assign it to a global to display the error on screen.

Link to comment
Share on other sites

  • 9 months later...

Archived

This topic is now archived and is closed to further replies.