Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Sincronize 3 Visa reads

Hi,

 

I am working on a project that has 3 places of measurement of pressure and flow.

2 of those device are connected by bluetooth and it serial code is COM 4 and COM 6.

The other one is a USB device thats change it serial code by the usb port that I plug it.

 

For the read, I used a Visa Read for each one but when I put the devices on serie, I can see that there is a big delay between them.

Another problem that I am having is a timeout error in Visa Read that crash the program. It read everything but, in a random time, it crashes and a error appears.

 

Info of the code

- The bluetooth devices has a Terminal Char \r\n and the usb device has a Terminal Char \r\00. I can't change this Terminal Char, but Labview read the exact buffer. I confirm this using Tera Term.

 

- It's a new project, so I am trying to deal with this bug first and then I will see how can I put time stamp on Waveform Chart, put all the waves below each other and export the data on a sheet or another file to work with on Matlab.

 

Thanks for the help.

 

PS: I attach a video of the problem to help to see the delay between them. On top are the flow signals and below the pressure signal. The first device of the video is COM 6, second USB (COM 3) and last one is COM 4. By the video, you can see that the flow signal has to appear first on COM 6, than COM 3 and the last on COM 4 but this is not whats happening.

Download All
0 Kudos
Message 1 of 34
(3,881 Views)

Hi

Just to be able to measure better where the problems exactly occur I would not put all three reads in the same loop. If one instrument is faster (measuring more data items per second), It will be slowed down by the other instruments.

I would each give its own while and send the data via a queue to a "main" loop that gathers the data.

Anyhow I would try to optimize each of the instruments in speed, maybe you need a special serial buffer setting to make the instrument react faster.

greetings from the Netherlands
0 Kudos
Message 2 of 34
(3,824 Views)


@Albert.Geven  escreveu:

Hi

Just to be able to measure better where the problems exactly occur I would not put all three reads in the same loop. If one instrument is faster (measuring more data items per second), It will be slowed down by the other instruments.

I would each give its own while and send the data via a queue to a "main" loop that gathers the data.

Anyhow I would try to optimize each of the instruments in speed, maybe you need a special serial buffer setting to make the instrument react faster.


 

When I get each one alone, I don't have this delay for my blow. So I don't think that the problem is the sensor buffer because using Tera Term, I don't have any delay using the three sensors.

I was thinking on use three of the same program that read each sensor indivudually and try to sync them with the time stamp of windows. But I really wanted them all syncronize in the same file because my experiment will have a lot of data.

 

About the loop of each instrument, with your tip, I was think on using time loop, but they would never be syncronized. I had thought on put three loop inside this big one but I am thinking that when the first one started, the others ones will only start when the first one is over. So how can I do that?

 

Before I go, thanks for the help.

 

PS: I will try something and if I got, I put it here.

 

 

0 Kudos
Message 3 of 34
(3,799 Views)

As I said, when I got them in each program, I can record them and I can syncrozine with windows time stamp. But I really wanted to do it in a single file.

0 Kudos
Message 4 of 34
(3,788 Views)

@MrBadgerBR wrote:

As I said, when I got them in each program, I can record them and I can syncrozine with windows time stamp. But I really wanted to do it in a single file.


Yes, this is the way to do it.

   - Run data collection in separate while loops.  Record a time stamp for every measurement and synchronise data afterwards.

   - This approach is still single file, just multiple while loops in a single  file.

   - Rather than plotting your data on a chart use an XY graph with time as X-axis.  You can plot all three measurements in the same plot to visualise the synchronisation.

 

Some other comments:

 - it looks to me like your code can be simplified into 2 subvis (initialize and measure+calculate).

 - the instruments use termination characters, so why limit the reading to 14/17 bytes?  I think that is why it seems to pause/crash on occassion.  Use 1024 bytes for all readings.  Measure the length of string and then parse.  If it isn't the expected 14 or 17 bytes then examine why not and either accept or reject that data.

 - use these 2 subvis for each of the 3 data collection loops.

 - use the "High Resolution Relative Seconds.vi" to measure time between measurements

 - save all the data in arrays while measuring, then save to file afterwards or implement TDMS logging.

 

