WinCC Unified: Convert DINT to DWORD
Hi,
A customer of mine selected a Siemens WinCC Unified RT (PC) with a Rockwell 5380 processor. I can understand your issue. Siemens discrete alarm only works with BOOL or WORD/DWORD (ANY_BIT data type).
My Rockwell PLC programs publishes faults as DINT (32 faults).
Since WORD/DWORD does not exists (as a native type) either faults are publish as BOOL or the WinCC unified converts them.
As indicated by mk42, a scheduled task is a good start. Each DINT needs a scheduled task (tag changed). I don't see that as an issue; it's fast to setup and there are no WinCC Unified performance issues.
Alarm/Fault have a very slow hit rate and depending on the machine size, 10 DINT would give 320 faults.
As you mentionned, the problem is how to convert DINT to DWORD on WinCC Unified? There are no WinCC helper function and, as far as I know, JS will not be of any help.
Solution: On PLC tag change (DINT), bit shift the DINT and Set/Reset a mirror target DWORD.
Here are the steps:
1- Add the same number of DWORD internal tags (a DWORD for each DINT, 1:1).
2- Create a Global script (DINT_TO_DWORD) with the following code:
export function DINT_TO_DWORD(dintValue, tagNameToWrite) {
/*
Set DWORD tag bit that mirrors the DINT bit field values
Useful to set alarms according to a DINT tag (typ. for Rockwell processor)
param:
dintValue : tag value to parse
tagNameToWrite : string name of the tag to be written to (typ. DWORD tag)
*/
let tag = Tags(tagNameToWrite);
for (let i = 0; i < 32; i++) {
let value = dintValue >> i & 0x0001;
if (value != 0)
tag.SetBit(i);
else
tag.ResetBit(i);
}
}
3- Setup a Task Schedule for each DINT (PLC tags).
For each task, set in the "Events/Update" a call to the DINT_TO_DWORD global script.
Ex. GlobalModule.DINT_TO_DWORD
dintValue: CONTROLLERTAGS\Cell\fault // DINT, PLC Tag
tagNameToWrite: cellFault // DWORD, alarm tag name
4- Setup discrete alarms in WinCC Unified using the mirror DWORDs.
Voilà.