Getting at underlying data

Server side code on an event:

Srvr = "SIMATIC.S7-1500.OPC-UA.Application:PLC"
Pth = 'nsu=http://www.siemens.com/simatic-s7-opcua;s="BatchDB"."Data"'
DB1_Data = system.opc.readValue(Srvr, Pth)
MyMsg = DB1_Data.getValue()#['VacuumCheckStart(inHg)']
MyFunc.MsgBox(str(MyMsg))

Returns:

{"VacuumCheckStart(inHg)":0.0,"VacuumCheckStart(Time)":[144,1,1,0,0,0,0,2],"VacuumCheckStop(inHg)":0.0,"VacuumCheckStop(Time)":[144,1,1,0,0,0,0,2],"VacuumCheckLoss(inHg)":0.0,"BatchStart(Time)":[144,1,1,0,0,0,0,2],"HeatSetStart(Time)":[144,1,1,0,0,0,0,2],"CoolStart(Time)":[144,1,1,0,0,0,0,2],"BatchStop(Time)":[144,1,1,0,0,0,0,2],"HourlyDataIndex":2,"HourlyTimes(Time)":[144,1,1,0,0,0,0,2,144,1,1,0,0,0,0,2,144,1,1,0,0,0,0,2,144,1,1,0,0,0,0,2,144,1,1,0,0,0,0,2,144,1,1,0,0,0,0,2,144,1,1,0,0,0,0,2,144,1,1,0,0,0,0,2,144,1,1,0,0,0,0,2,144,1,1,0,0,0,0,2,144,1,1,0,0,0,0,2,144,1,1,0,0,0,0,2,144,1,1,0,0,0,0,2,144,1,1,0,0,0,0,2,144,1,1,0,0,0,0,2,144,1,1,0,0,0,0,2,144,1,1,0,0,0,0,2,144,1,1,0,0,0,0,2,144,1,1,0,0,0,0,2,144,1,1,0,0,0,0,2,144,1,1,0,0,0,0,2,144,1,1,0,0,0,0,2,144,1,1,0,0,0,0,2,144,1,1,0,0,0,0,2],"OilTempSetpoint(C)":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"OilTemp(C)":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0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.0,0.0,0.0],"BAC UnitTempOut(C)":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"AmbientAirTempInside(C)":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"AmbientAirTempOutside(C)":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]}

What is the syntax for reading the data out of MyMsg?
MyMsg[‘VacuumCheckStart(inHg)’] returns ‘must be an integer’ and
MyMsg[0] returns a {

I think your last line may have converted the dictionary to a string, try without the str function.

Thanks, but I got it working…

import json
Srvr = "SIMATIC.S7-1500.OPC-UA.Application:PLC"
Pth = 'nsu=http://www.siemens.com/simatic-s7-opcua;s="BatchDB"."Data"'
DB1_Data = system.opc.readValue(Srvr, Pth)
MyMsg = DB1_Data.getValue()
MyDict = json.loads(MyMsg)
MyFunc.MsgBox(str(MyDict['VacuumCheckStart(inHg)']))

Parsing with json.loads only to immediately call str doesn’t make any sense; you’re just burning CPU cycles for no gain. Passing MyMsg directly to MsgBox should work; the errors you were getting line up with MyMsg already being a string.

It looks like the OP was only wanting one value out of the dictionary.

1 Like

D’oh, you’re right. Carry on.