Home > Software engineering >  In thread calls put_Item function writes data to EXCEL, will produce interrupts, if put_Item in use
In thread calls put_Item function writes data to EXCEL, will produce interrupts, if put_Item in use

Time:09-27

UINT CDemoCANDlg: : ReceiveThread (LPVOID v)
{
=(CDemoCANDlg *) AfxGetApp CDemoCANDlg * DLG () - & gt; GetMainWnd ();
Int k=0;


While (1)
{
Int NumValue;
int i;
VCI_CAN_OBJ pCanObj [200].

Cstrings strbuf [200], str1;
Cstrings ID;//store ID
Cstrings DATA [8].
Cstrings Index [8].
The Index [0]="you:";
The Index [1]="I:";
The Index [2]="he:";
The Index [3]="address:";
The Index [4]="address:";
The Index [5]="dw";
The Index [6]="w w";
The Index [7]="ww";
int num=0;

CSize size;
Unsigned int JustnowItem;
BYTE ReceivedID [4].

Size. The cx=0;
Size. The cy=50;
Cstrings STR.
Int Len=0;
For (int kCanIndex=0; KCanIndex<2; KCanIndex++)
{
//dynamic linking the receiving function called
-> -> NumValue=https://bbs.csdn.net/topics/VCI_Receive (DLG m_DevType, DLG m_DevIndex, kCanIndex, pCanObj);
//receive information list
K++;
Cstrings strTime;
SYSTEMTIME systime;
GetLocalTime (& amp; Systime);
StrTime. The Format (" 02 02 02 % d: % d: % d: % 3 d ", systime. WHour, systime. WMinute, systime. WSecond, systime. WMilliseconds);

For (num=0; Num{
If (nextrow==59999)
{
DLG - & gt; M_list. DeleteAllItems ();
Nextrow=0;
}


DLG - & gt; M_list. ItemColorFlag [nextrow]=0;

STR. The Format (" % d ", nextrow);//data line STR
JustnowItem=DLG - & gt; M_list. InsertItem (nextrow, STR);
Nextrow++;

DLG - & gt; M_list. SetItemText (JustnowItem, 1, strTime);//strTime system time

STR. The Format (" % d ", kCanIndex);
DLG - & gt; M_list. SetItemText (JustnowItem, 2, STR);

DLG - & gt; M_list. SetItemText (JustnowItem, 3, and "Receive");
STR="";

If ((pCanObj [r]. Num RemoteFlag)==1)
{
DLG - & gt; M_list. SetItemText (JustnowItem, 5, "Remote");
}
The else
{
DLG - & gt; M_list. SetItemText (JustnowItem, 5, "Data");

}
If ((pCanObj [r]. Num ExternFlag)==1)
{
for(i=0; i<4. I++)
ReceivedID [I]=pCanObj [num] ID [I];
If (DLG - & gt; M_radioIDFormat)//the from sja1000 format to direct id
{

ReceivedID [3]=(ReceivedID [2] <5) | (ReceivedID [3] & gt;> 3);
ReceivedID [2]=(ReceivedID [1] <5) | (ReceivedID [2] & gt;> 3);
ReceivedID [1]=(ReceivedID [0] <5) | (ReceivedID [1] & gt;> 3);
ReceivedID [0]=ReceivedID [0] & gt;> 3;
}
for(i=0; i<4. I++)
{
Str1. The Format (" % 02 x, "ReceivedID [I]);
STR +=str1;
ID=STR;
}
DLG - & gt; M_list. SetItemText (JustnowItem, 4, STR);//ID information

DLG - & gt; M_list. SetItemText (JustnowItem, 6, "Extended");//

}
The else//standard frame
{
for(i=0; i<2; I++)
ReceivedID [I]=pCanObj [num] ID [I];
If (DLG - & gt; M_radioIDFormat)//CAN2.0 B format conversion to direct ID value
{

ReceivedID [1]=(ReceivedID [1] & gt;> 5) | (ReceivedID [0] <3);
ReceivedID [0]=ReceivedID [0] & gt;> 5;
}
for(i=0; i<2; I++)
{
Str1. The Format (" % 02 x, "ReceivedID [I]);
STR +=str1;//save the final ID
ID=STR;
}
DLG - & gt; M_list. SetItemText (JustnowItem, 4, STR);//ID information

DLG - & gt; M_list. SetItemText (JustnowItem, 6, "Standard");//


}
STR. The Format (" % d ", pCanObj [r]. Num DataLen);//the length information of 8 bytes
DLG - & gt; M_list. SetItemText (JustnowItem, 7, STR);

STR="";
If (ID!="0409")
{
For (I=0; i<(pCanObj [r]. Num DataLen); I++)/information/data
{
Str1. The Format (" % 02 x, "pCanObj [num]. Data [I]);
DATA [I]=str1;
STR +=str1;//STR final 8 bytes of data from STR "0 07 e 11 0 d 99, 95, 00 00"

}
}
The else
{

The Index [0] +=DATA [0].
The Index [1] +=DATA [1].
The Index [2] +=DATA [2].
The Index [3] +=DATA [3].
The Index [4] +=DATA [4].
The Index [5] +=DATA [5].
The Index [6] +=DATA [6].
The Index [7] +=DATA [7].
// calls the following code will generate interrupts
DLG - & gt; Range. Put_Item (COleVariant ((long), 1), COleVariant ((long), 1), COleVariant (Index [0]));
DLG - & gt; Range. Put_Item (COleVariant ((long), 1), COleVariant (2) (long), COleVariant (Index [1]));
DLG - & gt; Range. Put_Item (COleVariant ((long), 1), COleVariant ((long). 3), COleVariant (Index [2]));
DLG - & gt; Range. Put_Item (COleVariant ((long), 1), COleVariant (4) (long), COleVariant (Index [3]));
DLG - & gt; Range. Put_Item (COleVariant ((long), 1), COleVariant (5) (long), COleVariant (Index [4]));
DLG - & gt; Range. Put_Item (COleVariant ((long), 1), COleVariant ((long) 6), COleVariant (Index [5]));
DLG - & gt; Range. Put_Item (COleVariant ((long), 1), COleVariant (7) (long), COleVariant (Index [6]));
DLG - & gt; Range. Put_Item (COleVariant ((long), 1), COleVariant (8) (long), COleVariant (Index [7]));

}

DLG - & gt; M_list. SetItemText (JustnowItem, 8, STR);
DLG - & gt; M_list. Scroll (size);
/finished/receiving information list

}
}
Sleep (10);


If (StopFlag==1)
return 0;
}

Return 1;
}

CodePudding user response:

Thread not initialize the COM
Recommend the thread sends a message to the main process, main process to read and write operations,

CodePudding user response:

Generally see code feel no problem,
nullnullnullnullnull
  • Related