Craig

 

0 Kudos
Message 5 of 34
(3,765 Views)

I did all that you said and when I done in separete while loops, the graphs didn't crash.

But, because of the data are in diferents while loops, I couldn't get them in a vector to save them all in a single file. How can I do this without knowning the size of the vector?

 

I am putting the code here but in the end of the while loop (push stop button), I only can get one value.

0 Kudos
Message 6 of 34
(3,726 Views)

Hi

looking at your code it surprises me that all 3 lines are identical. Not a problem but maybe a feature.

Each while delivers two graphs each with a timestamp and a flow and pressure.

You put them in a chart that is Ok to view. Bbut it is a mistake here is to use the graph data and put it into a merge signals vi.

Please do not use the dynamic data type. It is meant to make things easier but makes so misty what happens inside that it is more difficult.

Put 1 timestamp and the pressure and flow data either in a 3 element array (or better in a cluster later) and enable the crossing of the while loop to build an array (right click on the crossing and select tunnel mode/ enable indexing. Then you get 3 2D arrays that contain all data.

If needed you can use this data to fill 3 xy graphs (you need a conversion) to display all data.

Putting this in a file depends on how much data you need to save.

 

greetings from the Netherlands
0 Kudos
Message 7 of 34
(3,711 Views)

First of all, thanks for all answers.

I didn't know how to do the enable indexing thing and it was exactly what I were search for.

 

I try to remove all the dynamic data type for save it. When I get them to my "Write To Measurement File", my program crashs. So I only convert them on the last part of the code.

 

When I get timestamp to "Build Array", it became dynamic data, so I am not using it. I think that because of my Sample Frequency is 100Hz, I can get the index and multiply by 0.01 and get the time of each sample.

 

A problem that I am having now is that the sensors are not syncronized. As I show on video, they are in serie and by the graphs or the results, I can see that the delay is very high. I am attaching the files here to you see to.

 

First column is Flow and the second is Pressure. As I block the air exit, the pressure gets high and them I can see in "Medicao.lvm" that there is a 0.56 sec (832 with 888 index number) delay with the first with the second and a 1.38sec (888 with 1006 index number) delay with the second and the third.

 

What can I do? I put them in a one while loop? Has a .vi that sincro them?

Download All
0 Kudos
Message 8 of 34
(3,693 Views)

Let's simplify the main block diagram, then you can get down to business.  First, lets start with a simplification of your code into subvis.  See attached.  Note that I use a timer in the "acquire data" subvi to store the time the measurement occurred. Now your main block diagram will have 3 loops like below.

 

with_subvis.png

 

Now what is it you really want to do with that data?  Display all measurements from all sensors in real-time in a single plot? 

 

Or just log data to a file that has the exact measurement time for each sensor?  This way you can plot synchronised data later.

 

Both are possible, logging to TDMS as you measure is easier.  Displaying all in 1 plot will require a queue or other type of architecture producer/consumer design pattern.

 

Craig

Download All
0 Kudos
Message 9 of 34
(3,667 Views)

I can't open the files because I am using Labview 13.0 (Labview 2013) and yours is Labview 18.0.

 

For the data, I need it to have all the pressure and flows to research a method of breathing that can help my pacient to have less lung damage for mechanical ventilation. So I need the data to be sincronize to see what happen with each tipe of breathing that I will try to do because the sensors will be far of each other. So this program is only to acquire the data and the processing will be done in Matlab.

The plot view is only to know that the pressure and flows are changing and that I can see what I am putting into my pacient. Because of that, I don't need them to be in the same plot. I only did that to see if they are sincronized.

0 Kudos
Message 10 of 34
(3,653 Views)