Common Pitfalls in GCL+ Programming (Part 1 – Boolean Logic)

Setpoint Systems has been providing FREE training to our customers for over 25 years, and in that time we’ve learned as well… how to best serve our customers.  We’ve also learned to recognize some of the most common technical challenges our customers face.  I’d like to highlight a few GCL+ programming challenges and solutions.  This post will lay the foundation for future discussions.

We need to start with a brief introduction of boolean logic.  You can follow the embedded link to see the definition in more detail, but in a nutshell here’s what it is:

Boolean logic (boolean algebra), is all about statements being either true or false.  This is fundamental to how computers and programming work.  True can also be thought of as 1 and false as 0.  A question can be asked and the answer is either true or false.

Courtesy of Sue's Blog Spot: http://suesauer.blogspot.com/

Courtesy of Sue’s Blog Spot: http://suesauer.blogspot.com/

For example, we might want to know if the weather is nice outside.  We can’t ask a computer or DDC controller if the weather is “nice” though–it would have no idea what we mean.  We must ask specific questions with true or false answers, like “Is the outside temperature above 60°F ?”  But the way boolean logic works, we represent our question in the form of a statement that can be evaluated as true or false.  This would look like “Outside Air Temp > 60”.  So far so good, right?

But what if it gets too hot?  We need to add more criteria to our question.  Perhaps we’d like to ask “Is the outside temperature is between 60°F and 85°F ?”.  What would that look like if we wanted to ask a DDC controller?  We now have TWO criteria that both have to be true.  It has to be above 60°F AND below 85°F.  This introduces the boolean operator “And”.  When we use “And”, the statements on either side must both be true in order for the whole statement to be true.  If either statement is false, the whole thing is false.  Our statement would now look like “(Outside Air Temp > 60) AND (Outside Air Temp < 85)”  I’m using parentheses to emphasize the two statements that are being compared by AND.

Another commonly used boolean operator is OR.  If you want EITHER statement to be able to make the overall statement true, this is what you use.  For example, we might ask “Is the outside temperature is between 60°F and 85°F OR is the outside relative humidity below 75% RH ?”  This would be shown as “((Outside Air Temp > 60) AND (Outside Air Temp < 85)) OR (Outside Relative Humidity < 75)”.  Again, note the use of parentheses to indicate the order of operations.  This is especially important if you mix AND along with OR in the same statement.

Finally there’s NOT.  This one is fairly simple–it reverses true to false and false to true.  For example, if I wanted to know if it wasn’t raining outside, I could ask “Is it NOT raining?” which would be shown as “Not(Raining)” where “Raining” is a boolean true/false value that lets me know when it IS raining.  Making sense or NOT(making sense)…?

I hope this has been informative.  It lays the foundation for upcoming discussions of GCL+ programming tips.  Stay tuned for more!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s