I have a INT32 tag called ControlDINT
I need to Read and Write to the individual bits in that tag.
In Compactlogix processors I can address this as
ControlDINT.0
ControlDINT.1
ControlDINT.2
ControlDINT.3 and so on up to ControlDINT.31
How can I read and write these bits using the panel?
The reference and user documentation is not of any use.
Bit Level Operations on INT32 or INT16
-
- Posts: 137
- Joined: Mon Jun 11, 2012 2:10 pm
Re: Bit Level Operations on INT32 or INT16
To change a single bit you can write script such as
Note that when you write to a tag the entire tag value will be written to the controller not just the single bit you set.
Code: Select all
int setBit(int currentValue, int bitNumber, bool value)
{
int bit = 1 << bitNumber;
if (value)
currentValue |= bit;
else
currentValue &= ~bit;
return currentValue;
}
Adam M.
Controls Engineer
FlexEnergy
Controls Engineer
FlexEnergy
Re: Bit Level Operations on INT32 or INT16
Hello all!
'Cause I have 0 knowledge with C# and scripting I took another approach...
Each INT is a sum of numbers. Every bit has its own number. Bit 0 = 1, Bit 1 = 2... BIT 7 = 128.. And so on... If I add or subtract from INT a value of 2, then I will change only the BIT 1 in whole INT.
Example. I want to change BIT5 in the whole INT. This is decimal number 32. So I add two buttons - one is visible if BIT5 is 0 and one if BIT5 is 1. First button add 32 to the INT (Increment Analog) and the second subtract 32 (Decrement Analog). The end result is changing Bit 5 from 1 to 0 or in other direction.
I hope I helped someone...
BR
Gargy
'Cause I have 0 knowledge with C# and scripting I took another approach...
Each INT is a sum of numbers. Every bit has its own number. Bit 0 = 1, Bit 1 = 2... BIT 7 = 128.. And so on... If I add or subtract from INT a value of 2, then I will change only the BIT 1 in whole INT.
Example. I want to change BIT5 in the whole INT. This is decimal number 32. So I add two buttons - one is visible if BIT5 is 0 and one if BIT5 is 1. First button add 32 to the INT (Increment Analog) and the second subtract 32 (Decrement Analog). The end result is changing Bit 5 from 1 to 0 or in other direction.
I hope I helped someone...
BR
Gargy