I am trying to use a UDT to read several Modbus registers, perform a calculation and return a value. Please see code below. Returns a “Error_Configurtion“ message. I feel it is simple or I just don’t have the correct Expression for the tag path to the OPC device.ModbusRegister. Any suggestions?
// Current Unbalance Formula
(
// Calculate Absolute Maximum Deviation of Phase Currents
(max(abs([{deviceName}]{unitId}.HRUS577 - [{deviceName}]{unitId}.HRUS580),
abs([{deviceName}]{unitId}.HRUS578 - [{deviceName}]{unitId}.HRUS580),
abs([{deviceName}]{unitId}.HRUS579 - [{deviceName}]{unitId}.HRUS580))
)
// Divide by Current Average Magnitude * 100 for %
/
[{deviceName}]{unitId}.HRUS580
)*100
You aren't actually referencing the tags. This is the one rare case where the usage of tag() in an expression is allowable. You'll need to rebuild how you construct the dynamic paths to be strings, and place them each inside of tag().
Edit: seems like everyone's reading comprehension is off, or I need more coffee. You cannot do what you are trying in an expression tag.
But how does the tag() expression handle OPC UA Server paths? For this instance of my UDT, I have set up 4x unique parameters to use as a template. The deviceName references the Modbus TCP device on the gateway and the unitId references the Modbus ID.
// Current Unbalance Formula
(
// Calculate Absolute Maximum Deviation of Phase Currents
(max(abs({[.]CurrA} - {[.]CurrAvg},
abs({[.]CurrB} - {[.]CurrAvg}),
abs({[.]CurrC} - {[.]CurrAvg}))
)
// Divide by Current Average Magnitude * 100 for %
/
{[.]CurrAvg}
)*100
Please post code as preformatted text, it preserves whitespace and syntax highlighting, see Wiki - how to post code on this forum. You can edit your post by clicking the pencil icon in the bottom right.
To me it looks like your first abs is missing its ending enclosing paranthesis (adjusted for better readability):
// Current Unbalance Formula
// Calculate Absolute Maximum Deviation of Phase Currents
(max(
abs({[.]CurrA} - {[.]CurrAvg}),
abs({[.]CurrB} - {[.]CurrAvg}),
abs({[.]CurrC} - {[.]CurrAvg})
// Divide by Current Average Magnitude * 100 for %
) / {[.]CurrAvg}) * 100
// Current Unbalance Formula
(
// Calculate Absolute Maximum Deviation of Phase Currents
(max(abs({[.]CurrA} - {[.]CurrAvg}),
abs({[.]CurrB} - {[.]CurrAvg}),
abs({[.]CurrC} - {[.]CurrAvg}))
)
// Divide by Current Average Magnitude * 100 for %
/
{[.]CurrAvg}
)*100