|
//有数据进来,显示之
DWORD __stdcall Thread_USB_Read(LPVOID lpPara)
{
CUsbhidtestDlg *pDlg=(CUsbhidtestDlg *)lpPara;
//unsigned char receivebuf[100];
//unsigned long NumberOfBytesReaded;
if (pDlg->HidDev.write_errcount)//设备已丢失!::有效果,但是反应慢
{
pDlg->SetSend_false();
pDlg->Kill_Timer();
}
while(pDlg->usb_Thread!=NULL)
{
if ( pDlg->bExit) break;
BYTE str[65]={0};
DWORD len=0;
DWORD err,p_total;
CString cstr,sn,c,sz_info="";
UINT i;
UINT icount=0;
HJ_EVENT *pHJ;
for (i=0;i<65;i++) str[i]='\0';
if(pDlg->HidDev.ReadHid(str,&len,&err))
{
cstr="USB接收数据::\r\n";
if(len==65) len=64;//滤除最后一个字符
if ( (strcmp(pDlg->str_lastcmd,(char *)":I")==0)&&(str[0]==':' && str[1]=='I'))
{
sz_info="\r\n\r\n发现芯片:";
if (strncmp((char *)&str[2],(char *)"EF17",4)==0) sz_info+="Winbond W25Q128";
else
if (strncmp((char *)&str[2],(char *)"C816",4)==0) sz_info+="GD 25Q64";
sz_info+="\r\n设备ID号:";
sz_info+=(char *)&str[2];
///pDlg->GetDlgItem(IDC_EDIT1)->SetWindowText(sz_info);
// break;
}
if( (pDlg->LastCmd_index==3) && str[0]==':'&& str[1]=='b' )
{
pHJ=(HJ_EVENT *)&str[2];
p_total=pHJ->jh+(pHJ->hl<<16);
sz_info.Format("\r\n共有记录:%d条\r\n",p_total);
//(pDlg->GetDlgItem(IDC_EDIT1))->SetWindowText(cstr);
pDlg->LastCmd_index=0;
// break;
}
CButton *p;
p=(CButton *)pDlg->GetDlgItem(IDC_CHECK_BIN);
if(p->GetCheck())//16进制显示BCD
{
sn="";
for(i=0;i<len;i++)
{
c.Format(" %02X",(int)str[i]);
sn+=c;
icount++;
if (icount>=32)
{
icount=0;
p=(CButton *)pDlg->GetDlgItem(IDC_CHECK_RETURN);
if(p->GetCheck())
{
c="\r\n";
sn+=c;
}
}
}
cstr+=sn;
pDlg->g_rec_str+=sn;
}
else
{
cstr+=str;
pDlg->g_rec_str+=cstr;
}
p=(CButton *)pDlg->GetDlgItem(IDC_CHECK_PAUSE);
if(!p->GetCheck())
pDlg->GetDlgItem(IDC_EDIT1)->SetWindowText(cstr+sz_info);//GetDlgItem(IDC_EDIT_REC)->SetWindowText(pDlg->g_rec_str);
pDlg->PutReceive_Count();
//pDlg->AddToInfOut(cstr,TRUE,TRUE);
}
}
return 0;
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|