LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Nesting for loop inside while - only executes once

Solved!
Go to solution

Hi, first of all, I'm a total LabView noob, so please forgive any stupid questions.

 

What i try to achieve is to pull 2-dimensional sensor data from a serial device as lines of integer sequences, i.e. when sending the command :MEASURE:RAW the device would return the following data:

12 45 12 56
85 12 9 98
87 14 78 10

The sensor data should fill an array which will subsequently be visualized somehow. 

 

As VISA Read terminates when it reads a newline character my naive approach was to execute it once for every line of sensor data in a for-loop. The for-loop itself will be nested in the main while loop, which can be stopped with a button., as shown in the following block diagram:

woyzeck_0-1629220298998.png

The problem however is that the both loops only execute one time. Once the for-loop is done for the first time, the while loop just stalls.

I'm sure it's obvious for you experts, but I'm stuck. Any hints are highly appreciated.

0 Kudos
Message 1 of 4
(1,403 Views)
Solution
Accepted by topic author woyzeck
  • Please attach your VI instead of a picture. (we cannot see many important things such as the mechanical action, hidden characters in your strings,, etc.)
  • How do you know exactly when it stalls?
  • Why do you do 14 iterations if all you keep is the value from the last iteration?
  • Learn about shift registers.
  • Do you really only need to send the measure command once and then never again? ((do you have the manual for the instrument?)

 

0 Kudos
Message 2 of 4
(1,399 Views)

Never mind - the problem was - as mentioned by you in the last point - that the VISA Write was outside the loop and so the VISA read ran into timeouts as there was no more data available to read. Actually the loops continued, but at very low speed.

 

Grabbed some coffee and was surprised that the thing was in its third loop when I came back...

0 Kudos
Message 3 of 4
(1,397 Views)

@woyzeck wrote:

Grabbed some coffee and was surprised that the thing was in its third loop when I came back...


Well, the default serial timeout is 10 seconds so it will continue at that pace ad infinitum, never receiving any data. (i.e. the while loop time will be 14x10 seconds).

 

I still think you have significant code problems (e.g. your tunnel modes, etc.) and we would be happy to point you in the right direction to improve your code 100 fold. :D) As a first step temporarily get rid of the communication and generate simulated data to work things out.

Message 4 of 4
(1,390 Views)