Create a Boolean Variable in PacControl. How?

How do I create a Boolean variable in PacControl?

I only see Int32 or int64.

Can a variable created with one of these data types be referenced at the bit level?

If so, what would be the syntax to use?

Objective is to create a virtual I/O point (coil) that will be used in my strategy, which PacDisplay will in turn also recognize it as a Boolean point and not as its int32 parent tag.

Thanks

Hi skyfox,
Yes! Check out this discussion on testing for “true”. Also, you’ll find in PAC Display when choosing either Int32 or Int64 tags, you’re given the option of specifying the bit. Here’s an [URL=“http://www.opto22.com/community/showthread.php?t=412&p=1631&viewfull=1#post1631”]OptoScript example that does some bitwise manipulations. In the “Logical” commands in PAC Control, you’ll find a wide variety of commands like “Bit Test” and “Bit Set” and related.
-OptoMary

Thanks OptoMary,

Your help is much appreciated!

Good Morning OptoMary,

Well, that was not exactly what I was after.

From what I read from your “[B][U]Testing for True[/U][/B]” post is that you are testing the entire “int32” variable value to see if it is “True” or false instead of checking an individual bit in that double word.
What I want is to simply set or clear an individual bit (bits 0-31) in that int32 variable.

i.e. Want to [B]Set[/B] int32(bit 5) or (bit 7) or (bit 11) etc., etc.

In the PLC world (in its simplest form) I can do;

                                                   --[ Some Input On ]----------------------------(My Variable.Bit2) -  Done.                Simple and clean!

In OPTO world, am I going to have to do something like;

int32_test [B][OR][/B] 2^Bit //pseudo code example

Or, similar using OPTO script every time I want to set or clear a bit in one of my local variables?

Can this be done without using OPTO script? This could get really cumbersome and frustrating if I am dealing with or, want to/have to deal with lots of Boolean variables. Example shown was for just setting one bit. Checking for true and comparisons with other variables will need to be done as well.

Is there a simpler way?

Just out of curiosity, why is “Boolean” Data type not available in PacControl ?

Thx.

Hi Skyfox,

Sounds like you need ‘bit set’ and ‘bit clear’ commands.
You will find them on page 278 and 292 in doc 1701, the pac control command reference.

PAC’s are a little more liberating than their younger siblings PLC’s.
I once worked with a programmer that came from PLC land, and he was a big bit set/bit clear guy.
He would use the same int32 variable all over the place, and use different bits in different parts of the program.
Rightly he claimed that it was more efficient, however in a PAC, we have lots of memory and not need to get down to flipping bits just to save a few bytes.
When time came to debug and commission the system I lost track of the number of times he shot himself in the foot by losing track of which part of the program (strategy) set which bits.
Slowly but surely he came to see that it really was a lot simpler and far more efficient to just use an appropriately named int for true and false.
It makes the program easier to read and debug when your under pressure and it sure makes things a lot easier for someone else to come along at a latter time and work on the system.

Just my real world 2cents worth.

The nice thing about programming is that its art and not science. Thus there is no right and wrong, its what ever works for you.

Ben.

Thanks Ben,

PAC’s are a little more liberating than their younger siblings PLC’s.

I guess this one is debatable. PLC’s have come a long way.

In a PAC, we have lots of memory and not need to get down to flipping bits just to save a few bytes.

Well this one I guess depends on how you use it.

I can use one Int32 (2-bytes) to toggle 32 outputs (for example when in manual mode) or, buffer 32 input bits. In a PAC, the same would take 64-Bytes to do the same. So there is a big difference.

The nice thing about programming is that its art and not science. Thus there is no right and wrong, its what ever works for you.

Agreed,

And thanks for pointing out “page 278 and 292 in doc 1701” not sure how I missed it. Been thru over 1500 pages of documentation in the last few days.

Thanks again.

Cheers.

Hi Skyfox,

We have a lota lota lota customers that have written some pretty big strategies and never come up against any issues of 64 bytes vs 2 bytes. PAC’s have megabytes of memory, so they can write their strategies the way they want.

At the end of the day, they get the job done, and that’s the important thing.

No worries about the bit set and clear, I always keep at hand a printed copy of form 1703, the pac control commands quick reference.
The commands are grouped by type, so its easy to narrow down what is there, and then you can dig deeper for any command after that in form 1701.

Glad we could help.

Ben

Hi All, I can see the thread that Mary linked to is no longer valid… are there any recent threads related to this? I’m trying to get a Groov View button to trigger a chart in PAC Control, but I’m having issues with checking if the bit/variable is true or false.

I have tried Variable True? and Bit On? Logical functions but none seem to be working. I’ve just got the int32 variable linked to a button in Groov View, which I can confirm is being written true as I’m viewing the state of said variable via an LED on the same page. I just can’t seem to get this state change in PAC Control. Mind you, I specified the Bit on Groov View to be Bit 1.

The Variable True command should work - can you post the code/logic or screenshot of what you are trying?

FYI, by setting bit 1 - the value of the integer will be 2. Setting bit 0 will set the integer value to 1. I think you can leave the bit field empty in groov view and it will set all bits to 1 (value -1). It shouldn’t matter if using the “Variable True” command as any non-zero value would return true (value <> 0).

This may be the original post that Mary was linking to: Bit Addressing - #2 by mstjohn

1 Like

Great, thank you. I changed the button to not specify a bit and that worked great.

3 Likes