The logic is like this:
- In gateway events, the trigger signal is monitored, and tag change scripts is like so:
if newValue.getValue() == True:
config = system.tag.getConfiguration(str(event.tagPath.getParentPath()).replace('handshake/outHandshake', ''))
dbNumber = str(config[0]['parameters']['DB Number'].value)
plcName = str(config[0]['parameters']['PLC'].value)
locationCode = str(event.tagPath.getParentPath()).split('/')[1]
infoResult = system.opc.readValues('Ignition OPC UA Server',\
["["+plcName+"]DB"+dbNumber+",STRING310.1",\
"["+plcName+"]DB"+dbNumber+",STRING314.4",\
"["+plcName+"]DB"+dbNumber+",STRING304.4",\
"["+plcName+"]DB"+dbNumber+",STRING320.14",\
"["+plcName+"]DB"+dbNumber+",STRING336.157"])
project.mes.sendTelegram(str(event.tagPath), locationCode, \
infoResult[0].value, \
plcName, \
infoResult[1].value, \
infoResult[2].value, \
infoResult[3].value, \
infoResult[4].value, dbNumber
)
- As written above, telegram data is read, and self-developed function project.mes.sendTelegram is called.
def sendTelegram(tagPath, locationCode, offline, plcName, seqnr, telegramCode, timestamp, body, dbNumber = ''):
startDate = system.date.now();
logger = system.util.getLogger('MES-'+locationCode)
logger.info(locationCode + " " + telegramCode + " " + body)
retryNum = 0
homePath = tagPath.split("/handshake")[0]
handshakePath = tagPath.split("outHandshake")[0] + "inHandshake/";
delay = 0
# generate delays for correctly writes to PLC
import time
time.sleep(0.25)
system.opc.writeValue('Ignition OPC UA Server', "["+plcName+"]DB"+dbNumber+",X16.0", False)
# generate delays for correctly reads from PLC
time.sleep(0.25)
checkValue = system.opc.readValue('Ignition OPC UA Server' , "[" + plcName + "]DB" + dbNumber + ",X16.0").getValue()
while checkValue == True:
logger.warn('Write problem')
system.opc.writeValue('Ignition OPC UA Server' , "[" + plcName + "]DB" + dbNumber + ",X16.0" , False)
# generate delays for correctly reads from PLC
time.sleep(0.25)
checkValue = system.opc.readValue('Ignition OPC UA Server' , "[" + plcName + "]DB" + dbNumber + ",X16.0").getValue()
# more logics about interactions with Java Instance
Without the time.sleep(0.25), there always occur that value False is not correctly written to the target place, while the extra readValue still telling me the data is written to False (No log info with "Write Probelm" ever appeared).