Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Generating Error Codes from Status Bits

I am working to create an instrument driver and looking for an efficient way to generate error codes.  The instruments repose to a status inquiry is a 32-bit unsigned word with each bit representing a different status.  For example, Bit 1 is represented with 0 - Temperature Okay and 1 - Overtemperature Condition.   Bit 2 is represented with 0 - Key Switch Off and 1 - Key Switch On.  Bit 3 is represented with 0 - Output Off and 1 - Output On.  To me these status could be an error, warning, or simply a status.  The ones that are just status's aren't a problem, but I want to create error/warning clusters for all the others so I can use error handling.  There is about 20 of them that need to be error clusters.

 

Right now my first thought is to create 20 parallel case structures and then merge the error clusters.  But this seems very inefficient.  Here is an example of what I am starting with.  Another complication is that both values of 0 and 1 could represent the error state on different status bits. 

 

Status.png

Is there a better way of doing this?

 

 

 

 

0 Kudos
Message 1 of 11
(4,421 Views)

Hi

The first thing to do is to define a cluster with all the errorbits and maybe a cluster that defines if the bit is active 1 or zero for an error.

 

The next thing is to do is give these bits proper namesnumber to boolean cluster.png

When the number is turned into an array of booleans it can be fed into a for loop that gets errormessages from an array of strings and these strings are pumped into an errorcluster.

 

just an idea

greetings from the Netherlands
0 Kudos
Message 2 of 11
(4,411 Views)

How I would tackle this problem is first address the issue of some bits being inverted in terms of their error flag status.

 

To achieve this we can create a bitmask, make an I32 number which has all of the inverted bits set to 1 and all other bits set to zero.

Then XOR this I32 mask with your input I32 to create our new masked I32.

 

I would then make a for loop with a conditional terminal, set to iterate 32 times.

 

In the loop I would use the scale by power of 2 function with a value of 1 and a power of (i) from the loop iteration counter.

The output of this function I would AND with our masked I32 and then check if it is equal to the original value.

 

If it is equal, we would want the loop to stop and pass out the value of (i) so we know which bit we matched.

We can pass the value of (i) directly to a case structure which contains all of the required cases, or index out from an array, whatever suits your needs best.

 

Hope this helps.

 

Steve

 

 

Stephen C
Applications Engineer
0 Kudos
Message 3 of 11
(4,396 Views)

I agree almost except for the following lines

 

The output of this function I would AND with our masked I32 and then check if it is equal to the original value.

In the loop I would use the scale by power of 2 function with a value of 1 and a power of (i) from the loop iteration counter.

 

I would have an array of booleans that I feed to a loop (autoindexing) so no need for 32 to be connected

And build an array of booleans that is converted to an intger after the loop.

 

All bit shifting is eliminated in this way

greetings from the Netherlands
Message 4 of 11
(4,387 Views)

That is a nice idea!

Stephen C
Applications Engineer
0 Kudos
Message 5 of 11
(4,382 Views)

I decided to implement this last night when I had some time.

 

I realised that its a little neater to search the 1D bool array for (T) and do away with the loop completely.

Im going to post it up as a community example later, but here it is for now incase you still need it.

 

 

 

Stephen C
Applications Engineer
0 Kudos
Message 6 of 11
(4,349 Views)

Hi

the find error is ok when only one error at a time is expected, but if more errors occur a for or while loop is essential.

the speed is not a problem if the first test is on "any error present" withan array OR on the bits.

In our departement we claim that we have a lot of time if an error is detected, because that one deserves attention anyhow.

greetings from the Netherlands
0 Kudos
Message 7 of 11
(4,342 Views)

Sounds similar to the method I use to look for errors in a status register. I custom build error routines for each instrument.

 

I do not have LabVIEW 2011, though. Can you possibly save your example in LV2010 so I can have a look?

 

     Rob

0 Kudos
Message 8 of 11
(4,340 Views)

maybe I respond twice now but the first reply did not appear soon enough in that case or I pressed cancel.

 

Attached is a LV10 version

Also optimised with a while loop to handle all errors and add strings.A line for each error.

 

greetings from the Netherlands
Message 9 of 11
(4,330 Views)

Thank you for sending the LV2010 version.

 

I had a small problem with it running as an infinite loop at first. The bit array is coming in through a tunnel and search array stops at the first True bit that was found. Then it did that again. I realized that start index of the search had to be connected (to the shift register counter above it). Then it works correctly.

 

Here is the modified version:

 

0 Kudos
Message 10 of 11
(4,327 Views)