LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Control USB and GPIB devices by event structure

Hi there!

 

This is my first topic here and I hope it's the right forum.

At the moment I try to improve my LabView skills. At university - long time ago - we didn't go far into it.. so my experience is limited.

 

What I want to do:

I'm working for a EMC lab and we do a lot of EMC tests. As some tests are a bit more time consuming because we do a lot things by hand, I wanted to improve it by using labview.

I started with controlling each device seperately which is working flawless (arbitrary waveform generator and voltmeter). Now I wanted to combine the VIs. That is not working and I'm not sure why.

 

That's my code (just an example, there are some more events for reading ID):

image.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

VISA 1 is GPIB and VISA 2 is USB connected.

When I start the events one after an other it suddenly breaks (not in the "first round" but in the second or third). 

And that's the point where I'm lost.

I also tried to slow down the event but that didn't solve the problem.

 

Maybe you can help me!

 

Greetings,

Fabian

 

0 Kudos
Message 1 of 10
(2,649 Views)

It's hard to tell from photos, but I just want make sure that first of all, you are using ONLY ONE event structure.  Multiple event structures can "fight" each other.

After you initialize each resource, you'll want to pass them all into the event structure.  A clean look is to bundle each resource handle with a name (string constant can work) then build an array of those clusters.  Passing this array into the event structure is just a single wire to work with inside the event handler. Lets say you had 10 devices; 1 wire is cleaner than 10 input terminals.  Each event case can index the array for the appropriate resource to work with.  When your program ends, index through the array closing each resource.  There are probably other (maybe better) methods, but this will get you started.

0 Kudos
Message 2 of 10
(2,646 Views)

Hey!

Thanks for your answer.

 

I have two event structures: 1 for USB (function generator) and 1 for GPIB (voltmeter).

Good to know, that I need to reduce it to ONE event structure otherwise it will blow up.

 

Thanks for that advice and giving me the right direction!

 

Greetings,

Fabian

0 Kudos
Message 3 of 10
(2,610 Views)

Hi Fabian,

 

Good to know, that I need to reduce it to ONE event structure otherwise it will blow up.

That is no "need to", but a good recommendation…

 

- There is no loop in your image: event structures usually are placed within loops…

- There is no error handling in your image…

- Do you name all buttons just "OK button" with a number? Why not use descriptive control labels?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 10
(2,606 Views)

GerdW is correct.  You CAN have more than 1 so long as they are running in parallel.  However, when you are first learning, it is very easy to make mistakes with such a setup.  Since I am assuming your events won't absolutely need to run in parallel, one event handler should suffice for now.

0 Kudos
Message 5 of 10
(2,593 Views)

Hello there!

 

Thank you for your advices and sorry for my late reply (at the moment it's super busy at work).

 

The reason why I took two event structures is, that I need to "talk" to two different devices. I'm building that setup for an EMC measurement where the function generator and the volmeter is finally inside a closed loop system.

 

-> How can I control two different devices by VISA when I just have 1 event structure?

-> I did no error handling because I thought it's not that much of a need when I'm still in try-out.

-> "OK buttons" will ofc be renamed in the final version. For testing purpose it's just "unnamed" because I just test different functions with it (set measurement parameters: frequency, output voltage, ...)

 

I had that event structure already in a while loop with a stop condition. But that didn't change anything.

 

Is there any example in labview for my issue?

 

Greetings,

Fabian

 

0 Kudos
Message 6 of 10
(2,548 Views)

Hi Fabian,

 

I had that event structure already in a while loop with a stop condition. But that didn't change anything. Is there any example in labview for my issue?

What exactly is your issue?

All you said is "it doesn't work" - that sentence doesn't include any useful information…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 10
(2,542 Views)

Hi Gerd!

 

My setup is the following:

- Function generator with USB connected to laptop

- Voltmeter (later it will be an oscilloscope) with GPID-USB-HS adapter conntected to laptop

 

What labview should do for me:

- Control both devices

- Do a closed loop control (function generator -> amplifier = disturbance for EMC test --> blackbox --> oscilloscope = measure disturbance and control output level of the generator to a given point). For this EMC test I need a lot of different frequencies and signals. That is why I need more button to "load" those settings.

 

What does not work:

- In my first post is a picture with my current labview setup. 

- If I want to initialize just the function generator alone and do different settings (like set frequency, set output) - it works. (same for volmeter)

- If I want to init the voltmeter after is successful initialized the function generator - it does NOT work.

 

"Not work" means:

Labview gives me an Error and the wanted function (like set frequency) will not be finished.

 

Is this information helpful?

 

 

 

0 Kudos
Message 8 of 10
(2,538 Views)

Hi Fabian,

 

"Not work" means:

Labview gives me an Error and the wanted function (like set frequency) will not be finished.

Is this information helpful?

This would be helpful once we know which error you get…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 10
(2,530 Views)

Hello there!

 

Sorry for my late response but I have rarely time to get into my labview work.

 

In the meantime I did a lot of progress, I guess. I started using the QMH and my VISA problems are gone. Controls are working (output on/off, read measurement value etc.).

The next step was to do a servo loop. I want to read a measurement value (from oscilloscope or digital desk multimeter or similar) and control the output power of a signal generator (or similar).

 

In my example it is still a frequency generator: Different frequencies with different output values to equal the value I want.

My problem is now that I want to cancel immediately my servo loop if anything bad is happening (as I already said I'm working for an EMC lab and I want to automate some immunity tests with labview).

The only way I can stop the loop is when I press the "Abort execution" button. But with that step I can't immediately disable the output of the signal generator (like an emergency stop).

 

I know already that a while loop inside an event structure is not the best thing you want to do because the program can't handle any user events ... yeah and that is exactly what I'm struggeling with. Any other ideas? An advice in the right direction would be great! 

 

I'm sorry that all my comments in the code are in German, but I hope you can still figure out what my code does.

 

Thanks in advance!

 

Greetings,

Fabian

Download All
0 Kudos
Message 10 of 10
(2,417 Views)