03-30-2022 05:31 AM
Hi there,
I have created an action engine that is used to control a camera. The action engine has the following actions:
The action engine functions on a .NET reference that is saved in a USR. However, I want to create multiple camera objects that are identified by the CameraID and for that I would need multiple .NET references. Two options I can think of right now are, making a case for every CameraID that each contain a separate USR or duplicating the function for every CameraID. But I don't really like these solutions. How would you go about doing this?
Solved! Go to Solution.
03-30-2022 09:39 AM
Use a class instead of an FGV. Then you can easily have multiple instances of the class.
03-30-2022 10:06 AM - edited 03-30-2022 10:08 AM
This is why you want to program by wire (even if .NET is by reference).
If you insist on a FGV, you can also keep an array in the USR, and give the VI an index. Obviously, you could use an add, list, remove, etc.
I'd also use a (by wire value) class...
03-30-2022 11:18 AM - edited 03-30-2022 11:19 AM
A little tip for the OP:
When you move from an action engine to a class-based solution it's gonna feel a little like you're turning all your code inside out. Instead of a bunch of action cases all held together in a single case structure, you'll be spreading them out among distinct member functions. Instead of USR's that contain hidden internal persistent data, you'll pass class wires in and out of your functions to preserve the changes you make to your private class data.
-Kevin P
03-30-2022 12:03 PM
@Ongelofeloos wrote:
Hi there,
I have created an action engine that is used to control a camera. The action engine has the following actions:
- Initialize
- StartAcquiring
- RenderImage
- StopAcquiring
- LoadParameters
- Exit
The action engine functions on a .NET reference that is saved in a USR. However, I want to create multiple camera objects that are identified by the CameraID and for that I would need multiple .NET references. Two options I can think of right now are, making a case for every CameraID that each contain a separate USR or duplicating the function for every CameraID. But I don't really like these solutions. How would you go about doing this?
When I run into this I just stuff the USR with an array of refs and make "Channel " or "Device Index" a required input. This avoided a lot of duplicate code at the cost of a IPE between the while and the case
Using a FBN instead of a single iteration while loop cleans it up very nice.
03-31-2022 02:18 AM
@JÞB wrote:When I run into this I just stuff the USR with an array of refs and make "Channel " or "Device Index" a required input.
I was also thinking about doing it like this, using classes is something I still need to get used to.
@JÞB wrote:
This avoided a lot of duplicate code at the cost of a IPE between the while and the case
Using a FBN instead of a single iteration while loop cleans it up very nice.
What do IPE and FBN mean?
03-31-2022 03:16 AM
@JÞB wrote:
This avoided a lot of duplicate code at the cost of a IPE between the while and the caseUsing a FBN instead of a single iteration while loop cleans it up very nice.
What do IPE and FBN mean?
IPE: In Place Element Structure
FBN: Feedback Node
Both are in Programming -> Structures palette