I'm using Ignition's serial module to control some lights, using a vision client on a pc to communicate with an Arduino to ultimately send the signal to the light.
I was wondering if it was better to open and configure a serial connection at the startup of the vision client, and send over a persistent connection that lasts for months (with some code that detects if the connection is ever lost, logs an error, and attempts to reconnect).
Or, is it better to open a new serial connection each time I want to change the lights, send the values, and then close the connection? My issue with this is that opening a serial connection to the Arduino causes it to reset, which takes a few seconds -- and means that I need to add some delays between opening and writing.
You've basically answered your own question? Sounds like keeping it open and writing a heartbeat is the best option for your usage.
1 Like
Ah, I hadn't considered the heartbeat.
Is the purpose of that just transmitting dummy data to stop the software from auto closing the connection?
Right now we send the tag data every tag change, as well as every 5 minutes. Should we do something in addition to this, or will this be enough?
In normal terms, a heartbeat is useful to generate an alarm on a system if it stops performing as expected. Normally you want to know if your serial link has died before it causes a problem on the floor. Software doesn't normally close a connection unless you have configured a timeout on it, you would normally have a heartbeat that is less than half the timeout value so that if one packet gets missed it can retransmit and it will survive the timeout cutoff.
Most Industrial systems use fixed polling for IO, so maybe just send the current data at 1s intervals regardless of change and you satisfy your heartbeat requirement by responding to the sent data.
Alright. I'll bring it up that we should look to having the Arduino client respond to the data sent. Right now it just accepts the data, but doesn't communicate back.
For our serial devices we normally poll for the Unit Id, Serial number, or internal clock value as a keep alive. It might be worth configuring your arduino to have the ability to send that on request.
For now, I'm just having the arduino echo back the sent message, whenever we send it an alarm. We do this in the following manner inside ignition
system.serial.write(com_port, my_message)
response = system.serial.readLine(com_port)
system.serial.readBytes(com_port, 1) # discard second half of newline
expected_message = "Received code: " + my_message
if response != expected_message:
log_to_gateway("error", "Unexpected message from andon. Expected: \"{0}\", got: \"{1}\"".format(expected_message, response))
Is this a decent solution?
1 Like