LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Can CVI do synchronous multi threads?

Thanks for the input Luis.  An excellent information as allways.  Very useful.
0 Kudos
Message 21 of 26
(1,710 Views)
That sounds good to me. If I understand correctly, you will run your DAQ and add the data to the queue in the thread function, and then read the data from the queue and plot it to the graph in the main thread. This seems pretty standard, and it should work ok without having to block the main thread.

Off the top of my head, there are a couple of things to look out for: one is to make sure that you don't overflow the thread-safe queue (you can receive events, if you like, to warn you when the queue is too full). Also, you can, if you like, make the queue grow dynamically, but that doesn't really solve the problem in the long run, if your UI thread just can't keep up. If that happens, you have to decide how to handle it (plot every Nth value only, skip values that are too old, etc...)

Another thing to look out for is how to stop the DAQ task. You said one of the conditions is the user clicking a button. In that case, you want to make sure that you don't stop the task from the wrong thread. So the button callback should just set a global flag that the DAQ's thread function can check.

Luis
0 Kudos
Message 22 of 26
(1,709 Views)

I know in multi-thread algorithm the OS alternatively processes different threads for a slice of time. I want to know how fast the OS can switch between two different threads? From my understanding, the windows based OS has 10 mS i.e. 100 Hz swithching frequecy. If that's ture, does that mean the minimum process time for each thread is 10 mS? Thus, windows based OS cannot handle higher frequency (>100 Hz) thread. Is that right? Thanks.

 

0 Kudos
Message 23 of 26
(1,705 Views)

The 10mS number is a bit of a rule of thumb thing.  The actual value varies considerably based on the hardware itself, the configuration of the OS etc.   Take a look at this forum thread, particularly the last post by menchar:

http://forums.ni.com/ni/board/message?board.id=180&message.id=23030&query.id=24323#M23030

Coding up some test cases and evaluating the results are about all you can do in some cases.  The trick of course is to know what your conditions are for your worst case testing.  The issue you will have when dealing with very short time to service periods is not just the resource time allocated to your process, but the time it takes for the OS to switch things in and out to enable your thread.  There are so many variables that getting "determinant performance" where you really know what is happening down to the mS level is difficult.  That is why a realtime OS exists, it is tailored to prioritizing tasks on specific intervals and with very low latency when switching between tasks

 

0 Kudos
Message 24 of 26
(1,686 Views)

One of the basic problems with a normal PC OS is that it can always be blocked by some set of conditions the operator finds.  It is very hard to make them bullet proof.  I don't know what your absolute timing requirements are for your hardware control (average response time, worst case maximum), maybe you would like to post them here, but while we are covering the subject of realtime performance there are a couple of other options for getting deterministic hardware performance while still using a conventional windows OS and CVI. 
One route is to use CompactRIO or CompactFieldpoint hardware.  You can setup a control application within the intelligent hardware controller of these systems that will respond in the microsecond range or better.  You stream the acquired data for storage, post processing or display out of the hardware acquisition device to the PC, but all time critical decisions are made on the hardware itself.  If you have a situation where that kind of performance is required, this is a excelent solution, the tradeoff being higher hardware cost and the need to invest some time learning the LabView Realtime software used with these type of controllers.  You have not described anything that would require anywhere near the power or flexibility of CompactDAQ, but it is a option in these type of designs.

The R Series Intelligent DAQ Cards provide similar capability but a step down from CompactDAQ and CompactFieldpoint.  These cards use an on board FPGA that can be programmed to execute functions based on input conditions to the hardware.  For these cards you have to learn the LabView FPGA software, but they again provide the capability to react to events at the hardware level with microsecond resolution.

Yet another option is to look beyond the integrated NI solutions and use an embedded controller card to offload some of the hardware control.  This is similar in nature to the design structure of CompactDAQ but you would get something along the lines of a PC104 embedded controller card.  Actually PC104 is a form factor, there are other embedded form factors such as EPIC and EBX. These are basically little stand alone CPUs with some basic I/O and an expansion bus that uses plug on adapter cards to add additional features.  The CPU cards support numerous Operating Systems and are programable in a number of languages .  One of the simplest to get running is of all things DOS.  DOS makes a pretty decent hardware control OS for a embedded controller.  There are special flavors of DOS available for almost all the PC104 type embedded systems.   There are of course others OS's like PharLap, Windows CE, Embedded Linux, etc. You write a control program to run on the embedded card that handles your I/O control just as you would any other system.  Again you stream the data from the card back to the PC for display or data storage.  An embedded controller that includes a winsock interface to connect it over an ethernet port to the PC is an excelent way of implementing this.  These systems have a lower hardware cost than some of the other integrated solutions and a lot of vendors, but you are going to expend more labor getting things setup and running unless you already have some experience using embedded systems.

Again I am not suggesting you go this route, but if the timing requirements you have are just too much to implement with conventional PC hardware these options split the task up so that the timing/control functions move to hardware with better realtime capability.

 

0 Kudos
Message 25 of 26
(1,670 Views)
Not sure if this has already been mentioned, but you may find the cvi\samples\apps\daqmthread\daqmt.prj interesting.
0 Kudos
Message 26 of 26
(1,664 Views)