Best way to turn boolean tag value high every 5 seconds?

I am creating a heartbeat between ignition and a plc. I want to set a boolean tag high every 5 seconds. The plc will be turning it off. Also on the ignition side I want to say if boolean tag remains high for 15 seconds then trigger an alarm. Whats the most efficient way to do this? Create a new tag group with a scan rate of 5 seconds to set the bit high again and set some sort of counter that if three scans go by and its still high then trigger an alarm?

Smart people suggest that it’s good practice not to write to one tag from two sources (Ignition and PLC). Example:

I know that doesn’t answer your question, but I think you could benefit from searching “handshake” on the forum and seeing how others have implemented.

1 Like

I can try handshake. I do not have a DB to access for this so transaction groups or ways using a DB are out.

Handshake issues asside, i’m not sure this is the most efficient way but in your place i would do the following:

  • Create a Timer Gateway Event, configure it with a delay of 5000(ms) with fixed delay and shared threading.

  • Use the following script:

#Read the tag value
myTag = system.tag.read('TagAddressHere').value
if myTag == False:
	#Write only if the Tag is False.
	#If your tag is True for too long, the alarm should detect it.
	system.tag.write('TagAddressHere',True)

The Equal mode with a setpoint of 1 will monitor when your tag is True to turn on the alarm but with the Active delay set to 15, it should wait 15 seconds before actually activating the alarm.

I hope this helps!

Thanks. Its worth a shot.

The thing also is I will have 6 different plcs I am monitoring connections to on two different gateways eventually but for now I am trying to get heartbeat established between one backend gateway and one plc on the gateway. I want to be able to produce an alarm on both the plc and ignition side. Obviously if they aren’t talking then you cant feed that same alarm through both avenues.

I have done this by creating an OPC tag that my plc will set to 1 ever 10 seconds. I then created a gateway timer script that will increment a memory tag by 1 every second. To finish i use a gateway tag change script that will reset my memory tag to 0 when the OPC tag changes state. If your Memory tag is greater than 15 PLC fail alarm.

@leonardo.godoi’s method is probably cleaner, but this works aswell.

I tend to prefer encapsulating this type of functionality into a UDT. This way I can easily instantiate another “heartbeat” object when it is time to monitor another device (in this example). Attached is a tag JSON that will create the structure shown here:

HeartbeatObjects

You’d obviously change the heartbeat tags to OPC tags and then set the address accordingly–the example here uses memory tags.

heartbeat_objects.json (5.0 KB)

1 Like