LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I make the temperature data from a USB-TC01 a global variable?

Solved!
Go to solution

Hello all!  I have a (probably) simple question.  I bought the USB-TC01 and with the software came a VI called LabVIEWTempLogger.  This VI reads the voltage from a thermocouple and does internal conversions using DAQmx and an on-board CJC to give a simple temperature reading.  My problem is I want to use this temperature in another VI, so I want to make a global variable out of the temperature reading from LabVIEWTempLogger.  How do I define a global variable as the temperature from LabVIEWTempLogger?  Thanks!

0 Kudos
Message 1 of 11
(4,871 Views)

You can do an number of different things. You haved the source code (diagram and front panel) of the temperature measuring vi? There is in LabVIEW, since around v8.2 I think, a construct called the "Shared Variable" which is sort of a global on steriods. Or, if you wanted everything in one overall program you could have the temperature vi called by a higher level program and pass the temp values, either by a shared variable, a gobal, a queue (see producer/consumer architecture), among many different methods. Generally, globals are frowned upon, as they are easily misused, and if you are trying to run your temperature program and your "other" program, sharing a global is probably not the optimal method.

Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



0 Kudos
Message 2 of 11
(4,858 Views)

I do have the source code for the temperature VI.  And just to clarify, I want to use the temperature from the temperature VI included with the USB-TC01 to in a temperature controller VI that I will use to control a GWInstek PST-3202 DC power source.  I do not know how to "call" the temperature VI using a shared variable, global variable, etc.  My confusion is how do I tell the VI that controls the DC power source that a (global or shared) variable has a certain value?  How do I actually set the variable to the temperature from the temperature VI?  I am confused because I think I need to tell my VI that controls the DC power source which channel the USB-TC01 is coming from, but in the temperature VI the code does not need a channel (for example if you use an RS-232 connection, you have to tell the program which COM port it's attached to).  I think this is because it is using DAQ Assistant?

0 Kudos
Message 3 of 11
(4,830 Views)
You are making this far too complicated. I would suggest you spend some time taking the free tutorials first. Then you will know how to create a subVI that returns a value and how to pass that value to another subVI (or any part of your main program) with an ordinary wire. Forget about all of this global/shared variable nonsense.
0 Kudos
Message 4 of 11
(4,822 Views)

I can't use the subVI option because I'll need the temp variable in multiple places in the temperature controller VI.  I really think it would be best to use a global variable, I just don't know how to define the global variable as the temperature generated from the USB-TC01 VI and I can't find any resources online that state how to do it clearly.

0 Kudos
Message 5 of 11
(4,797 Views)
I disagree that a global would be best. Every place you need the temp, call the VI that reads it.

A global is on your structures palette. Basic. Described in the help. Since you don't know how simple it is to create one, you are almost certain to abuse a global. It would be much simpler if you should just attach your code.
0 Kudos
Message 6 of 11
(4,792 Views)

If you can call a subVI multiple times in a single VI, that would be the best option.  I have read the introduction on globals but I still don't know how to define a particular variable in a VI as the global variable, just how to put independent variables on the "front panel" of a new global variable.  My temperature controller VI (GWInstek PST-3202 power supply.vi) is attached as well as the VI I want to take the temperature from (LabVIEWTempLogger.vi).  Please let me know if using a subVI would work in my case, or if I need globals.  But either way, a description of how to set a particular variable in a VI as a global would be beneficial for me, even if it happens that I won't be using a global.  The variable shows up in three places in the temperature controller VI, and I have written notes next to them.

Download All
0 Kudos
Message 7 of 11
(4,783 Views)
Unless someone beats me to it, I'll look at the code when I have access to a pc later.

To answer to one of your questions, you can call a subVI as many times as you want.
0 Kudos
Message 8 of 11
(4,779 Views)
Solution
Accepted by topic author airic001

You need to pull out of the temp logger VI the DAQ Assistant. Put it in a subVI if you wish.

 

Your main VI has some problems. The first is doing an equal comparison on the current temperature. Never do an equal comparison on a floating point number. Use In Range and Coerce.

 

The local 'Set Temp deg C' should be replaced with a wire from the terminal. All locals should be replaced with a wire. You can easily have the terminals wired from outside the main loop.

 

I don't see the difference in code in the True and False states where you are reading the voltage.

 

Do not use VISA Bytes at Serial Port. It's just bad style. You have it programmed for a LF terminal character so get rid of the fixed wait and set the number of bytes to read to some high number. The read will wait until the termination character is detected and then automatically terminate.

 

Lastly, you've already created a global so I don't understand your questions about it.

0 Kudos
Message 9 of 11
(4,770 Views)

Oh thank you!  This post is extremely helpful.  I have a few questions and clarifications, however.

 

1) I worry that using In Range and Coerce won't be the best function in this case, because I'm trying to get the temperature of my oven to stabilize around a certain set temperature as closely as possible.  I suppose I could use a very small range of temps, however.  Why is it a bad idea to do an equal comparison on a floating point number?

 

2) When you say "The local 'Set Temp deg C' should be replaced with a wire from the terminal", what terminal do you mean?  I want to be able to change the set temperature of my oven depending on the thermodynamic quantity I'm looking for with different molecules (chemistry grad student).  Therefore, shouldn't I have a variable that sets the temperature I want at the time?  I don't understand what you mean there.

 

3) The difference in code in the true and false states is just + or -, meaning if the set temp is larger than what the thermocouple is reading, I want to make the voltage on my oven to increase and if the set temp is smaller than the thermocouple reading, I want to decrease the voltage.

 

4) When you say in order to replace VISA Bytes at Serial Port I need to get rid of the fixed wait, you mean the timer inside the while loop, correct?  As I'm sure you can tell, I'm not a programmer and I'm teaching myself LabVIEW through the book, tutorials, and forums so I'm not 100% on all of the programming lingo yet.  If I remove VISA Bytes at Serial Port, what function do I need to use to set the number of bytes?  And I'm guessing whatever function it is, I would just replace VISA Bytes at Serial Port with this function?

 

5) Those globals were from a thermometer program my professor wrote for an Omegaette thermometer we determined later I could not use in my experiment, so I was trying to figure out how to replace them with the subVI for the USB-TC01.

 

I have attached the new VIs in which I have changed:

(For LabVIEWTempLogger_new.vi): I made a subVI for the DAQ Assistant and made a connector on the TempLogger VI for physical channel input as well as made an output for the current temperature reading.

(ForGWInstek PST-3202 power supply_new.vi): I exchanged all the old global variables for the subVI as instructed.

Download All
0 Kudos
Message 10 of 11
(4,756 Views)