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: 

Problems with VISA serial connection (Missed ticks in data)

Solved!
Go to solution

Hi,

I have designed a DAQ card with USB connection. The USB connection is working in Virtual Com Port mode. 

 

The main vi has a while loop. The sampling time is defined by user and the main while loop iterates by this sample time (for example 5ms, 10ms or ...). Data communication is done in this while loop using VISA read or write tools. Data is stored in some global variables so that other vis could read or change them.

 

There are seperate vis for each part of DAQ card, Analog Input, Digital Output and ... . Each vi has its own while loop which iteration step may be different from the main while loop.

 

The program works correctly but there exist a lot of so-called "missed ticks" in data communication. I attached a screenshot from Analog Input vi. A sine wave is produced with Analog Output vi and this output is wired to an Analog Input. As you see the data communication has some problems. 

 

Is this because of several loops working concurrently? Or VISA communication has some problems? 

 

Thanks in advance.

0 Kudos
Message 1 of 7
(3,606 Views)

Can you zip and post the actual code? It would be very useful to help find the error.



-Matt
0 Kudos
Message 2 of 7
(3,586 Views)

As previously mentioned we need to see real code.  And, it would be helpful to know what that USB DAQ device is.

 

VISA is very seldom the problem.  I would go so far as to say the most likely source of the issue you are seeing is between the monitor and chair in your development enviornment.  A snippet of the main vi BD would help us understand if you are using a relable design pattern to get the results.


"Should be" isn't "Is" -Jay
0 Kudos
Message 3 of 7
(3,574 Views)

This is the code for the main vi.

0 Kudos
Message 4 of 7
(3,565 Views)
Solution
Accepted by topic author iman_h

The main problem I see with your VI is that you are using Bytes at Port which is the wrong thing to use about 99% of the time.  It looks like you are trying to break apart about 31 bytes and turning them into numbers.  Suppose at the instant you check the bytes a port, you've only received 28 of those bytes.  Some of the variables will wind up with 0's because you don't have all the data.  But on the next read, you'll get the remaining 3 bytes plus whatever comes in the.  Now your packet of data is misaligned.

 

I suggest that if you want 31 pieces of information, you just put a constant 31 at the VISA read and get rid of the Bytes at Port node.

 

Other tips.  Index Array is EXPANDABLE!  You don't need to create 31 copies of index array and wire a constant to each one.  Drop one node and expand the bottom border downwards as far as you need.  You won't even have to add any constants because by default it will give you index 0, index 1, index 2, ....

Message 5 of 7
(3,552 Views)

Dear RavensFan, Thanks! The problem is solved. The DAQ card is working nicely now. I replaced the Bytes at Port with a constant. 

Thanks about the note about Index Array. Actually I used them in this way because I had to change the index of data with respect to a data array in microcontroller and changing the index number is easier than rewiring the Index Array.

 

0 Kudos
Message 6 of 7
(3,535 Views)

@iman_h wrote:

Dear RavensFan, Thanks! The problem is solved. The DAQ card is working nicely now. I replaced the Bytes at Port with a constant. 

Thanks about the note about Index Array. Actually I used them in this way because I had to change the index of data with respect to a data array in microcontroller and changing the index number is easier than rewiring the Index Array.

 


Unless I misunderstood this post, you can achieve the same thing using RavensFan's suggestion by explicitly wiring each element in the expanded node.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 7 of 7
(3,503 Views)