09-30-2019 10:14 AM
Hello,
I am trying to streamline an application developed by my predecessor. I have generated a .vi that upon clicking a mechanical switch, will search a directory for an excel file, open it if it exists, create it if it doesn't using a pre-written excel template, and begin plotting data into a specific worksheet depending on the value of a combo box on the front panel. I would like the program to save, and close the excel file when deselecting the "record permeation data" button. My issue is that if I insert the "Save Report to File" and "Dispose Report" nodes into my case structure hierarchy, the program saves the file and closes it on every iteration of the while loop. I have been unable to find a way to move these nodes outside the while loop while still managing to write data to the excel file.
I have attached a .vi with the serial inputs replaced with a generic sine function so that I can work on this remotely. I have also attached the Excel template I am writing the data to. Hopefully I haven't left out any critical information.
Disclosure: I am very new to LabView, and my code is probably the least elegant you've ever seen. I'm also a Chemist by training so this is my first foray into any sort of programming. Please forgive my ignorance.
Thank you!
09-30-2019 11:36 AM
There are two options. If you will always write data at some point then just open the Excel file before the loop and save it after the loop. If you prefer to run the program with or without writing the data, then you should create a simple state machine inside the loop. When the button is pushed then combine the copy template with the file open, selected worksheet and find starting cell functions. The next state will append the data. When the button is turned off then write the file and close Excel.
Issues with your code:
1. Get last row in Excel will not work correctly if there are other cells used in the sheet
2. Your waveform calculates the dt value incorrectly. This value should be consistent.
09-30-2019 09:23 PM
I recommend you write a one-page document describing what you want to do. In the case of this particular Report-from-a-Template, describe what you expect (in broad strokes) a typical Data Run to look like.
It looks (to me) like this may be an interesting two-pass process, involving both LabVIEW and Excel in creative ways. I'm guessing that your Document will say something like this:
We've now broken a Big Complicated Problem into a sequence of four simpler Steps, each of which is either a sub-VI (which you string in a simple sequence) or a "State" of a State Machine model.
You should be able to do all of these things in a fairly straight-forward manner with the Report Generation Toolkit. There are some interesting examples out there (including one I especially like, right here in the Forums, search for Revised Example.
Bob Schor
09-30-2019 10:18 PM
Thanks for the thoughtful reply, Bob!
I work on gas separation membranes and our lab utilizes some rather "homegrown" instrumentation. A lot of work has been done building and validating the instruments, but our data acquisition is not as streamlined as I would like to see. My predecessors essentially adopted a hand-me-down LabVIEW program from another lab, modified the VISA serial resources to fit our instruments and called it a day.
To answer your questions:
To outline a given run:
The old process and subsequent data work-up involved generating a spreadsheet for each individual gas (often 5 gasses for a single membrane), generating a scatter plot of downstream pressure vs. time, fitting a regression curve to the data, changing the equation to scientific notation w/ 5 sig figs, directly copying the slope from the graph equation and pasting that into a master spreadsheet. I work with guys who worked the data up this way their entire graduate school careers, and I am just trying to make my life a bit easier.
Based on an earlier suggestion, I have started looking into building a state machine. It seems like it will work much better than my original code, but I am finding it difficult to get right. Limited programming experience makes this process more difficult than it should be. Hopefully I can get it figured out!
Thanks again for your reply!