Create a Boolean Variable in PacControl. How?


#1

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


#2

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


#3

Thanks OptoMary,

Your help is much appreciated!


#4

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.


#5

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.


#6

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 ([U]2-bytes[/U]) to toggle 32 outputs (for example when in manual mode) or, buffer 32 input bits. In a PAC, the same would take [B]64-Bytes[/B] 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.


#7

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