LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

*How to step up while loop*

Hallo forum visitors,
I'm using while loop to realize communication thru RS232 with a remote device. Inside the while loop VISA write, VISA read and Write to spreadsheet are adopted. Although the Baud rate is set at 19200, in the final file I get 36 points per second. Why so slow? How could I step up the communication? I doubt that each iteration takes too much time, so how can I shorten the iterations?
Any advice is appreciated.

xianese
0 Kudos
Message 1 of 7
(3,341 Views)
Could you attach your program?
0 Kudos
Message 2 of 7
(3,335 Views)

Is there any unnecassary large time-delay (wait ms) primitive inside the while loop ?

Check for this. Post the code to shed more light on it.

- Partha ( CLD until Oct 2027 🙂 )
0 Kudos
Message 3 of 7
(3,310 Views)
Thank both of you for the immediate reply.

The attachment is the snapshot of part of the block diagram.

There is a wait in the loop, but it is actually set at 0. I thick it affects the loop not that much. Perhaps I should relocate the save to spreadsheet outside the loop. Could I use build array to store all the desired elements, then pass it out of the loop after all iteration? Is it a recommended way?

xianese
0 Kudos
Message 4 of 7
(3,299 Views)

The build array + writing to file using Write to Spreadsheet aren't very efficient to have inside a loop like that. Write to Spreadsheet file opens, writes, and closes the file every time it is used. It would be a better idea to create the array and write it to file outside the loop, or buffer the data and write it every once in a while if you are running this for an extended period of time.

If you know how long this will be run, I suggest initializing a 2D array before the loop with 3 columns and as many rows as necessary to hold your data. Then each time you read, use replace array subset to replace a row of the array. This will be more efficient.

If the program will run for an indeterminant amount of time, create the array to use as a buffer. Whenever it fills up, write the contents to the file and start over at the beginning. If you're going to do this, it will be even faster to open the file before the loop, write inside it, and close the file after it.

0 Kudos
Message 5 of 7
(3,292 Views)
Your data is U16, but the tick count is U32 so you have a coercion that causes an extra data copy in memory. If the relative time is relatively short, you coul convert the time stamp to U16 instead. Still these things are peanuts. Probably no big deal. 😉
 
Writing to a spreadsheet also involves formatting operations and constantly opens and closes the file at each iteration.
 
If you really want to speed up the file I/O you have to use low-level file functions. Open the file on the left outside the loop, then append your data with simple writes inside the loop while keeping the file open. Once the loop has finished, you would close the file on the right, again outside the loop.
 
Is the array always the same size?
 
(1) If you want to write to a ASCII table (spreadsheet), you would do the formatting manually using "array to spreadsheet string" and just append the string to the end of the file at each iteration.
(2) If you really want to go fast, write the data in binary.
 
Overall, the RS232 part is probably still the slowest issue ant there is not much you can do about it. .... 😉 However, it is always good to streamline the rest of the code and make it more efficient. Many times you have many other things running on the computer and is it always good to reduce memory and CPU use by a significant factor if it is as simple as described here. 
 
 
 
 
 
0 Kudos
Message 6 of 7
(3,274 Views)
Thank you again for your detailed analysis, and nice to see you again, altenbach.

Could you offer more examples on

low-level file functions
It would be thankful, if you could give me a rough layout of your suggestion:

Open the file on the left outside the loop, then append your data with simple writes inside the loop while keeping the file open. Once the loop has finished, you would close the file on the right, again outside the loop.
(1) If you want to write to a ASCII table (spreadsheet), you would do the formatting manually using "array to spreadsheet string" and just append the string to the end of the file at each iteration.


Is the array always the same size?

Yes, it is expected to always contain two data, one is time, and the other is what yields from VISA write in each iteration.

what's the term for the format of binary file in labview?

happy weekend
xianese


0 Kudos
Message 7 of 7
(3,244 Views)