LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Do I need multithreading?

Hi All
 
This question spans a number of subjects so I hope I have put it in the right area.
I am using an interrupt like function to detect transistions on a digital input (DAQmxCfgChangeDetectionTiming) and setting up a counter/timer to accurately timeout after a specified time period. The while loop requires the ProcessSystemEvents function in there otherwise the change detection function does not work properly as there is not anytime allowed to service this function.
 
However, the ProcessSystemEvents function usually causes a General Protection Fault as I use the code below or similar code several times during my program.

setup_timer();                                                                       //Configures timer counter to time out (go low) after 10 seconds
start_change_detection();                                                    //Monitor digital input 1 for transistions using DAQmxCfgChangeDetectionTiming
read_digital_input();                                                              //Monitor timer output which is connected to digital input 2
 
 while (data[0] ==1)                                                               //While timer output is high  (timer not timed out)
 { 
   ProcessSystemEvents();                                                 //Do other events while waiting, necessary for change_detection() to work properly
   read_digital_input();                                                           //Read digital input again
 }
 

If I wrote the timer function in a second thread and removed the ProcessSystemEvents from the while loop, would this work?
I am using a NI PCI-6229 I/O card, LabWin 8.01
 
Any help would be appreciated
Regards
Andy
0 Kudos
Message 1 of 2
(3,146 Views)
Hi Andy,

Yes, implementing a second thread will help your application.  When you are running this code, your UI is also being called which will lock up your program.

I would recomend looking at some of the shipping examples and search for multithreading.

If you are still having difficulties please reply back and if possible could you also send in your code so I can get a better idea of what you are tryong to do.

Regards,

Seamus
0 Kudos
Message 2 of 2
(3,087 Views)