LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Typdef - There must be a better way!

Years ago I made a great little LabVIEW code that uses a typdef to inject calibration and serial number information about my sensors into my save file. This didn't seem like the best way but it worked and I could live with the drawbacks.

 

Well, I can't anymore. Other people have to use the code and the number of sensors I have available has ballooned.

 

How it works: I have a little section of my script with 20 copies of the typdef in it.

 

skinnert_0-1718719058325.png

 

When I select the drop-down I have a format of "serial# (space) calibration" which I pull apart later when I put it into my TDMS file. Each sensor gets its own values in the file. It works great.

 

skinnert_1-1718719166498.png

 

The problem is that with the typdef I can put 20 of the same sensor in and the software doesn't care or notice. It will happily run and record this data... On the one hand, this is good because I'd rather collect the data and sort out the problem later. However, if there is a way to NOT have this problem that would also be great.

 

skinnert_2-1718719228545.png

 

Is there a better method to do this than typdef or a way to force the typdefs to recognize the values that are already taken? Honestly, loading in a database every time might be better if that's an option. I could keep it updated in a central location and it would likely be easier to work with than the typdef interface.

 

To be clear, I'm not saying typdefs are bad! They're great and useful tools, I think I'm just pushing it to do something that it isn't quite meant to do.

 

LabVIEW file and typdef are attached. I deleted anything that wasn't pertinent and only left in the typdef and TDMS portions.

 

Download All
0 Kudos
Message 1 of 6
(353 Views)

Did I understand it correct? The values of the serial number and it's calibration are hard coded in the typedef?

If that's how it works you could make a typedef for a array of a cluster containing the serial number and the calibration. Then feed those values into the ring with property nodes and if a certain one is selected you "remove" it from all the other ones by updating the array you're feeding the rings.

That's just a quick thought of mine, hth.

Message 2 of 6
(333 Views)

You could use the Disabled[] property of the control. Once you select a value on 1 control, you disable that option on all other controls. You'd need to implement some logic for this, but that seems the best option to me.

Message 3 of 6
(308 Views)

I'd dump the typedefs and load the sensors from a file.

 

The way I see it, you have two problems to solve that are unrelated.

 

1- You need a way to keep track of your sensor information (calibration values, etc)

2- You need a way to ensure that selecting a sensor one time means you can't select it again.

 

Trying to combine these will be frustrating, so just separate them out. For #1, I'd heartily recommend making a JSON file using the JSONText library to load your sensor data. It will be MUCH easier to keep up with than updating a typedef, it'll be super flexible, and it'll be readable by other programs (should you need to do so later).

 

For #2, I think I'd write some reusable code (perhaps a QControl if you're feeling like learning something new) that takes an array of references to all of your dropdown boxes (or, a single reference to an array of dropdown boxes). The dropdowns should be rings, not enums, since rings can change at runtime.

 

When you initialize your control, feed it an array of all possible sensor types. I'd recommend a Set for this. Each time you have a Value Change event, update another Set that includes everything that's been selected already. Now, when you have a MouseDown event, do a boolean difference between the set of "all sensors" and the set of "already used" sensors. Now, the only ones you can select will be the new sensor.

 

(Note: be sure to leave one option in the dropdown to "none" or similar. That way if someone selects a sensor and decides they don't want one there after all, they can clear the box.)

Message 4 of 6
(295 Views)

@skinnert wrote:

Is there a better method to do this than typdef or a way to force the typdefs to recognize the values that are already taken? Honestly, loading in a database every time might be better if that's an option. I could keep it updated in a central location and it would likely be easier to work with than the typdef interface.


A database or databases (a DB server (recommended), a DB file or even simple files) sound like a valid solution.

 

@skinnert wrote:

To be clear, I'm not saying typdefs are bad! They're great and useful tools, I think I'm just pushing it to do something that it isn't quite meant to do.


Yes, type defs are useful to define types.

 

You're using one to store data, which is OK if the data defines the type. This might have been the case when you started, but you've crossed the border. Your "type data" now became just "data", so you need a data solution.

 

0 Kudos
Message 5 of 6
(234 Views)

This worked surprisingly well.

Yamaeda_0-1718809600664.png

 

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 6 of 6
(204 Views)