LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read from Excel File and Write to Digital Port

Hi, I recently designed a program (attached below as "New Write.vi") that does the following:

Asks a user for their input on m rows and n columns, and proceeds to build a m x n array that is filled with numeric controls.

The numeric controls in the array have a data range of 0 to 2. When the user hits the "save" button, the values in the array are written to an Excel file, and the array is reinitialized to its default values. The user can then proceed to input more values, and then hit the "save" button again to append the data in the array to the same Excel file.

Afterwards, the user will open up the other program (attached below as "Read test.vi"). When the user presses the "Open" button, she can select the file (i.e. the one that the write VI creates). Somehow, when the "Run" button is pressed, it should write to the DAQPad (I am currently using the USB 6507 with LabVIEW 7.1).

Here is the difficult part that I am not sure whether or not is possible. Depending on the value in each "cell" of the array, (0, 1 or 2), it will do one of the following:

0 - Lines 1 AND 2 are turned off.
1 - Lines 1 is off, but line 2 is on
2 - Line 1 is on, but line 2 is off.

Essentially, I am trying to recreate a tristate mode using two lines (the actual tristate mode will be controlled via a relay circuit board). The problem I am encountering is somehow interfacing the array to the lines.

i.e. If I create a 2 x 2 array, the first cell will control the first 2 lines, the second cell will control the following 2 lines, and so forth.

Any help will be greatly appreciated.  
Anthony Wong
University of Toronto
Chemistry Department
Download All
0 Kudos
Message 1 of 23
(3,026 Views)
Hello Anthony,
 
I want to make sure that I understand what you want to do correctly. Let's say you have a 2x2 array that looks like this:
 
0   0
2   1
 
I infer from your post that you would want the lines to look like this:
 
Line 0: low
Line 1: low
Line 2: low
Line 3: low
Line 4: high
Line 5: low
Line 6: low
Line 7: high
 
I may have misinterpreted what you wanted, but if this is correct the VI I attached below should do the trick.
 
Hope this helps!
Charlie S.

Visit ni.com/gettingstarted for step-by-step help in setting up your system
0 Kudos
Message 2 of 23
(2,987 Views)
Hi

The VI you uploaded is a good start for what I had in mind, as it encompasses the general principle of what I want the VI to do.

However, when I use the "Read from Spreadsheet" VI and read a .xls file that has the following pattern

1  1
1  1

The LEDs do not turn on at all.

Also, the final output should not be writing to LEDs, but to the actual lines of my DAQPad-6507 (USB).

So if the pattern is:

0   0
2   1
 
The actual lines on the DAQPad should be as follows:
 
Line 0: low
Line 1: low
Line 2: low
Line 3: low
Line 4: high
Line 5: low
Line 6: low
Line 7: high

In adddition to this, it should be possible to expand this to more than a 2 x 2 matrix. Let's say I have a 3 x 3 matrix

0 0 0
2 1 0

The lines on the DAQPad should look as follows:

Line 0: low
Line 1: low
Line 2: low
Line 3: low
Line 4: low
Line 5: low
Line 6: high
Line 7: low


Then I suppose we'd need to configure a second port that has the following:


Line 0: low
Line 1: high
Line 2: low
Line 3: low
Line 4: low

That would take care of the 3 x 3 matrix.  

Please let me know if this is possible, I appreciate your time
Anthony Wong
University of Toronto
Chemistry Department
0 Kudos
Message 3 of 23
(2,980 Views)
I forgot to mention that in my previous post that the line outputs will have to be somehow configured to turn off by themselves, after a specified amount of time.

Attached is a sample of the format of the files that I will be importing from Excel into LabVIEW 7.1

I'll try to explain what the values represent to the best of my abilities

500
0   0
0   1

500
0   0
0   2

The first group of numbers:
500 = the time to keep the line outputs on for. In this case, of the last two lines (line 6 and 7), line 6 is on for 500 ms.

The second group of numbers:
The 2 now indicates that of the last two lines, line 7 is on (line 6 has now been turned off). The line remains on for an additional 500 ms before turning off.   
Anthony Wong
University of Toronto
Chemistry Department
0 Kudos
Message 4 of 23
(2,966 Views)
Hello Anthony,
 
