LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Producer/Consumer Design Pattern with Classes

I'm starting a new project which involves acquiring data from various pieces of equipment using a GPIB port.  I thought this would be a good time to start using Classes.  I created a GPIB class which contains member data of:  Address, Open State, Error; with member vis such as Set Address, Get Address, Open, Close...general actions that all GPIB devices need to do.  I then created a child class for a specific instrument (Agilent N1912 Power Meter for this example) which inherits from the GPIB class but also adds member data such as Channel A power and Channel B power and the associated Member Functions to obtain the data from the hardware.  This went fine and I created a Test vi for verfication utilizing a typical Event Structure architecture. 

 

However, in other applications (without classes) I  typically use the Producer/Consumer Design Pattern with Event Structure so that the main loop is not delayed by any hardware interaction.  My queue data is a cluster of an "action" enum and a variant to pass data.  Is it OK to use this pattern with classes?  I created a vi and it works fine and attached is a png (of 1 case) of it.

 

QSM with Class.PNG

 

Are there any problems doing it this way?

Jason
.
0 Kudos
Message 1 of 7
(3,598 Views)

Hello Jterosky,

 

I don't see a problem with doing it this way. It should work the same with classes.

Miriam
Field Applications Engineer
NI Colombia
CLD
0 Kudos
Message 2 of 7
(3,559 Views)

@JTerosky wrote:

I'm starting a new project which involves acquiring data from various pieces of equipment using a GPIB port.  I thought this would be a good time to start using Classes.  I created a GPIB class which contains member data of:  Address, Open State, Error; with member vis such as Set Address, Get Address, Open, Close...general actions that all GPIB devices need to do.  I then created a child class for a specific instrument (Agilent N1912 Power Meter for this example) which inherits from the GPIB class but also adds member data such as Channel A power and Channel B power and the associated Member Functions to obtain the data from the hardware.  This went fine and I created a Test vi for verfication utilizing a typical Event Structure architecture. 

 

However, in other applications (without classes) I  typically use the Producer/Consumer Design Pattern with Event Structure so that the main loop is not delayed by any hardware interaction.  My queue data is a cluster of an "action" enum and a variant to pass data.  Is it OK to use this pattern with classes?  I created a vi and it works fine and attached is a png (of 1 case) of it.

 

QSM with Class.PNG

 

Are there any problems doing it this way?


 

Including the error cluster as part of the  private data is something I have never seen done and ... well I'll have to think about that one.

 

Ben

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 3 of 7
(3,545 Views)

I included the error cluster because it contains information specific to the object and I thought (maybe incorrectly...I'm new at using classes) that all data specific to the object should be kept within the object.  Also, since I use the class wire to maintain dataflow that I didn't need the error wire for that purpose....aaahhhh...but what if I want to establish dataflow between vis of different classes...like a signal generator and a power meter?  Then I would need to have the error cluster external to the class so that dataflow can be maintained between functions of different classes.

 

I think that I just convinced myself to pull the error cluster out of the object.

Jason
.
Message 4 of 7
(3,524 Views)

Socratic method at work.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 5 of 7
(3,517 Views)

Thank you both for your comments.

Jason
.
0 Kudos
Message 6 of 7
(3,501 Views)

No problem. You made me think. That is a good thing.

 

Since you are just starting off on the LVOOP path, you may want to view the images I have collected in my LVOOP Albumn. Some of those images have links back to the original thread where they were posted.

 

They may give you some ideas and inspiration.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 7 of 7
(3,481 Views)