473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Help using flags

I am monitoring some electronic equipment. Every few seconds i poll for
equipment status. The results are returned in 6 groups - like 0A 40 08 00 00
00. Currently only the first 3 bytes contain meaningful info

each bit reports either normal operation (a 0) or an error condition (a 1)
for a component of the equipment.

I set up <flag> Enum for each byte (just the first 3 bytes for now)
Enum Byte1
None=0
component1=1
component2 =2
component3 = 4
.... to 128
end enum

Enum Byte2
None=0
component1=1
component2 =2
component3 = 4
.... to 128
end enum

i need a routine that will quickly anaylyze and let me test the status of
each flag.

Thanks.

Feb 4 '06 #1
3 1879
Hi Bob,

You can use an Enumeration to check flags, but the values of the
enumerations must match the values of the flags. Flags are stored as bits,
that is binary values:

1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, etc.

If you give these values to your enumerations, you can use Bitwise operators
to check them.

The following is an article about VB.Net enumerations, including Flags
enumerations:

http://aspnet.4guysfromrolla.com/articles/042804-1.aspx

For more information on VB.Net bitwise operators, see:

http://msdn.microsoft.com/library/de...ml/vaopror.asp
http://msdn.microsoft.com/library/de...dxbitshift.asp
http://msdn.microsoft.com/library/de...fficiently.asp

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Who is Mighty Abbott?
A twin turret scalawag.

"Bob Harrison" <Bo*********@discussions.microsoft.com> wrote in message
news:36**********************************@microsof t.com...
I am monitoring some electronic equipment. Every few seconds i poll for
equipment status. The results are returned in 6 groups - like 0A 40 08 00
00
00. Currently only the first 3 bytes contain meaningful info

each bit reports either normal operation (a 0) or an error condition (a 1)
for a component of the equipment.

I set up <flag> Enum for each byte (just the first 3 bytes for now)
Enum Byte1
None=0
component1=1
component2 =2
component3 = 4
... to 128
end enum

Enum Byte2
None=0
component1=1
component2 =2
component3 = 4
... to 128
end enum

i need a routine that will quickly anaylyze and let me test the status of
each flag.

Thanks.


Feb 4 '06 #2
I suggest taking a look at the BitArray class. It will take an integer
or array of bytes in its constructor. You can then test the status in
individual bits.

Feb 6 '06 #3
I ended up returning the bytes and doing a routine like this

dim rslt as integer
For ii as integer = 0 to 2
Select case ii
case 0
result= byte(ii) and equipment.flagbyte0.test1 '(test one is
value=1)
if result=equipment.flgbyte0.test1 then
doAlarmIcon
else
donormalicon
end if

....code for flags 2,4,8,16,32,64,128
Case 1 'for net status byte
......

"Chris Dunaway" wrote:
I suggest taking a look at the BitArray class. It will take an integer
or array of bytes in its constructor. You can then test the status in
individual bits.

Feb 6 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: REH | last post by:
I'm a little confused about argument dependent lookup. Exactly when does this apply? Specifically, I was hoping to use it to access enumeration constants. For example: namespace Flags { enum...
1
by: Rohit Raghuwanshi | last post by:
Hello all, we are running a delphi application with DB2 V8.01 which is causing deadlocks when rows are being inserted into a table. Attaching the Event Monitor Log (DEADLOCKS WITH DETAILS) here....
5
by: Rob | last post by:
Help me, I'm just beginning with programming in Access 2000. I've tried the http://www.mvps.org/access/api/api0001.htm but it won't work in Access. What am i doing wrong. I don't have...
10
by: Ramprasad A Padmanabhan | last post by:
Hello all, On my linux box ( redhat 7.2 ), I have been using char as a boolean data type. In order to save on the number of bytes as compared to using int or short int. typedef char boolean;...
13
by: Chua Wen Ching | last post by:
Hi there, I saw this article here in vb.net. http://www.error-bank.com/microsoft.public.dotnet.languages.vb.1/148992_Thread.aspx and ...
11
by: pamelafluente | last post by:
I am doing my own PrintDialog, and have placed there a combo with the printer names, as in the PrintDialog provided by VB.NET. Here is the question: how do I open the native windows printer...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
0
by: Drew Greenwell | last post by:
Hello, Can anyone tell me how to write a schema for something like this? Im trying to write a webhelp setup and decided to go with a book chapter theme but i need to constrain this template to...
2
by: muppetjones | last post by:
I have been receiving a "Floating point exception" from Perl after my program has run several iterations. I have not been able to pin point the location of the error, and I am clueless. Especially as...
3
by: Rymfax | last post by:
I was hoping someone could help me get SetupInstallFromInfSection working properly. I'm trying to start in install section in a driver INF (hal.inf specifically). I'm doing this in C#, but I also...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.