07-14-2011 03:58 AM
Hi !
I just contact asynchronous timer and I'm not familiar with it..I have some confusing points.
Such as "interval" in this statement
SetAsyncTimerAttribute(TimerID,ASYNC_ATTR_INTERVAL,5.0);
What it means .
I want to set a testing time for 7 days using asynchronous timer . There wil display running time and the rest of the testing time in user interface.
However,I do not know how to realize it.
I would appreciate it very much if you could give me some help.
Thank you very much !
Best regards.
xiepei
07-14-2011 04:10 AM
Hi,
in toolbox\asyncdem.cws you can find an example of using the SetAsyncTimerAttribute function.
07-14-2011 04:16 AM
Hi !
Thank you very much for your reply.
I have seen that example.But I could not understant it.
I do not know how to connect it with the function I want to realize .
I want to set a testing time for 7 days using asynchronous timer . There wil display running time and the rest of the testing time in user interface.
However,I do not know how to realize it.
Do you have any good idea ?
Thank you very much !
Best regards.
07-14-2011 08:02 AM
Asyncronous timers are like UI timers: they fire their callback with EVENT_TIMER_TICK event at regular intervals. The interval is set either in NewAsyncTimer or with SetAsyncTimerAttribute.
They are not to be intended as delay timers.
To execute such a long test with a timer you should build up a so called state machine on top of the timer and accumulate the time from test start to show on the UI or to discriminate among the sequence of operations to be performed.
The time spent from the last timer callback execution is given in eventData2 and can be cast to a double this way:
double tn; tn = *(double *)eventData2;
Accumulating 'tn' intervals on a double variables will give you the time from test start.
Timer time has a rollover approximatively once every 47.5 days, and that is the rollover of your double variable in which you get test time. On 7 days test time you will have not to bother fot timer rollover.
07-15-2011 03:52 AM
Hi !
Thank you every much for your reply.
I've already known how to use asynchronous timer interval.I intended to use Multi Thread to detect data and add it to my "start testing" function.
However,I'm not familiar with Multi Thread use. So I have to study multithreading technology use.
On the other hand,I judge the salve address range,CRC checking,data frame length and the data after processing.But,there's another situation.
Because of my procedure consist of many functions,there's the normal operation and the wrong error when each function is running. So,how to deal with the function whether it gives the correct or not.That is troubling me.The following is my detection data code.and it is in my thread function.
inqlen = GetInQLen (comport); for(i=0;i<inqlen;i++) { in_data[i]=ComRdByte(comport); } crc=usMBCRC16(in_data,inqlen ); //CRC computation device_addr= in_data[0]; //slave address bytes=(((int)in_data[2]<<8)|((int)in_data[3])); // bytes addr= in_data[4]; if((inqlen!=23)||(device_addr>10)||(in_data[1]!=0x10)||(bytes!=8)||(addr>73)||(crc!=0)) errorcount++; if((inqlen==23)&&(in_data[0]==device_addr)&&(in_data[1] == 0x10)&&(bytes==8)&&(crc==0)) { if(addr==1) { wv = (((int)in_data[5]<<8)|((int)in_data[6])); // alternating voltage zy = (float)(((int)in_data[7]<<8)|((int)in_data[8])); // Main circuit voltage zy=zy/1000; zl=(float)(((int)in_data[9]<<8)|((int)in_data[10])); // Main circuit current zl=zl/1000; bn=((int)in_data[11]<<8)|(int)in_data[12]; //Battery Numbers wc=((int)in_data[13]<<8)|(int)in_data[14]; //working condition cs=((int)in_data[15]<<8)|(int)in_data[16]; //current battery state bp=((int)in_data[17]<<8)|(int)in_data[18]; //battery power wt=((int)in_data[19]<<8)|(int)in_data[20]; //working time if((wv<0)||((wv>10)&&(wv<80))||((wv>300)&&(wv<550))||(wv>750)||(zy<0)||(zy>30)||(zl<0)||(zl>6)||(bn<0)||(bn>10)||(wc<1)||(wc>8)||(cs<0x20)||(cs>0x2b)) { errorcount++; SetCtrlVal (panelHandle, PANEL_ERRORCOUNT, errorcount); } else { rightcount++; SetCtrlVal (panelHandle, PANEL_RIGHT, rightcount); } } if(addr==9) . . .
Thank you very much !
Best regards.
xiepei
07-15-2011 04:33 AM
Hi!
I need to supplement a point.There's a mistake " 119, 26 Warning: Result of unsigned comparison is constant." when I debug the project.The place where it occurs error is
if(dCount>=0) { dCount--; SetCtrlVal (panelHandle, PANEL_REST, dCount); }
in
int CVICALLBACK AsyncTimerEventFunction(int reserved,int TimerID,int event,void*callbackData,int eventData1,int evenetData2)
But it could not affect my project's continuing debugging.I'm afraid that it would affect our project running on the spot.
Attachment is my .c file. I'm sorry to trouble you again.
Thank you very much !
Best regards.
07-15-2011 04:36 AM
Hi !
attachmet is my .c file
07-17-2011 03:37 AM
Hi xiepei,
it's not clear to me which is the exact question, but I looked at your code and I noticed several unclear items or errors that you should correct before your program can run.
1. Threaded function is launched twice: first time in the main and then in start test function
2. Threaded function is executed only once, as there are both a break and a ThreadFlag=0 immediately befor the end of while loop
3. Stop function has no influence on threaded function: if that one were correctly executing the loop it would continue even after the user presses stop (even more: it would contune indefinitely as the countdown timer has been stopped!)
As per the warning you are receiving, it is evident that an unsigned variable can never be negative, so a test with ">=" is redundant since it is always verified: the compiler is warning you about this.
07-17-2011 09:35 PM
Hi !
Thank you very much for me correcting mistakes.
I'm sorry I did not speak clearly for my problem.
One:
My procedure idea is:
1.Input testing time in “Testing Time(days)”numeric 2.press "statrt"button to start test 3.press "stop" button to stop test
It will show starting time,current time,running time and the rest of time and right count when I press "start" button.If there's mistake ,it will show error count on "Error Count"numeric. It will calculate per and show it on "Packet Error Rate"numeric when it reaches the testing time or I press "stop"button.
I have to judge the salve address range,CRC checking,data frame length and the data after processing right or not in my program.However,because of many functions in my program, there's the normal operation and the wrong error when each function is running. So,how to deal with the function whether it gives the correct or not.That is troubling me.
Two:
As I'm not familar with threaded function,I refer to other multithreading examples.I saw it launch threaded function a time in the main fuction.Because I have to have to activate asynchronous timer when I press"start" button.So I launch the threaded function twice in the start function.
I have added a ThreadFlag=0 in the stop function,but I'm not sure it is right.
You said the threaded function was executed only once before the end of whole loop.Could you give me some indication how to sove it ?
The attachment is my whole procedure and I have changed CVI version to 2009.
Thank you very much !
Best regards.
xiepei
07-18-2011 03:42 AM
Attached some little code update: you will find an answer to your question 2.
I don't understand your Q1! Nevertheless, considr that you should add error checking for communications errors: it should notice the operator and possibly stop the running test. If you are dealing woth errors in data received from the unit under test, they could be treated the same way or alternatively they could be simply counted and let the test proceed, as you are doing now.