Home > Back-end >  For help! C language to create a thread is not running
For help! C language to create a thread is not running

Time:05-27

The code below
 
ULONG _stdcall ThreadFunc1 (LPVOID lpParam) {
AfxMessageBox (_T (" ThreadFunc1 "));
Static int nCount;//the number of generate events
While (g_keepRunning)
{
//as long as the events in the list have a signal, ends wait
ULONG RetForWait=0 XFFFFFFFF;
RetForWait=WaitForSingleObject (g_hEventSFIFO, INFINITE);
If (RetForWait==WAIT_OBJECT_0)
{
Cstrings tempStr;
CSFDJController1Dlg * curDlg;
CurDlg=(CSFDJController1Dlg *) AfxGetApp () - & gt; M_pMainWnd;
//display into the events of the number of
NCount++;
TempStr. The Format (_T (" number of events: % d) ", nCount);
//curDlg - & gt; SetDlgItemText (IDC_LBL_COUNT, tempStr);
Long retCount;//, I;
//or to decide whether to read, because the number of real data may not need the number of
TempStr. The Format (_T (" the number of data in SFIFO: % d) ", ZT8348_GetSFifoDataCount (g_cardNO, 1));
//curDlg - & gt; SetDlgItemText (IDC_LBL_DATA_COUNT, tempStr);
//ZT8348_GetSFifoDataCount get driver buffer (SFIFO) in the number of the current valid data
If (ZT8348_GetSFifoDataCount (g_cardNO, 1) & gt;=g_wantCount)
{
//ZT8348_AISFifo timing start AD or external trigger start AD, read from the drive buffer (SFIFO) batch number g_wantCount hope to get the number of
RetCount=ZT8348_AISFifo (g_cardNO, 0, g_resultArr, g_wantCount);//g_resultArr acquisition results
//show the first 8 digits
//g_resultArr [I]=1000.0;
//number for each averaging 30000, every 100 values
ZT8348_AISFifoChAver (g_resultArr g_cardNO, 0, 30000100);

//ZT8348_AISFifoChAver function only supports single channel, the current state is 1 channel value is 0, use 2 channel, averaging time requires twice times

Float gaiv=(g_resultArr [1] * 2)/(float). 1000;//conversion unit converts the mv v
Float gaimv=(g_resultArr [1] * 2);
TempStr. The Format (_T (" v "% 7.3 f), gaimv);//a total of seven two of the decimal point
CurDlg - & gt; SetDlgItemText (IDC_LBL_AD1 + 0, tempStr);

Float kg=38.18 * gaiv;//36.28 five points and the average of the
TempStr. The Format (_T (" % f 7.2 KG "), KG);//a total of seven two of the decimal point

CurDlg - & gt; SetDlgItemText (IDC_LBL_AD0 + 0, tempStr);

PYali=g_resultArr [1];
/* if the pressure value is minus the standard value range */
Float ca=PYali - chazhi;
If (ca<=2) {
//AfxMessageBox (_T (" obtain stable pressure value of the number of "));
Countaaa++;
}
If (countaaa> 3) {
//PYalir=PYali;
PYalia (kg);
}
Chazhi=PYali;

}
}
}
return 0;
}


Float StartCaijiwd () {
Cunya=0;
//AfxMessageBox (_T (" start gathering without parameters "));
//a new file
If ((g_fp=(fopen (" wending. Dat ", "wb")))==NULL)
{
AfxMessageBox (_T (" open file failed "));
return -1;
}
//AfxMessageBox (" PYali ");
//create a thread to monitor events
DWORD dwThreadId;
HANDLE hThread;
G_keepRunning=1;
HThread=CreateThread (NULL, 0, ThreadFunc1, NULL, 0, & amp; DwThreadId);
If (hThread==NULL)
{
AfxMessageBox (_T (" CreateThread failed \ n "));
}
The else
{
The CloseHandle (hThread);
}

//start the AD
ZT8348_DisableAD (g_cardNO);//stop timing AD
ZT8348_ClearHFifo (g_cardNO, 1);//to empty hardware FIFO (HFIFO)
ZT8348_ClearSFifo (g_cardNO, 1);//to empty software FIFO (SFIFO)
If (ZT8348_GetSFifoSize (g_cardNO, 1)!
=2000){
If (ZT8348_SetSFifoSize (g_cardNO, 1, 2000).
=2000){
Cstrings tempStr1;
TempStr1. The Format (_T (" g_cardNO: % d "), g_cardNO);
AfxMessageBox (tempStr1);
AfxMessageBox (_T (" not enough buffer application "));
Cstrings tempStr;
TempStr. The Format (_T (" wrong number: % d "), ZT8348_GetLastErr ());
AfxMessageBox (tempStr);

return -1;
}
}

G_wantCount=1024000;//200000;
ZT8348_SetSFifoThreshold (g_cardNO, 1, g_wantCount);//set SFIFO threshold
//open the interrupt, note HFIFO more than half full open interrupt will be crashed
//create a event
G_hEventSFIFO=CreateEvent (NULL, false, false, NULL);
If ((HANDLE) g_hEventSFIFO!=NULL)
ZT8348_OpenIRQ (g_cardNO, (long) g_hEventSFIFO, 0).//open the interrupt

ULONG AIRangeArr [8].
ULONG ampInxArr [8].
//can't use, because not all elements initialized to 2, ULONG AIRangeArr [8]={2};
//ULONG ampInxArr [8]={0};
//formula: sampling frequency=16000000 hz/(frequency division coefficient + 1)
Const ULONG ADinClock=16000000;
ULONG ADfreq=500000;//frequency division coefficient
ULONG ADstartModeWord=1;//time start-up
ULONG I;
//range for - 10 ~ + 10 v
for(i=0; i<8; I++)
{//2:0, + 10000 mv
AIRangeArr [I]=2;//6;//in the light of - 10000 - + 10000 mv range into the zero point and full value, must be consistent with the board's actual jumper
AmpInxArr [I]=0;
}

ZT8348_AIinit (g_cardNO, 0, 2, AIRangeArr ampInxArr, ADstartModeWord, ADinClock/ADfreq - 1, 0, 0).
ZT8348_EnableAD (g_cardNO);//start time AD

//returns the function state
Cstrings tempStr;
TempStr. The Format (_T (" wrong number: % d "), ZT8348_GetLastErr ());

/* PYali is within the scope of agv returned trigger stop harvesting */
//AfxMessageBox (" 2333333 ");
//float att=5000;
//Sleep (3000);
While (0.02) {
Sleep (6000);
If (cunya> 0 {
//AfxMessageBox (_T (" success for pressure value "));
Return cunya;
}
//AfxMessageBox (_T (" wait for 2 seconds to obtain stable pressure value "));
}

//return 0;
}

Void StopCaiji () {
//stop acquisition
The fclose (g_fp);//close
ZT8348_CloseIRQ (g_cardNO);//close the interrupt
//returns the function state
Cstrings tempStr;
TempStr. The Format (_T (" wrong number: % d "), ZT8348_GetLastErr ());


G_keepRunning=0;
If ((HANDLE) g_hEventSFIFO!=NULL)
{
If (CloseHandle (g_hEventSFIFO)!
=0, l){
G_hEventSFIFO=NULL;
AfxMessageBox (_T (the "closing acquisition"));
}
}

return ;
}

nullnullnullnullnullnullnullnull
  • Related