in source/machine_connector/m2c2_opcda_connector/m2c2_opcda_connector.py [0:0]
def job_execution(connection_data, running_count=0, error_count=0):
"""Executes the job."""
global payload_content, control, ttl, connection
if control == "start":
try:
start_time = time.time()
# In this section, the program will pull data based on explicit tags (in keywork ['tags'])
# provided by the user or tags based on a wild card pattern
# provided by the user (in key word ['listTags])
if connection_data["opcDa"]["tags"]:
payload_content.extend(
connection.read(connection_data["opcDa"]["tags"])
)
# Here, to find all tags that match the wild card,
# we first must list the tags, then read them
if connection_data["opcDa"]["listTags"]:
for entry in connection_data["opcDa"]["listTags"]:
payload_content.extend(
connection.read(connection.list(entry))
)
running_count += 1
error_count = 0
# Send the data if the query iterations are done.
if running_count >= connection_data["opcDa"]["iterations"]:
running_count = 0
post_to_user("data", convert_to_json(payload_content))
payload_content = []
ttl = time.time() - start_time
except Exception as err:
logger.error("Unable to read from server: %s", str(err))
error_count += 1
if error_count >= ERROR_RETRY:
try:
logger.error("Connection retry to OPC DA server...")
device_connect(connection_data)
logger.warn("Connection completed. Connection starts again...")
except Exception as e:
logger.error("Connection retry failed: %s", str(e))
logger.error("Stopping the connection.")
control = "stop"
post_to_user("error", msg.ERR_MSG_LOST_COMMS_CONNECTION_STOPPED.format(err))
Timer(
interval=connection_data["opcDa"]["interval"],
function=job_execution,
args=[connection_data, running_count, error_count]
).start()
elif control == "stop":
if payload_content:
post_to_user("data", convert_to_json(payload_content))
payload_content = []
connector_client.stop_client()
try:
connection.close()
connection = None
except Exception:
pass