08-18-2025 03:51 AM
I have a cluster of 3 error clusters. Each error cluster relates to a translation stage. I would like to have a guard clause in my state machine but the case structure only allows 1 error cluster to be wired to it at a time. I have used a for loop in the hope of passing out a single error cluster at a time.
I think I am on the wrong track here... I would appreciate some advice on a better alternative.
Thank you for your time
Alex
08-18-2025 04:26 AM
Use Build Array instead of Bundle, then autoindex the array into the For loop.
However the Case structure must be into the loop. Whether this is appropriate for your program or not cannot be assessed without additional details.
08-18-2025 05:56 AM - edited 08-18-2025 05:57 AM
Hi Alex,
in the example as shown in your image you should use BuildArray instead of Bundle to get an array of clusters (as already suggested).
When your question is more general "how to process each element of a cluster of same elements" then you could use ClusterToArray to convert the cluster (consisting of elements of the same datatype!) into an array.
In the end you get an array where you can apply an autoindexing FOR loop!
08-18-2025 07:36 AM
Good morning, Alex.
I'm curious why you need three Error lines on Shift Registers within a State Machine. Can a single State give rise to two separate Error Lines, each of which are capable of generating an Error, meaning the State can have 0, 1, or 2 Errors within it? [I can envision such a scenario, but I'll discuss it later ...].
I use a Channel Message Handler as my model for a State Machine. The Message consists of "Next State" (an Enum) and "Arg" (a Variant, in case I need to pass something "into" the State). At the end of the Case Structure that encapsulates the State's code, there is an (optional) "Send Message" sub-VI that has as inputs the new "Next State" and any other Argument you need to pass (often unwired). Between the exit from the Case and the exit from the surrounding While, there is an Error Handler routine that checks for Errors.
The net effect is that instead of going to "my next state", it goes to "Error State" with an Argument that tells what State caused the Error and the Error itself. Now you can write code to do something with this information, including, if you want, to simply log it, and then (since you know what was going to be done next if there were no error) simply exiting the Error State and going to the "Next State". [I don't advocate this -- I'd say "Save the Error Information to a file, and do a graceful shut-down, if possible".]
Bob Schor
08-18-2025 08:19 AM
Thank you both for the solution, but sadly it has raised further questions. The whole programme is shown below.
The producer loop will actually generate an image(5-10 per sec) to the user, once I receive my camera, for know I just generate a number. The consumer loop will be an event state machine. It will deal with things like move only x,y or z, scan over x-y plane (nested loop) from x_min to x_max in steps of delx and y_ to y_max in step of del_y and a few other things.
I see now that the guard clause will send only the last err cluster, so I have now connected the error wires to the case structure. I want to use these to ensure sequential operation of the stages. However, with so many error wires it is starting to look a mess..
Thank you once again.
Alex
08-18-2025 08:29 AM
Hi Alex,
@alex_b2 wrote:
The producer loop will actually generate an image(5-10 per sec) to the user, once I receive my camera, for know I just generate a number. The consumer loop will be an event state machine. It will deal with things like move only x,y or z, scan over x-y plane (nested loop) from x_min to x_max in steps of delx and y_ to y_max in step of del_y and a few other things.
I see now that the guard clause will send only the last err cluster, so I have now connected the error wires to the case structure. I want to use these to ensure sequential operation of the stages. However, with so many error wires it is starting to look a mess..
This XYZ stage is just one device, so why do you need 3 error wires for a single device?
08-18-2025 10:14 AM
Hello Gerd,
The x,y z stage is not a single stage. There are 3 actuators (Thorlabs DRV014) which are connected to a stepper motor controller (Thorlabs BSC203) and controlled independently. The x & y actuators will move a sensor, which I will raster over the plane parallel to the table. The z stage will move a light spot up and down, normal to the table.
Thanks for your input.
Alex
08-18-2025 10:22 AM
If you want to stop on any error while keeping error info separate for each stage, use Merge Errors to get a single output error wire (it's similar to an OR).
To Merge Errors you can wire the three error wires separately, or an array of errors.