I think we're trying to tackle too many questions here at once. I put the LED's in the VI only as an example of where you could place your DAQ code, once you're ready to interface with some actual hardware. If you need help with that, I recommend you start a thread on the DAQ message board. To answer your other, software-oriented questions:
 
1. What happens (exactly) when you try to read from the .xls file? The "Read from Spreadsheet" is intended to read from a text file (not the native Excel format). You can try saving your excel files as *.csv or *.txt -- you should be able to read that easily in LabVIEW
 
2. As for the 3x3 matrix, you should be able to do that with the code I orginally attached. You can resize the array on the front panel to contain as large an array as you want. Depending on how you decide to program the DAQ portion of your code, you made need to split the resulting 1D array of booleans into "chunks" of 8bits each.
 
3. Finally, to incorporate the timing into your code, you should be able to read the array from the file "line-by-line." That is, if you know that every entry will be an nxn matrix preceeded by a time, you could read the time off, then parse out the array subset corresponding to your data. Using the time that you read, you can time a for or while loop to output your data. This would be software timing, but at 500ms it shouldn't make a big difference. I have attached an example that should demonstrate all of this.
 
Hope that helps -- good luck!
Charlie S.

Visit ni.com/gettingstarted for step-by-step help in setting up your system
0 Kudos
Message 5 of 23
(2,957 Views)
Hi Charlie S.,

I have managed to write a bit more of code and have modified your original program and it is now capable of communicating with the first 8 lines of the DAQPad.

Below are some answers to your above message:

1) When I read from the Excel file, LabVIEW opens, and interprets the data correctly, and is able to read from it. There is no problem whatsoever (I believe the files are being saved as a text file in tab delimited form, and I am merely using Excel to open them).

2) In essence, the matrix should not be limited to an n x n matrix; it should be n x m (i.e. 2 x 6, or 8 x 1, etc). This is not a problem, as you said that I can simply resize the array on the front panel. You said:

"Depending on how you decide to program the DAQ portion of your code, you made need to split the resulting 1D array of booleans into "chunks" of 8bits each."

I am unsure by what you mean, and am not too familiar with how to proceed at this point.

3) I've taken a look at your program, and I will attempt to work this into my own program as well. Will this work for any irregular matrix size as well (n x m)?

Thanks for your help  
Anthony Wong
University of Toronto
Chemistry Department
0 Kudos
Message 6 of 23
(2,939 Views)
I suppose it doesn't help if I don't attach the VI below...

Also, I noticed something unusual, when my data appears as follows (ignoring time, assume it has been parsed out)

1   0
0   0


Line 0 of both the first and second port are on (I only want line 0 of the first port to be on). This is so that when the data looks as follows (say the matrix is now 2 x 4)

1  0  0  0
2  0  0  0

What would occur is that line 0 of the first port would be on, while line 1 of the second port is also on (in this case, assume 1 0 0 0 control 8 lines, and 2 0 0 0 control another 8 lines on another port).


Anthony Wong
University of Toronto
Chemistry Department
0 Kudos
Message 7 of 23
(2,935 Views)
Hi Charlie,

I have managed to update my program even further in these few short hours that I have worked on it, and it is nearing what I wish to have.

Attached is the file below...

There is one problem that is quite bothersome, however. If my matrix exceeds 4 "cells" (i.e. say a 4 x 2), it still will not communicate with the rest of the lines on the DAQPad. As I outlined above, if the pattern appears as follows:

500
1  0
0  0

Line 0 of both the first and second port are on (I only want line 0 of the first port to be on).

If this problem, as well as the problem of being able to recognize what to do when the matrix exceeds 4 cells, then it would be a great deal of help.

Thanks for your time  
Anthony Wong
University of Toronto
Chemistry Department
0 Kudos
Message 8 of 23
(2,931 Views)
Hi Anthony,
 
Sorry for the somewhat-delayed response -- I've been away from my desk all day. I'm happy to help out! Could you post your code, so that I can take a look at what's going on?
 
Thanks!
Charlie S.

Visit ni.com/gettingstarted for step-by-step help in setting up your system
0 Kudos
Message 9 of 23
(2,920 Views)
Hi Charlie,

Sorry, I thought I attached the file in my previous post, but I forgot to attach the file.

Here it is below.

Thanks for your help  
Anthony Wong
University of Toronto
Chemistry Department
0 Kudos
Message 10 of 23
(2,915 Views)