09-23-2013 01:11 PM
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!
Solved! Go to Solution.
09-23-2013 02:09 PM
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.
09-24-2013 10:24 AM
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?
09-24-2013 12:34 PM
09-25-2013 09:19 AM
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.
09-25-2013 10:04 AM
09-25-2013 12:05 PM
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.
09-25-2013 12:12 PM
09-25-2013 01:18 PM
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.
09-25-2013 02:23 PM
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.