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.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with EasyTab_SetTabAttribute in threads

I am having difficulties with EasyTab_SetTabAttribute(panel, tabCtrl, tabPanel, ATTR_EASY_TAB_DIMMED, flag) in my multi-threaded data acquisition application.

The application is designed in two tabs, each coordinating a different measurement (but sharing underlying hardware). I want to use the DIMMED feature of the tabs to enforce resource locks (can't switch tabs while an acquisition is in progress, but before and after is OK).

My code is designed in two threads. The main thread deals with the GUI...the second thread performs a (polled) data acquisition). On "Start" button press (in the main thread), I dim the other tab (the one not currently in use) and start up a data acquisition procedure in the second thread. At the completion of the data acquisition procedure (and in the acquisition thread), I attempt to undim the tab which was dimmed earlier...like this:

/* GLOBALS */
int mainPnl, tabCtrl, acqPnl1, acqPnl2;
int threadPool, threadTID;

/* This call gets scheduled in the acquisition thread by the "Start" button callback (below) */
int CVICALLBACK _threadFunc( void * ) {

/* Perform data acquisiton */

EasyTab_SetTabAttribute(mainPnl, tabCtrl, acqPnl2, ATTR_EASY_TAB_DIMMED, 0);

}

/* This function gets called in the GUI thread by the "Start" button in Acquisition panel 1 to start the ball rolling */
int CVICALLBACK cbHandleStartButtonInAcq1(...) {

EasyTab_SetTabAttribute(mainPnl, tabCtrl, acqPnl2, ATTR_EASY_TAB_DIMMED, 1);

CmtScheduleThreadPoolFunction(threadPool, _threadFunc, NULL, &threadTID);

}



(Yes, I've left out the event switch() statements and the return statements from the snippet, but I think you get my meaning).

The problem is this...The first SetTabAttribute (the one in the button callback) works perfectly (the other tab is dimmed as expected). However, the second SetTabAttribute (called from the acquisition thread) does not undim the other tab (does not return any error code, either).

I'm sure my problem has something to do with the thread interactions. I've tried many variations to help locate the problem:

1) This same structure works perfectly for other (non-easytab) controls on the panels using SetCtrlAttribute(..., 0/1).

2) Placing another SetTabAttribute(..., 0) in the button callback immediately after the existing one which dims the tab functions as expected. Tab is (presumably) dimmed, and then undimmed.

I've added the EasyTab source to my project and traced through the execution and all appears OK (same operations occur for both DIM and UNDIM calls). It's almost as if the EasyTab is undimming, but not recognizing that it's status has been changed. Does anyone have any other recommendations?

Thanks in advance,

- Matt Pfenninger
0 Kudos
Message 1 of 4
(2,783 Views)
A quick and dirty solution would be for you to use the PostDeferredCallToThread function in your aquisition thread, which would allow you to always set the dimming from the GUI thread.

I'm not sure yet why the problem is ocurring. It will take some investigation to find out more.

Luis
NI
0 Kudos
Message 2 of 4
(2,783 Views)
Hello Matt,

I believe the problem here is one of refreshing the panel. Since the set attribute call is from a different thread from where the panel was created, it is not automatically refreshed. Try placing the function ProcessSystemEvents(); just after EasyTab_SetTabAttribute(mainPnl, tabCtrl, acqPnl2, ATTR_EASY_TAB_DIMMED, 0); and see if that helps.

If none of these suggestions help, or if I�m not correctly understanding your issue, please post the software and versions you are using, the applicable portions of your code, and any other information that may help, and I�ll be happy to look further into it.

Please let me know if this works for you and have a nice day!

Robert M
Applications Engineer
National Instruments
Robert Mortensen
Software Engineer
National Instruments
Message 3 of 4
(2,783 Views)
Adding ProcessSystemEvents(); worked like a charm. Thanks for all your help.

Cheers,

- Matt
0 Kudos
Message 4 of 4
(2,783 Views)