LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Labview to Excel

Hello,

 

I have made a VI that when a button is pressed, a serial command is sent out via COM PORT 3. The VI then awaits serial information back via COM PORT 3.

 

The VI is communicating with a PICAXE 08M. I've got the VI acceptiong a string, then using "Decimal String To Number" I then manipulate the desired number contained in that string.

 

Firstly, I would like to like to make the whole process loop x amount of times. I would I like to use a for loop but not sure how.

 

Secondly, everytime a string is recieved, I would like to take the desired number and export it to a desired excel spreed sheet for further anaylise.

 

Another way to look at what my VI is doing, is that everytime I press a button, I take a sample.

 

My goal is to take multiple samples at one press of the button and store the values into a spread sheet.

 

Can anyone help?

 

Below is my VI.

 

Note: the PICAXE does not support duplex communication, hence the READ/WRITE buttons reset.

0 Kudos
Message 1 of 6
(3,621 Views)

That is a very awkward program.  I would recommend that you look at the Basic Serial Read and Write Example in the Example Finder.  Although in reality, you shouldn't need the read and write switches that it has.

 

A normal serial program sets the serial port parameters before a while loop.  Closes the port after the while loop.  In the while loop, it will write a command, wait some period of time, then read from the serial port.

 

Once you have that, you can put the write and reads in a case structure tied to a single button that you click to take a reading.  For multiple writes and reads, you can wrap them in a For loop with the N index wired up.

 

Do you want to write to a real .xls Excel spreadsheet, or to a .txt or .csv file that excel can open and import?  The latter is easier as there is a Write to Spreadsheet File function in the File I/O palette.  To communicate directly with an Excel spreadsheet, you will have to use ActiveX commands.  There are numerous threads to search for discussing this topic.

 

You may want to use a producer/consumer architecture (search forums and look under File/New .... for a template) to pass data from your serial communications loop, to a file I/O loop.

0 Kudos
Message 2 of 6
(3,610 Views)

Hello,

 

Ok, so I've simplified the program as best I can and put it inside a FOR LOOP. It will Send and Recieve data as many times as I specify in the control box. 

 

So I think the best option would be to to store the data in an array. When x amout of samples are taken, then output the files to a spreadsheet.

 

It would be nice if i could output to excel, but if it is easier to output to txt then so be it.

 

Any suggestions.

 

If my program is still "awkward" please let me know so that I may adjust it.

 

Cheers

 

K

0 Kudos
Message 3 of 6
(3,595 Views)

This would be closer to what you would want.  Of course I have no way of testing it out.  And without knowing what the strings look like when you read it in, I don't know if the text file would look right.

 

0 Kudos
Message 4 of 6
(3,593 Views)

Hey there,

 

As far as I am aware, you have toconfigure the VISA with read and write options specific to your needs.

 

Then when you read/write something at the same time, you need to store the incoming data in a buffer because the information that is inbound in not instantaneous. I'm only speaking from experiance.

 

Your example goes straight from Write to Read with no Buffer.

 

I've taken the "string to spreadsheet" block from your example and incorperated it into my code and it works.

 

Thank you for your help.

0 Kudos
Message 5 of 6
(3,584 Views)

Kamilan wrote:

Hey there,

 

As far as I am aware, you have toconfigure the VISA with read and write options specific to your needs.

 

Then when you read/write something at the same time, you need to store the incoming data in a buffer because the information that is inbound in not instantaneous. I'm only speaking from experience.

 

You are writing, then reading.  Yes the inbound data is not instantaneous.  The serial port has a buffer to accumulate the incoming bytes.  The code will not progress past the VISA read until either 100 bytes have accumulated in the buffer, or the timeout value has been reached.  (Or the termination character has been read, but that is not enabled in your case.) 

 

Your example goes straight from Write to Read with no Buffer.

 

I've taken the "string to spreadsheet" block from your example and incorporated it into my code and it works.

 

Thank you for your help.


 

0 Kudos
Message 6 of 6
(3,496 Views)