Don't allow tag to go below zero

I have a customer that wants me to limit the value of the OPC tag from the PLC to a positive number. In other words, if the actual analog input falls below 0, I want to display 0 and store 0 to the history.

I thought tag clamping would be the way to do this, but it doesn’t work. Any ideas? I thought about putting an expression tag, but I’m using a lot of UDT’s and this would be difficult.

I understand this may not be an option, but this sounds like something that should be done in the PLC.

Otherwise, an expression tag as you suggested added into the required UDT(s) and referencing the raw PLC value also in the UDT would work.

Normally, that’s what I would do. However, in this case, I don’t have the ability to make changes in the PLC. I went ahead and just put a script on the vision window.

1 Like

It’s good to separate concerns. If it only matters to the user to show 0 on the GUI for the tag(but not in historian or what have you) then only putting the logic on the GUI seems appropriate.

This should definitely be done from the PLC if they are also wanting to limit the value to zero in the history. Otherwise you will be writing to the tag from 2 directions, just asking for a race condition to occur, and most likely not guaranteeing the value in history to not drop below zero.

Yes, if it can’t be done in the PLC, the second half of the quote above suggests it should be done via expression tag (with history on it), rather than a script in the GUI.

Expression tag in UDT is totally easy and the straight way to do it.