From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

visa serial port and while loop

Solved!
Go to solution

Hi,

 

I am trying to acquire data from a device via serial communication. It is a RS232 interface. I am using a visa port and I know to open and close the visa port again and again while the programm is running is bad style. So, I trieed to use a while-loop excluding the Visa open and close (see the secound attachment, Program 2). Unfortunatly this program isn´t working and I can´t find the bug. In contrast the first attachment (program 1) is working properly (except that the speed is maybe lower). Could sombody help me to get the secound program working.

Thank you!

Best regards

Soffi

Download All
0 Kudos
Message 1 of 55
(12,079 Views)

The two images are exactly the same.  Where is the While Loop?

Nevermind, I found it.  (it much be way too early right now).

 

The only thing I see wrong is the fact that you cannot stop your loop without aborting the VI, meaning that your VISA Close is not being ran.  You should add a Stop button in order to stop the loop so that you can properly close your port.


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
Message 2 of 55
(12,054 Views)

Ok, thank you. That´s true Smiley Happy

But unfortunatly my problem can´t be solved by adding a stop-button.

Maybe it´s not about the programm, but about the device.

The measurement device, wich is connected to my computer, just sends one value. Then, an error apears on the measurement devices screen.

After that, a time out error shows up in labview.

The measurement device is a heidenhain position measurement device.

 

Best regards

soffi

0 Kudos
Message 3 of 55
(12,034 Views)
You should provide the error. You should also not use the Bytes at Serial Port when you have a termination character selected. There may also be a problem with the data being written. The '2' constant should be a U8. Attach the manual for the instrument.
0 Kudos
Message 4 of 55
(12,020 Views)
Solution
Accepted by topic author Soffi

What you need to do is to add a shift register for the VISA resource name and error. See the attached a screen shot.

 

I couldn't find this anywhere in NI's examples. (This one's based on the Basic Serial Write and Read example vi.) When I first started with LV, I asked tech support how to do this, and they told me. I WISH THEY WOULD SHARE THIS TECHNIQUE WITH US USERS!!

 

Hope this helps. (I can attach the vi if you want.)

 

Ed

Message 5 of 55
(12,000 Views)
Solution
Accepted by topic author Soffi

Here's the front panel screen shot. This vi continually sends a command out the serial port and reads a response, as long as the Write and Read button is True.

0 Kudos
Message 6 of 55
(11,997 Views)
Solution
Accepted by topic author Soffi

Here's the vi, attached. It was developed in LV 8.5.

Message 7 of 55
(11,993 Views)
Solution
Accepted by topic author Soffi
That's not the best way to do serial communication but the NI example is not the best either. When you have a termination character enabled, you do not use a wait or the Bytes at Serial Port. You just use an arbitrarily high byte count for the read. The read automatically terminates.

Shift registers are a basic concept and are shown in numerous examples and tutorials.
Message 8 of 55
(11,978 Views)

Knowing the error you are getting would help out a lot.

 

But first off, using "bytes at port" is not a good practice.

 

In general it is better to enable the termination character in the serial setup

look at the received data with the "/ codes display" view turned on you will see the termination character (probably /n or /r maybe both)

Then set your VISA timeout to a high er value than it should take to read your serial data

Now the VISA read will wait until it receives a termination character or time out

 

 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 9 of 55
(11,975 Views)

Dennis - Can you point to some examples/tutorials.

 

You notice my vi does use the LF termination character. Wiring up the Bytes at Port to Byte Count is okay, because, from LabVIEW 2009 Help:
http://zone.ni.com/reference/en-XX/help/371361F-01/lvinstio/visa_read/. "The VISA Read function returns less than the number of byte count if
the function reaches a termination character (mine is set to LF), or it reaches the end of the buffer, or a timeout occurs." (Mine is set to 1 sec.) So this is best of both worlds. If the serial string being read does not have a termination character, it will keep reading as long as there is data being received, within the timeout period.

 

Ed

0 Kudos
Message 10 of 55
(11,967 Views)