Simple Questions: Writing Tags to SQL

I need to write values to from the plc to my db a bit faster and with more handshaking than I get with the SQL Bridge. I want some advice so I don’t get started wrong on this.

  1. I’ll have a bool tag in the PLC to say I’m ready to send the data. Should I just use memory tags for handshaking and read/write them from my script to control the flow?

  2. Are there pros/cons to having the script be a tag-event script that triggers when the PLC is ready vs. it being a GW script that monitors the status of the trigger? I have enough time that I can afford to only check 1x/sec or so. Are there considerations for each approach?

  3. Any “best practices” I should be aware of?

Thank you.

Heh, “Simple Questions”. Misnomer if there ever were.

Don’t use a bool trigger. I strongly recommend an integer, possibly just a byte, that increments to signal new value. Your script should echo this value to another PLC tag to signal success (handshake). The PLC should not send any new values while the two differ. Ignition should have a startup check to handle any difference that was missed, and then cache the value of the handshake integer.

Writing tags from one direction only is very important for avoiding data races. (General advice–applicable to pushbutton logic, too.)

I avoid tag events, largely because all tags use the same scripting environment. Edits can be very disruptive. I recommend gateway tag change events segregated to appropriate projects.

I recommend only the PLC->Ignition trigger integer be assigned to an OPC tag. All other relevant data should be read with system.opc.read*(). After any database operations, use system.opc.write*() to deliver any reply data and then the handshake. The latter in its own call when sure all reply data was successfully written.

Catch errors and set a state marker for a timer script to see and retry whatever was broken.

That’s really helpful Phil, thank you so much.