LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

HAL design issue: multi channel device should mimic many single channel devices

I am stuck with the following scenario and I am sure that you also ran into it. Let's assume I have two different sensors to read the voltage from every 10 ms.
I could do this with 2 distinct voltmeters, but also using a multichannel voltmeter or an oscilloscope.


How would could I design my HAL, that my multi channel device mimics 2 distinct single channel devices.

 

For this assume the following actions for reading the sensors:

 

init voltmeter1

init voltmeter2

 

start voltmeter1
start voltmeter2


read voltage voltmeter1

read voltage voltmeter2

read voltage voltmeter1

read voltage voltmeter2

...

 

stop voltmeter1

stop voltmeter2

 

But actually there is just e.g. a multichannel oscilloscope in the background. Who ran also into this?

 

Quiztus2_0-1721292354992.png

 

Actor Framework
0 Kudos
Message 1 of 13
(565 Views)

I don't think you can do that without any by reference (or global) resource.

 

The simplest would be to make a multi channel device and make it put it's data in a global (functional global, queue (named, bleh), etc.). 

 

Better would be to make a multi channel device, and give it a method to get a reference to the data (e.g. queue (not a named one!), DVR). Fake single channel devices then need to get a hold on this reference, e.g. with a set method. This depends on how you instantiate your devices...

 

If instantiation is done with strings, it would be hard to avoid some named global. It can be done though. For instance, all devices could have a 'publish' method, that's always called. The published resources are collected in a map[name vs resource]. All devices also (optionally) implement a subscribe method, that can get a reference to shared data (any kind, better put it in a class so you can change and\or extend) by name.

 

Of course you might have to somehow make the first single channel device 'spawn' a multi device... Or at least make sure it's there.

Message 2 of 13
(529 Views)

What I figured out during my last major overhaul of my HAL is that I need 2 types of classes: device and instrument.  The way I defined them is the device is the full equipment (ex DMM, power supply mainframe) and the instrument is a measurement part of the device (ex a channel on the DMM, a power supply module).  I have my HAL call into the instrument (I use a map lookup so I can name my instruments).  The instrument has a DVR to the device to handle the communications.

 

This is kind of a mess at the middle layer, but it makes things quite easy at the application and instrument driver layers.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 3 of 13
(514 Views)

I added my physical device object as private data to a GOOP4 DVR class. I haven't tested it, but this should give me a proper physical device ref.

 

Then I created 'Virtual Instruments', which hold a name, a channel and a ref to the initialized physical device.

From there on I could treat the Virtual Instruments, as they would be physicals, BUT I am aware that some physical devices are not able to
check their running status. So I can't avoid starting, stopping ... the physical device more than once.

So then I thought about having some kind of 'Instrument Manager' , which would handle Start/Stop/Destroy by having a Mapping between virtual and physical devices.

 

Maybe a Factory Pattern could produce something generic for initialization, but so far this is nuts.

Quiztus2_0-1721334519196.png

 

Actor Framework
0 Kudos
Message 4 of 13
(489 Views)

@Quiztus2 wrote:

Maybe a Factory Pattern could produce something generic for initialization, but so far this is nuts.

 


And hence a universal HAL is complex and always involves some tradeoffs.

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 5 of 13
(471 Views)

@santo_13 wrote:

@Quiztus2 wrote:

Maybe a Factory Pattern could produce something generic for initialization, but so far this is nuts.

 


And hence a universal HAL is complex and always involves some tradeoffs.


The tradeoff is your sanity 😂.

 

Iff a universal HAL was feasible, there would be at least one already. 🦄

 

Even if there is one, it will be so complex people won't understand, use or like it...

 

Make a HAL that fits your needs, or maybe a tiny bit more (anticipating the future). That is hard enough...

Message 6 of 13
(455 Views)

@Quiztus2 wrote:

Maybe a Factory Pattern could produce something generic for initialization, but so far this is nuts.


Welcome to the fun that is creating a HAL.  All you are doing is moving complication around.  You make the HAL itself complex in the hopes of simplifying the interfaces between the application and the instrument.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 13
(451 Views)

You could do something like have the "multi-channel" device create two instances that each act like an independent channel

avogadro5_0-1721433863691.png

But under the hood share a common resource (possibly with something like a DVR to prevent concurrent access). This would let you preserve substantial parts of code designed for single channels. For closing refs, you could use ref counting within whatever shared data (I know I made 2 channels with names 0 and 1, I should only close the HW ref when both have closed).

 

Message 8 of 13
(409 Views)

I like the ref counting

Actor Framework
0 Kudos
Message 9 of 13
(396 Views)

For the sake of completeness. This is what I came finally up with. I added a class which manages the physical instruments and a mapping between targets(sensors or actuators).

Quiztus2_0-1721673242636.png

uml.PNG

 

Actor Framework
0 Kudos
Message 10 of 13
(365 Views)