LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

input data from two different ports

Hello!

 

I am fairly new to LabVIEW so forgive me if this is a rather basic question. I am trying to write a VI that will obtain input from two different ports on the usb. I have attached what I currently have below.

 

I have six independant scenarios controlled by 12 switches. The first set of six switches start the timing and the second set of six stop the timing. My current VI only accounts for the second set of switches. I am not sure how to input data from the first set of switches??

 

I also had a question about the timestamp options. I just need the time difference between starting the timer by hitting the first switch and stoping the timer by hitting the second switch. What timer option should I use to obtain this result?

 

Maybe it would be easier to just see an example of one switch from port 1 starting the timer and one switch from port 2 stoping the timer and I could then replicate that for all six switched since they are all independant...

 

Thanks so much for you help! I again apologize for my simple questions!

0 Kudos
Message 1 of 11
(3,101 Views)

Here is a better version of your VI where the boolean logic was simplified, and redundant code was eliminated.

 

I'm not clear on what you want with your first set of switches vs. the second set.  It is probably a matter of using similar logic as here to detect the time of the first set of switches, storing them in a shift register, and subtracting those values from the times you are getting for your second set of switches.

Message Edited by Ravens Fan on 06-04-2010 03:51 PM
0 Kudos
Message 2 of 11
(3,088 Views)

Sorry to start a new thread, I just didn't want to keep bothering the same person with my very simple questions.

 

Thanks for you help! I have successfully written a VI that obtains all the data I want. I now have questions about writing to a spreadsheet.

 

I have attached my updated VI. I am now struggling with how to write the difference between the two times to a spreadsheet. I have tried to put the start and stop switches as the input of a subtraction node but am not sure where to hook up the inputs...?

 

Thanks for all you help!

0 Kudos
Message 3 of 11
(3,031 Views)

You can wire the timestamps directly to the subtract to get the difference.  It isn't clear to me which timestamps you want to subtract.  Please explain better.

 

TimeSubtract.png

- tbob

Inventor of the WORM Global
0 Kudos
Message 4 of 11
(3,021 Views)

Thanks!

 

I had sucess taking the time difference that I was looking for, now I'm struggling to get it to correctly write to a spreadsheet. I've attached my updated VI which supposedly takes the time difference but when I open up the Excel file, I can only view six zeros...

 

Is there anything wrong with the logic of my VI or it it an error of the number being in the correct form inorder to be correctly view in Excel?

 

Also, would there be a way to add a display to my current VI inorder to check that the time difference is being calculated correctly?

 

I truly appreciate your help!

0 Kudos
Message 5 of 11
(3,005 Views)

One of the problems with Write to Spreadsheet file is that you are essentially losing data by the conversion of a number (double precision) to text characters.  I'm not sure why you'd be getting 6 decimal places.  There is an optional input at Write to Spreadsheet file that determines the format the text gets written out.  When left unwired, it uses the default of %.3f which means 3 decimal places.  You can change that format string to something else %.6f for 6 decimals, %.9f for 9 decimals, to preserve more of the data in the text file.  Beyond that, it is all the way Excel imports and displays it.  If you don't see enough decimal places, try widening the column.

 

EDIT:  I just realized the 6 zeroes you are talking about might be a zero for each element in your array as opposed to 6 decimal places.  Either way, try changing the format for the Write to Spreadsheet file.

 

If you still have problems, post the .txt file you get.  Also, post a copy of your VI after you run it where you have hit "Save Current Values as default", then save and attach.   That way we can see what the data looks like from inside of LabVIEW.

Message Edited by Ravens Fan on 06-08-2010 04:52 PM
0 Kudos
Message 6 of 11
(2,998 Views)

The two times you are subtracting are basically the same time, hence you will get zero, or very close to it.  Look at your block diagram.  You have two Get Date/Time in Seconds functions inside a loop with no dependency between the two.  They are running in parallel.  So they both are getting the same exact time (maybe a few microseconds apart).  So when you subtract, you will get zero.

 

I think you need to change how you are getting the timestamp.  They should not be in parallel.  There should be some type of case statement so that when one button is pressed, the time is recorded. Same for the other button.  Then the times will be different and the subtraction will be non-zero.  Perhaps you should move the time function inside each case structure which is inside the For loop.

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 7 of 11
(2,992 Views)

Check the boolean logic.  The logic for the turning on of the start switch doesn't match the logic for the turning on the of the stop switch.

 

Also, up until now, all the start data vs. stop data has been essentially stored in the indicators.  But you are doing your subtraction based on the outputs of the For Loops as they exist in the very last iteration of the outer while loop.  Look at the data flow, they are all based on the current time no matter what you happened to have stored in your indicators.

 

You will either need to do the subtraction based on the values in the indicators, or redo the logic so that you actually have an array of timestamps for start and an array for stop that you store in shift registers on the while loop (and inner For loops).

0 Kudos
Message 8 of 11
(2,979 Views)

Thanks for all your help!

 

I have tried the many suggestions with little luck.

 

I think the easiest way to correct my issue would be to simply hook up the subtraction node to read from the indicators...How would I do that?? All 12 numbers that I want can be seen on the front panel, and all I want to do is subtract those numbers and write the results to a spreadsheet.

 

I have attached the txt file which results in all zeroes as well as the VI which I tried to save its current setting as defaults but I don't know if it worked...?

Download All
0 Kudos
Message 9 of 11
(2,953 Views)

See attached.

 

 

0 Kudos
Message 10 of 11
(2,945 Views)