LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Formatting String for Excel

I am very new to using Labview. I am using a Keithley2420 SourceMeter to communicate with Labview. I have the unit sucessfully communicating with Labview but now it's just an issue of formatting the data for Excel. I would like to have the data in decimal format so I tried to convert the string into a decimal string but my options only let me turn it into a number and not a string of numbers, maybe I selected it incorrectly. I also tried to take the data string from the read buffer from the Read VISA icon and put this into an array to spreadsheet and it says that I have unconnected wires, but I know I don't have an array to connect, I would have to create one, but I don't know if I am going about that the right way. It's a simple VI because I just need it to read from the buffer, and I just need the data in Excel. If anyone can help it would greatly appreciated. I have attached the base VI that I am using to manipulate. This VI will read the buffer and return values, just not in the format I would like. Thanks.
0 Kudos
Message 1 of 21
(7,453 Views)
Could you provide a sample output from your device, ie what it is you get from the buffer that you are trying to format.

Also, how often are you going to be reading the buffer??  I ask since the vi will only run once.

If you want to make an array, you could feed the string output of the Visa Read into a build array node (In the array palette) and then feed that into the Write To spreadsheet file.vi and that you create a tab delimited file that is easily read in excel.
Kenny

0 Kudos
Message 2 of 21
(7,442 Views)
I have attached a data log of my first run of gathering data. It all dumps into one cell in Excel. I don't know if this could also be a problem with Excel. I looked at the delimited text import but I don't have a carriage return I have commas only, so I think I still need to format the string to make it work properly.

The experiment and VI will not be run simulataneously, this is the reason for the one run in the VI programming. It will be used to gather data readings from the buffer after each run of the experiment.


0 Kudos
Message 3 of 21
(7,429 Views)
Sorry I forgot to mention that also, the way it is reading is:

### (Volts -V), ### (Amps - A), ### (Timestamp - T), repeat until done with buffer, using commas to separate. I believe the device is reading this as ASCII code, which is why I trying to convert it in the first place, to a usuable form before sending it into Excel.

This is what I want it to look like in Excel. I don't know if it's already there for the formating or not. I think the main problem I am running into is the carriage return stuff I think I need to separate the data into rows as well. I don't need the headers in Excel, I can format Excel once everything is in Excel, I just wanted to give you an idea.

Thanks
0 Kudos
Message 4 of 21
(7,425 Views)

Here is an example.  Basically what you are doing is taking the input, parse out the part before the comma (Volts), take the rest of the string and repeat the operation, which this time gets you the Amps, and then repeat again to ge the timestamp.  Keep looping through this until you get an empty string, ie there is nothing left to parse.

You can also use the Ext/Fract String to Number.vi (String conversion palette) to convert your string to a number, making sure that you have a double wired to the type input.

 

It is saved in LabVIEW version 8.2.

Kenny

0 Kudos
Message 5 of 21
(7,421 Views)
Thanks Kenny for the VI, I opened the code in 8.2 but do not understand all that is doing, also I have to translate the code into 7.1 because this is what my workstation has. I can see that it's taking my string, I am assuming the string I put into it from the read visa before it gets written to the file. I don't understand where it goes to an array, do I take this array of strings whether it be decimal or just the string and do I convert this outside the loop to an array to spreadsheet to file, then write it to my file. Also when I built the fraction to number tree that you put within the loop it the build array gets an error, saying the two wires have different dimensions and it won't let me connect them.

Of If I get this code to work in 7.1, can I just send that string into the write file icon? Sorry this is only my 4th day working with Labview. Thanks.
0 Kudos
Message 6 of 21
(7,410 Views)

There should no be any difference between 7.1 or 8.2 as far as the code goes, all the "building blocks" used have been around for a long time.

I attached a picture that has been commented some more. 

I would suggest looking at some of the Array examples that are included with LabVIEW. 

Basically, you are initializing a shift register to be a 2D array with either a string or a double, in this case (it can be initalized to almost anything you want)  Then you add the volts, amps and temp to the array.  THe shift register is what "remembers" what you entered into it from the last loop of the while loop.  When the while loop stops (an empty string is received) then the output of the shift regiester is sent to the Array Indicator (String Array and Decimal Array in this case).  What you can then do (not shown) is feed the decimal array into the Write to Spreadsheet file.vi and save to an excel readable file.

Let me know if you have more questions.



Message Edited by Kenny K on 12-21-2007 07:53 AM
Kenny

0 Kudos
Message 7 of 21
(7,374 Views)
I attempted to build the while loop in my 7.1 version of Labview and maybe I don't understand the loop structure very well but it doesn't seem to be working. I cannot get the build array function to work because it either only accepts elements or arrays, it allows me to change the inputs to be either concatenate or not and I am not sure what that means exactly but it tells me eitehr way I have a bad wire connection.

I'm getting frustrated to the point that I actually now just want to make this even simpler. I've decided to extract one type data, such as only Volts. I can make Excel do,  however, it puts all the data into columns, I plan on taking 2500 data points for each experiment and since Excel can only have so many columns, I cannot transpose all my data, I will lose a large percentage of it if I go about it this way. Is there a way to save the data file in my VI so that Excel will read it as rows already? If I can do this, this solves all my porblems right there.
0 Kudos
Message 8 of 21
(7,270 Views)
Sorry here's the latest version of my VI.
0 Kudos
Message 9 of 21
(7,269 Views)
There is quite an easy way to do this if you install the (free) openg libraries, and use the string to 1D array VI that is in the array sub pallette.

Essentially, the ASCII data string from the unit is converted (using a comma as the deliminator) to a 1D array, and then this is reshaped depending on how many elements are in each "row" of your data.

A picture is attached. The green VI in the beginning is the string to 1D array that I was talking about, in my case I have 5 columns of data per row.

ps: you can install the openg libraries a few ways, either by downloading directly from sourceforge, or if you use the nifty VI package manager it will do the hard work for you.

edit: I have attached another picture of the inside of the string to 1D array, so you dont have to install those!




Message Edited by nrp on 01-03-2008 11:04 PM
Download All
0 Kudos
Message 10 of 21
(7,266 Views)