From Saturday, Nov 23rd 7:00 PM CST - Sunday, Nov 24th 7:45 AM CST, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Saturday, Nov 23rd 7:00 PM CST - Sunday, Nov 24th 7:45 AM CST, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
10-12-2021 11:04 AM
I have a question one how to store data in an excel file each time a program reaches a certain point within a stacked sequence structure.
I’m still learning how to use labview, but a brief overview of my project is I'm using labview to create an application that cycles through 24 input voltages. The program is a temperature monitoring system. The input consists of 4 multiplexers that are all attached to a binary coded decimal ‘counter’ that cycles through each of the inputs, these are then fed to a second multiplexer which specifies which of the 4 input multiplexers the program is sampling from. If input select 1 is 000 and select 2 is also 000, then the program is reading inputs from the first input of the first multiplexer. If select line 1 is 001 and select line 2 is 001, then the program is reading from input #2 of mux #2 etc.
My current program consists of using the DAQassistant to configure the pinout of the NI USB device to sequentially read from each of the inputs, and saves them to a global variable. The program is mainly using the stacked sequence structure to control the program flow. Each input from the DAQassistant is sampling at 1000Hz for each cooling line. What I am currently doing is converting the dynamic data type to an array and averaging the value of the array to get a single value for each sample. This single value is then assigned to a global variable of type string that corresponds to each channel i.e. Channel 1 Channel 2 etc.
My question is: once I have all the values assigned to each global variable I would like to do 2 things:
All the files are attached. If you jump ahead to frame #4 on the outer stacked sequence, you will see where I am trying to log the data, which I know (currently) is incorrect.
Any help is appreciated.
Thanks
10-12-2021 11:24 AM
I haven't even looked at your code but I can offer you the following advice:
within a stacked sequence structure (bad) -->> State Machine (good)
using the DAQassistant -->> Learn 10 Functions in NI-DAQmx and Handle 80 Percent of Your Data Acquisition Applications
saves them to a global variable -->> Use shift registers
Please go back and review some of the concepts in "Learn LabVIEW Basics" link at the beginning of the forum.
Now to answer your questions:
To continuously log data, you do the following:
Open file
while looping
write data to file
end loop
close file
"Check to see if the readings are within a permissible temperature range" You can use the "in range" function, or use the comparison functions like, you know, greater-than and less-than.
Hope this helps.
10-12-2021 11:49 AM
I'm unfamiliar with the state machine structure, due to my limited experience with labview; but is there a reason why you don't want to use global variables to do this?
I tested it and was able to read/store values to each global variable from an external circuit with a changing input voltage (changing thermistor resistance). I chose the DAQ assistant because its easy to configure the pinout.
If I have 24 values which represent 24 samples, 1 for each line, all stored in global variables, couldn't I just bundle them into an array and write them to an excel sheet?
I know there is a more a efficient way of writing this program, but this is what I have at the moment and don't have time to start completely from scratch.
10-12-2021 11:56 AM - edited 10-12-2021 11:58 AM
On top of what Frozen said, don't get hung up on an "Excel" file... Yes LabVIEW can create an Excel file using the MS-Office toolkit, but most time you don't really need it and it adds a huge level of complexity for a beginner...
Honestly I have been doing this for a long time and I have not needed anything but a simple text file to store data. I have had long term tests that ran for YEARS recording over 100 measurements at one second intervals and still used a simple text file.
Excel has no problem opening a text file comma delimited (CSV) is probably the most common but Tab delimited is the old Excel default. On opening a text file the "File Importer" will pop up and lead you through selecting the delimiter and opens the file.
Back to Frozen's suggestions: You should listen to them.
10-12-2021 01:03 PM
Whatever you are doing has nothing to do with excel. All you are writing is a delimited text file. I am also not sure why append=TRUE when writing the column headers.
That said, I agree that this code is absolutely horrendous (counters in floating point representations, stacks and stacks and stacks of stacked sequences, 24 ordered scalar globals where a single array global would work equally well. Peppered with Rube Goldberg constructs everywhere. Properly written, the entire thing could fit on a postcard and contains no stacked sequences and Locals&Globals.
10-12-2021 01:20 PM
@PH196 wrote:
I know there is a more a efficient way of writing this program, but this is what I have at the moment and don't have time to start completely from scratch.
Do yourself a favor and take the few hours that it would take to at least learn some LabVIEW basics. You don't have time to waste on code that may never work because you don't know how to use the tool. You will finish this task much quicker by learning to do it the right way and starting from scratch.
I started looking at your code but got lost with what is even the top level - the one labelled main does not appear to be the main.
@PH196 wrote:
I'm unfamiliar with the state machine structure, due to my limited experience with labview; but is there a reason why you don't want to use global variables to do this?
In the right context global variables are not bad, but most people who have limited experience with LabVIEW run into problems using them, and most veteran LabVIEW users rarely use them. It is easy to abuse global variables and create race conditions (parallel parts of the code are accessing the global variable at unexpected times).
@PH196 wrote:
I tested it and was able to read/store values to each global variable from an external circuit with a changing input voltage (changing thermistor resistance). I chose the DAQ assistant because its easy to configure the pinout.
If I have 24 values which represent 24 samples, 1 for each line, all stored in global variables, couldn't I just bundle them into an array and write them to an excel sheet?
Why put them in global variables at all? The data are held in the wires - just use the wires to get the data where you need it. Of course to do that without making spaghetti you need to learn some LabVIEW. A state machine is a very simple design pattern - learn about it.
10-13-2021 10:55 AM
@altenbach wrote:
Whatever you are doing has nothing to do with excel. All you are writing is a delimited text file. I am also not sure why append=TRUE when writing the column headers.
That said, I agree that this code is absolutely horrendous (counters in floating point representations, stacks and stacks and stacks of stacked sequences,
To be fair, the code outline wasn't necessarily my idea, I just took a bad outline and likely made it worse.
This is for an undergrad EE project, and as previously stated there was no background training or guidance given on how to use labview hence: using stacked sequences to control program flow.
I think what would be most helpful would be to explain how this project can be simplified using the state machine design.
There are really three components to it:
-two BCD 'select' lines that are connected to USB6009 input ports, that cycle through each of 24 inputs.
-A portion of the code that checks each line to see if its within a certain temp range, and sends out an email alert if its not.
-A portion that logs the data into an excel sheet.
10-13-2021 11:03 AM
@PH196 wrote:
This is for an undergrad EE project, and as previously stated there was no background training or guidance given on how to use labview hence: using stacked sequences to control program flow.
I think what would be most helpful would be to explain how this project can be simplified using the state machine design.
There are really three components to it:
-two BCD 'select' lines that are connected to USB6009 input ports, that cycle through each of 24 inputs.
-A portion of the code that checks each line to see if its within a certain temp range, and sends out an email alert if its not.
-A portion that logs the data into an excel sheet.
You need to post ALL of your code. I can not find your top level VI
Updated Main. VI is not your main vi.
10-13-2021 11:16 AM
That is the main VI as of now. I'll reattach.
Once you configure the output port pins using the DAQassistant, and run it, it should log the data into that simple chart you see on the front panel, and then store the data in excel sheet 'book'. Red means the value is out of range, green means its in range.
10-13-2021 11:26 AM
Thanks, but after seeing this, I must withdraw.
That entire code needs to be scrapped and started from scratch as that would probably take far less time than trying to refactor your code.