LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Write data captured by GPIB into csv file in different columns

Solved!
Go to solution

Howdy all,

 

I am trying to write the data that I captured from a GPIB read function into a csv file but I ran into some problems. First picture shows the vi that I built for completing transferring data from a GPIB read vi into a csv file. It simply goes through a 'build array' vi then sends the array to 'write to spreadsheet' vi. The data captured by the GPIB read vi is shown in the second picture, which has three different parameters: NET+value, NEI+value, W(E)EV+value. I want to save the data but only the value numbers (without NET, NEI & W(E)EV), as three columns in the speadsheet. All value numbers starting with NET go to the first column, and numbers starting with NEI go to the second. The remaining numbers go to the third column. Finally I want to add a name for each column with Time, Current, Voltage. However, with the simple vi that I built, the data is written to just one row in a csv file as shown in the third picture. Could anyone tell me how to build additional VIs to realize the operation that I expect? (data format as shown in pic4) Thanks!

CSV_vi.PNG

           pic1.  Built VI

data_captures.PNG

        pic2. DATA captured

 

data_saved.PNG

        pic3. csv data format with current VI

expected.PNG

      pic4.  Expected format

 

 

 

0 Kudos
Message 1 of 12
(2,098 Views)

You set a tab delimiter for that subVI rather than a comma.

 

It would be easier if you didn't use that and just used Open File, Write to Text File, Close text file and when you send the line, end it with a carriage return or line feed since you data seems to have commas in it already.

 

Open the File before the loop, and also Write out your column headers separated by commas and ending it a carriage return.  In the loop, write the strings without converting it to an array.  Make sure to end it with a CR.  After the loop, close the file.

0 Kudos
Message 2 of 12
(2,073 Views)

Hi RavensFan,

 

Thanks for your reply but it seems that it cannot realize what I need or I understood you wrongly. The pictures below show the VI I built now and the data captured and saved. The data are still saved to one row instead of three columns with corresponding header as I expect. And the characters in the data (NET,NEI,WEV) are not removed. I tried regular match to extract numbers from the data captured by GPIB but I couldn't figure out. The data doesn't append to the same file and I didn't find where to turn it on. (in the 'writeToSpreadSheet' VI, it can be turn on/off by choosing T/F'. Could you please provide your VI as an example so I can understand more clearly with what VIs do I need to use and how to? Thank you very much!

vi.PNG

data.PNG

save.PNG

0 Kudos
Message 3 of 12
(2,031 Views)

The question is do you want to learn LabVIEW or is this just a one time solution you want.

 

You can remove those characters by using find and replace with replace being empty string constant

 

You also need a line feed in-between your header and data.

 

 Your data needs to be manipulated further as well to add line feeds after every 3 cells/commas in your data.  

 

See if that helps, if you can't get it to work then I/someone could send you the vi function

----------------------------------------------------
Studying for CLA.
LabVIEW, inherit from social media habits!
0 Kudos
Message 4 of 12
(2,028 Views)

It sure looks like you are getting multiple upon multiple values in a single read rather than one row at a time.  If that is what is happening, your original post really didn't indicate that.

 

What is sending this data?  Why isn't it programmed to send the 3 values separated by commas then ended by a CR?

 

With what you last wrote, I don't see the while loop in your VI.  It looks like a 1-shot VI.

I certainly didn't say to append the headers in the same string as the data you were receiving.  I said "Open the File before the loop, and also Write out your column headers separated by commas and ending it a carriage return."   You didn't put in the carriage return, you put another comma on the end.

 

And proceeded to put a string of data and a CR in the same string.  I said " In the loop, write the strings without converting it to an array. Make sure to end it with a CR".   But you don't have a loop.

0 Kudos
Message 5 of 12
(2,019 Views)

Hi CDuck,

 

Thanks! Find and replace VI is simple to use and now I removed all characters that I don't expect from the data string. However, I haven't figured out how to add a line feed to the data string after every 3 commas. Could you please provide an example for adding line feed to a string? 

 

Best 

Nathan

0 Kudos
Message 6 of 12
(1,998 Views)

Sorry for the confusion. I didn't explain the data format clearly in my original post. The GPIB reads the measurement data from the instrument and sends the data out in one string. The data is not being sent simultaneously while the measurement is performed. 

0 Kudos
Message 7 of 12
(1,996 Views)

Hi Nathanzzs

 

Fair enough, this one can be tricky.

 

I attached my solution, I will be interested to see other solutions if anyone wanted to try it

 

EDIT* I forgot to mention I used OpenG, please install the OpenG toolkit with VIPM!

----------------------------------------------------
Studying for CLA.
LabVIEW, inherit from social media habits!
0 Kudos
Message 8 of 12
(1,990 Views)

Hi CDuck,

 

Could you please screenshot your VIs? My LabView is 2012 which could not open the VI that you just sent. Thanks!

0 Kudos
Message 9 of 12
(1,982 Views)

I saved it for LV 2012, also I subbed out the OpenG subvi so you shouldn't need OpenG now.  Try this attachment.  I did get an error that said %s doesn't exist in LabVIEW 2012 so we will see if it works I guess

----------------------------------------------------
Studying for CLA.
LabVIEW, inherit from social media habits!
0 Kudos
Message 10 of 12
(1,977 Views)