08-09-2011 04:17 AM - edited 08-09-2011 04:18 AM
Hi !
Thank you very much for your reply.
I've set the timer as disabled and enable it on opencomport callback.But it still occurs the same mistake.
Although I place a breakpoint on openComConfig function ,it skip directly to the function send_data_function and it did not pass the function openComConfig. When I debug,it breaks immediately on send_data_function callback. I have placed a breakpoint on main function and saw it skip directly to the send_data_function callback from the main function when it execute .
The code on openComConfig function :
int CVICALLBACK opencomport (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { // int status, baudrate,comport,device_addr; switch (event) { case EVENT_COMMIT: SetCtrlAttribute (panelHandle,PANEL_TIMER, ATTR_ENABLED, 0); // Com port opening GetCtrlVal (panelHandle, PANEL_DEV, &device_addr); GetCtrlVal (panelHandle, PANEL_COMPORT, &comport); GetCtrlVal (panelHandle, PANEL_BAUDRATE, &baudrate); status = OpenComConfig (comport, "", baudrate, 0, 8, 1, 512, -1); // Use '-1' in OutputQueueSize SetCtrlAttribute (panelHandle,PANEL_TIMER, ATTR_ENABLED, 1); if (status < 0) { MessagePopup ("error", "Serial ports has been occupied!"); ThreadFlag = 0; goto Error; // Stop function if error } Error: // Finishing functions CloseCom (comport); break; } return 0; }
Would you please help me see the procedure thoroughly when you have time ?
The problem has confused me some days.I think it might be wrong in other place,but I could not check it out.
Thank you very much .
Best regards.
xiepei
08-09-2011 04:33 AM
What I was intending is to modify the properties of the timer in the UIR editor and uncheck the "Enabled" checkmark so that it does not fires any event when program starts. Next you can enable it in your "open com" callback.
Disabling it when entering the callback is useless, as timer events start executing immediately after the call to RunUserInterface () in the main.
08-09-2011 09:49 PM
Hi !
Thank you very muuch !
I've modified the property of the timer in the UIR editor and uncheck the "Enabled" checkmark and comment "CloseCom (comport);"out on opencomport callback and ThreadFunction callback.It could eliminate the mistake.
See the following two screenshots(attachment-screenshot):
I set the timer interval 1 second.but the errorcount is increasing so fast,according to the running time.
One more thing,it would exit normally if I press "quit"command button after "stop"button.But,if I press "quit" command button directly and does not press"stop" button,it would break and occur error on ThreadFunction callback.
The program may appear many holes since it is my first time to contact asynchronous timer and multithreading.The attachment "Master Test" is the program I have modified.
Would you please give me some guidance ? Thank you very much !
Best regards.
xiepei
08-10-2011 06:13 AM
Hi Xiepei,
I understand that you are using those concepts for the first time, but in my opinion you should sit down a while and try re-designing your application from scratch.
At present you are using:
Since items #2 and #3 are independent, there is no guarantee that the thread function checks for answer from the DUT in sync with the message sent to it: in effect it simply queries at its maximum rate while the timer sends messages only once per second, so the great part of times the thread function finds no characters on the port and marks an error.
In my opinion you are using too much resources with respect to what your application requires, wasting a lot of efforts to synchronize the operations between them: you could have satisfactory results with a single, independent thread that handles all the matter. Within the thread loop you should:
If you want you can use a queue and its callback to display test results in the main thread so that the user is informed of the state of the process. No need for an UI timer nor for an async one.
On the other hand, you should pay a little more attention to handling the GUI: Start button is always active even if the port is not yet opened; moreover, it remains active even if the test is started, so the user could hipothetically start it again and again with predictable problems. Similarly, Quit button tries to quit the program without stopping a running thread, if any, and so it may set the system in an unpredictable state, with the UI stopped and the thread still running.
Making a chart of possible application states (idle, setting, testing...) and what operation is admitted/expected from the user in each of them could help you in delimiting the access to every function.
08-10-2011 10:29 PM
Hi !
Thank you very much for your guidance.
Do you mean to say that I do not need to use asynchronous timer or UI timer? And use a thread loop to achieve items #1,items#2,items#3,items#4 and items#5.
1. Define a function to send a message to the DUT and use SyncWait () function on it to guarantee that a single polling event occurs per second.
2. Define a function to receive datas from the DUT,decoding the message and checking if it is correct.
3. Within the thread loop I should use Timer () function to calculate elapsed time.
Besides,I don't know why the start button is always active even if the port is not opened. Our chief engineer requires to start the testing when we press the "start" button and stop the testing when we press the "stop" button.,so as the "quit" button.
I will carefully think about the application states and delimiting to the access to every function.
Thank you very much for your information and for being so helpfull.
Best regards.
xiepei