LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

While loop confliction with VISA Read

Hi, I have a question. Is it possible to put a VISA Read inside a whie loop, while a VISA Serial Port is outside the while loop, then connected each other. Are there any issues with this? If yes, which while loop stop condition should I use in this case?

 

My VI acquires the data from the port only once at the begeinning, then never obtains any data again. It might be an issue with while loop.

 

I also put my VISA Read in a sub VI which I am not sure if it can cause a problem.

Download All
0 Kudos
Message 1 of 14
(3,977 Views)

HI,

 

Yes, it is typical to put the initilization outside the loop and the reads inside the loop. 

 

However, your SubVI, which calls another SubVI, then re-initilizes the connection.  Don't re-initilize the connection, just pass the reference.

 

Also, when I unzip the sub VI's, and open the thesis VI, all the wires are broken as if this is not the correct top level VI. SPlitting Values is also missing.

 

thesis_with_Subs.png

-------
Mark Ramsdale
-------
0 Kudos
Message 2 of 14
(3,973 Views)

Not at all.  In fact, that's how it's supposed to be done.

Initialize outside of loop, read/write/whatever repeatedly inside of loop, close outside of loop.

 

I'm getting a lot of broken wires and subVIs that need relinked and one VI missing.  Did you give us older version of the subVIs or was this just where you got stuck?  I also noticed that you are initializing the serial port twice (main VI and read VI).


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 14
(3,970 Views)

Alright I attach them one by one

0 Kudos
Message 4 of 14
(3,966 Views)

..

Download All
0 Kudos
Message 5 of 14
(3,965 Views)
0 Kudos
Message 6 of 14
(3,964 Views)

Sorry for your inconvenience to download my sub VIs but I dont have Winzip now. There is only one initial VISA serial port and one VISA inside the big while loop. As I told you, the VISA reads only once at the beginning, then no more response :(.  Is it related with bit or baudrate? Or mv VI is too big? I notice that while it is measuring the data, it's quite slow too. Very slow!! What should I change or add into my VI in this case?

 

Thanks for your helps

 

 

0 Kudos
Message 7 of 14
(3,962 Views)

Hi,

 

I used all the individual SUBVI's you posted.  Still, the 'VI connection' SubVI doesn't match with the name for top level Thesis.  The name the top level is looking for is 'VI connection', the Sub you provided is 'VIs connection'.  The names are different, but I used the Sub provided.

 

So, just to be sure, previously from the ZIP files, the VI connection called another Sub that Re-initialized the connection, and you don't want to do that.  But that is gone now.

 

Now, the VI looks correct (no re-init), but it is not the name the Thesis top level VI is looking for.  So it is possible that you are running the Thesis VI with a SubVI that is different than what was posted.  I just wanted to mention that.

 

***

 

What are you getting from the Read of the device after the first read?  If there is no read, the VISA should time out and kick out an error as it is reading a fixed number of bytes.  Are you getting the "#" that you are looking for after the first read?  Maybe this "#" is not in subsequent messages, and this makes the data look like it is not reading.

 

On the surface, the code appears to be functional, you are reading based on a number of bytes, you might have better luck looking for a termination character instead.

 

-------
Mark Ramsdale
-------
0 Kudos
Message 8 of 14
(3,950 Views)

Sorry I attached VI connection for you. They are the same files with different names. It shouldn't be the issue about calling the wrong sub VI because I have both VI and VIs connection on my computer.

 

After the first read, the acquired values still change (but randomly). I tested it by adding tempertaure to a specific sensor, but it did not respond anymore after the program is started. It measures only one time. VISA doesn't kick out or do anything. The values keep changing randomly (I have no clue by they are changing all the time, even though they don't respond anymore)

 

What is a termination character? Which fucntion is it responsible for? How should I change it?

 

I think it might be an issue about the while loop because the VISA read obtains the read values only once. However, you said it isn't related with that, so I have no clue!!!

 

I also attached the original sub VI for the data acquisition that I received from the test bench, and then extracted all block diagrams inside the while loop and put into my big VI's while loop. And connected the VISA serial part outside the while loop.

 

I am pretty desperate now. I don't know how to make it work 😞

Download All
0 Kudos
Message 9 of 14
(3,940 Views)

Hi,

 

Can you describe a bit more about the second loop read.   You are saying the acquired values still read, but they are random. 

 

 

The program sets the buffer quite large 40960, was this supposed to be only 4096?   It is possible that you are putting a lot of data in the buffer, but only reading the values set by the number of bytes (200).  So, this could appear that you are getting random or incomplete data each subsequent read.  Do you know what size data you will be reading?  You might try setting the number of bytes to read to 40960. 

 

I see now that the program is setting and enabling the termination character ( on the init VISA serial).  It is currently set to "\n".  This means the VISA read will stop when it encounters a "\n".  I think you should choose one or the other, termination character or byte count.

 

The way you are set up now I think the VISA is looking for either the byte count (200) or the termination character (\n), so set the byte count high.

 

***

 

I don't see any write commands.  Is this instrument "just broadcasting" all the time? 

 

Did the original 'data read' VI ever work ? (which you say is the foundation fo the Thesis VI)

-------
Mark Ramsdale
-------
0 Kudos
Message 10 of 14
(3,933 Views)