📄 isp1581_demodlg.cpp
字号:
m_BulkWrite.repeattimes=m_nEditWriteRepeatTimes;
m_combo_bulkwritepipe.GetLBText(m_combo_bulkwritepipe.GetCurSel(),pipename);
strcpy(m_BulkWrite.pipe_name,(LPCTSTR)pipename);
m_writetransfer_info.bytecount=0;
m_writetransfer_info.buffersize=m_nEditWriteBufferSize;
m_writetransfer_info.curspeed=0;
m_writetransfer_info.maxspeed=0;
m_writetransfer_info.averspeed=0;
m_writetransfer_info.repeattimes=m_nEditWriteRepeatTimes;
m_writetransfer_info.timecount.hour=0;
m_writetransfer_info.timecount.minute=0;
m_writetransfer_info.timecount.second=0;
m_sStaticWriteTimeCount="00:00:00";
UpdateData(false);
EnableButton(false,false,false,true);
EnableEdit(false,false,false,false);
m_starttime=timeGetTime();
SetTimer(2,1000,NULL);
CWinThread * wt = AfxBeginThread(
BulkWritePipe, // thread function
&m_BulkWrite); // argument to thread function
m_BulkWrite.hThread=wt->m_hThread;
}
void CISP1581_demoDlg::OnButtonWritestop()
{
// TODO: Add your control notification handler code here
m_BulkWrite.bInThread=FALSE;
EnableButton(true,false,true,false);
EnableEdit(true,true,true,true);
KillTimer(1);
KillTimer(2);
m_calreadtime.bInThread=FALSE;
m_calwritetime.bInThread=FALSE;
}
int CISP1581_demoDlg::CheckBoard()
{
m_ControlIn.testDlg=this;
CWinThread * wt = AfxBeginThread(
ControlIn, // thread function
&m_ControlIn); // argument to thread function
return 0;
}
void CISP1581_demoDlg::EnableButton(BOOL readstart, BOOL readstop, BOOL writestart, BOOL writestop)
{
GetDlgItem(IDC_BUTTON_READSTART)->EnableWindow(readstart);
GetDlgItem(IDC_BUTTON_READSTOP)->EnableWindow(readstop);
GetDlgItem(IDC_BUTTON_WRITESTART)->EnableWindow(writestart);
GetDlgItem(IDC_BUTTON_WRITESTOP)->EnableWindow(writestop);
}
void CISP1581_demoDlg::InsertList()
{
int num=m_combo_bulkreadpipe.AddString("PIPE02");
m_combo_bulkreadpipe.SetItemData(num,2);
num=m_combo_bulkwritepipe.AddString("PIPE03");
m_combo_bulkwritepipe.SetItemData(num,3);
m_combo_bulkreadpipe.SetCurSel(0);
m_combo_bulkwritepipe.SetCurSel(0);
}
LRESULT CISP1581_demoDlg::OnUpdateMessage(WPARAM wParam, LPARAM lParam)
{
DWORD lasttime=(DWORD)lParam;
DWORD curtime=timeGetTime();
float tmp;
unsigned long bytecount;
UpdateData(true);
switch(wParam)
{
case 1:
bytecount=m_readtransfer_info.bytecount;
m_sStaticReadByteCount.Format("%d",bytecount);
tmp=(float)m_readtransfer_info.buffersize/(float)(curtime-lasttime);
m_sStaticCurReadSpeed.Format("%.1f",tmp);
m_readtransfer_info.curspeed=tmp;
if(tmp>m_readtransfer_info.maxspeed)
{
m_readtransfer_info.maxspeed=tmp;
m_sStaticMaxReadSpeed.Format("%.1f",tmp);
}
tmp=(float)bytecount/(float)(curtime-m_starttime);
m_sStaticAverReadSpeed.Format("%.1f",tmp);
m_readtransfer_info.averspeed=tmp;
break;
case 2:
bytecount=m_writetransfer_info.bytecount;
m_sStaticWriteByteCount.Format("%d",bytecount);
tmp=(float)m_writetransfer_info.buffersize/(float)(curtime-lasttime);
m_sStaticWriteCurSpeed.Format("%.1f",tmp);
m_writetransfer_info.curspeed=tmp;
if(tmp>m_writetransfer_info.maxspeed)
{
m_writetransfer_info.maxspeed=tmp;
m_sStaticMaxWriteSpeed.Format("%.1f",tmp);
}
tmp=(float)bytecount/(float)(curtime-m_starttime);
m_sStaticAverWriteSpeed.Format("%.1f",tmp);
m_writetransfer_info.averspeed=tmp;
break;
case 3:
break;
}
UpdateData(false);
return TRUE;
}
LRESULT CISP1581_demoDlg::OnCalTimeMessage(WPARAM wParam, LPARAM lParam)
{
if(wParam==1)
{
CalReadTime();
}
if(wParam==2)
{
CalWriteTime();
}
return TRUE;
}
void CISP1581_demoDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
int bytecount;
CString readbytecount;
CString writebytecount;
switch(nIDEvent)
{
case 1:
if((m_readtransfer_info.timecount.second+=1)>59)
{
m_readtransfer_info.timecount.second=0;
if((m_readtransfer_info.timecount.minute+=1)>59)
{
m_readtransfer_info.timecount.minute=0;
m_readtransfer_info.timecount.hour+=1;
}
}
bytecount=m_readtransfer_info.bytecount;
readbytecount.Format("%d",bytecount);
((CStatic*)GetDlgItem(IDC_STATIC_READBYTECOUNT))->SetWindowText(readbytecount);
UpdateData(true);
m_sStaticReadTimeCount.Format("%d:%d:%d",m_readtransfer_info.timecount.hour,
m_readtransfer_info.timecount.minute,m_readtransfer_info.timecount.second);
if(m_readtransfer_info.timecount.hour<10)
m_sStaticReadTimeCount.Insert(0,"0");
if(m_readtransfer_info.timecount.minute<10)
m_sStaticReadTimeCount.Insert(3,"0");
if(m_readtransfer_info.timecount.second<10)
m_sStaticReadTimeCount.Insert(6,"0");
UpdateData(false);
if(m_BulkRead.bInThread==FALSE)
KillTimer(1);
break;
case 2:
if((m_writetransfer_info.timecount.second+=1)>59)
{
m_writetransfer_info.timecount.second=0;
if((m_writetransfer_info.timecount.minute+=1)>59)
{
m_writetransfer_info.timecount.minute=0;
m_writetransfer_info.timecount.hour+=1;
}
}
bytecount=m_writetransfer_info.bytecount;
writebytecount.Format("%d",bytecount);
((CStatic*)GetDlgItem(IDC_STATIC_WRITEBYTECOUNT))->SetWindowText(writebytecount);
UpdateData(true);
m_sStaticWriteTimeCount.Format("%d:%d:%d",m_writetransfer_info.timecount.hour,
m_writetransfer_info.timecount.minute,m_writetransfer_info.timecount.second);
if(m_writetransfer_info.timecount.hour<10)
m_sStaticWriteTimeCount.Insert(0,"0");
if(m_writetransfer_info.timecount.minute<10)
m_sStaticWriteTimeCount.Insert(3,"0");
if(m_writetransfer_info.timecount.second<10)
m_sStaticWriteTimeCount.Insert(6,"0");
UpdateData(false);
if(m_BulkWrite.bInThread==FALSE)
KillTimer(2);
break;
}
CDialog::OnTimer(nIDEvent);
}
void CISP1581_demoDlg::EnableEdit(BOOL bulkreadsize,BOOL bulkreadrepeattimes,
BOOL bulkwritesize,BOOL bulkwriterepeattimes)
{
GetDlgItem(IDC_EDIT_READBUFFERSIZE)->EnableWindow(bulkreadsize);
GetDlgItem(IDC_EDIT_READREPEATTIMES)->EnableWindow(bulkreadrepeattimes);
GetDlgItem(IDC_EDIT_WRITEBUFFERSIZE)->EnableWindow(bulkwritesize);
GetDlgItem(IDC_EDIT_WRITEREPEATTIMES)->EnableWindow(bulkwriterepeattimes);
}
BOOL CISP1581_demoDlg::OnDeviceChange( UINT nEventType, DWORD dwData )
{
KillTimer(1);
KillTimer(2);
m_calreadtime.bInThread=FALSE;
m_calwritetime.bInThread=FALSE;
m_BulkRead.bInThread=FALSE;
m_BulkWrite.bInThread=FALSE;
Sleep(200);
ResetList();
CheckBoard();
return 0;
}
void CISP1581_demoDlg::ResetList()
{
m_combo_bulkreadpipe.ResetContent();
m_combo_bulkwritepipe.ResetContent();
}
LRESULT CISP1581_demoDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
if(message==WM_DEVICECHANGE)
return FALSE;
return CDialog::DefWindowProc(message, wParam, lParam);
}
BOOL CISP1581_demoDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(pMsg->message==WM_DEVICECHANGE)
return FALSE;
return CDialog::PreTranslateMessage(pMsg);
}
void CISP1581_demoDlg::OnChangeEditReadbuffersize()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
UpdateData(true);
if(m_nEditReadBufferSize>65536)
m_nEditReadBufferSize=65536;
if(m_nEditReadBufferSize<=0)
m_nEditReadBufferSize=1;
UpdateData(false);
}
void CISP1581_demoDlg::OnChangeEditWritebuffersize()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
UpdateData(true);
if(m_nEditWriteBufferSize>65536)
m_nEditWriteBufferSize=65536;
if(m_nEditWriteBufferSize<=0)
m_nEditWriteBufferSize=1;
UpdateData(false);
}
void CISP1581_demoDlg::CalReadTime()
{
if((m_readtransfer_info.timecount.second+=1)>59)
{
m_readtransfer_info.timecount.second=0;
if((m_readtransfer_info.timecount.minute+=1)>59)
{
m_readtransfer_info.timecount.minute=0;
m_readtransfer_info.timecount.hour+=1;
}
}
CString readtimecount;
CStatic *readstatic=(CStatic*)GetDlgItem(IDC_STATIC_READTIMECOUNT);
readtimecount.Format("%d:%d:%d",m_readtransfer_info.timecount.hour,
m_readtransfer_info.timecount.minute,m_readtransfer_info.timecount.second);
if(m_readtransfer_info.timecount.hour<10)
readtimecount.Insert(0,"0");
if(m_readtransfer_info.timecount.minute<10)
readtimecount.Insert(3,"0");
if(m_readtransfer_info.timecount.second<10)
readtimecount.Insert(6,"0");
readstatic->SetWindowText(readtimecount);
}
void CISP1581_demoDlg::CalWriteTime()
{
if((m_writetransfer_info.timecount.second+=1)>59)
{
m_writetransfer_info.timecount.second=0;
if((m_writetransfer_info.timecount.minute+=1)>59)
{
m_writetransfer_info.timecount.minute=0;
m_writetransfer_info.timecount.hour+=1;
}
}
CString writetimecount;
CStatic *writestatic=(CStatic*)GetDlgItem(IDC_STATIC_WRITETIMECOUNT);
writetimecount.Format("%d:%d:%d",m_writetransfer_info.timecount.hour,
m_writetransfer_info.timecount.minute,m_writetransfer_info.timecount.second);
if(m_writetransfer_info.timecount.hour<10)
writetimecount.Insert(0,"0");
if(m_writetransfer_info.timecount.minute<10)
writetimecount.Insert(3,"0");
if(m_writetransfer_info.timecount.second<10)
writetimecount.Insert(6,"0");
writestatic->SetWindowText(writetimecount);
}
void CISP1581_demoDlg::UpdateReadInfo(DWORD lParam)
{
DWORD lasttime=lParam;
DWORD curtime=timeGetTime();
float tmp;
unsigned long bytecount;
CString readbytecount,curreadspeed,maxreadspeed,averreadspeed;
bytecount=m_readtransfer_info.bytecount;
readbytecount.Format("%d",bytecount);
((CStatic*)GetDlgItem(IDC_STATIC_READBYTECOUNT))->SetWindowText(readbytecount);
//tmp=(float)m_readtransfer_info.buffersize/(float)(curtime-lasttime);
tmp=(float)m_readtransfer_info.nreadbytes/(float)(curtime-lasttime);
curreadspeed.Format("%.1f",tmp);
((CStatic*)GetDlgItem(IDC_STATIC_CURREADSPEED))->SetWindowText(curreadspeed);
m_readtransfer_info.curspeed=tmp;
if(tmp>m_readtransfer_info.maxspeed)
{
m_readtransfer_info.maxspeed=tmp;
maxreadspeed.Format("%.1f",tmp);
((CStatic*)GetDlgItem(IDC_STATIC_MAXREADSPEED))->SetWindowText(maxreadspeed);
}
tmp=(float)bytecount/(float)(curtime-m_starttime);
averreadspeed.Format("%.1f",tmp);
((CStatic*)GetDlgItem(IDC_STATIC_AVERREADSPEED))->SetWindowText(averreadspeed);
m_readtransfer_info.averspeed=tmp;
}
void CISP1581_demoDlg::UpdateWriteInfo(DWORD lParam)
{
DWORD lasttime=lParam;
DWORD curtime=timeGetTime();
float tmp;
unsigned long bytecount;
CString writebytecount,curwritespeed,maxwritespeed,averwritespeed;
bytecount=m_writetransfer_info.bytecount;
writebytecount.Format("%d",bytecount);
((CStatic*)GetDlgItem(IDC_STATIC_WRITEBYTECOUNT))->SetWindowText(writebytecount);
tmp=(float)m_writetransfer_info.nwritebytes/(float)(curtime-lasttime);
curwritespeed.Format("%.1f",tmp);
((CStatic*)GetDlgItem(IDC_STATIC_WRITECURSPEED))->SetWindowText(curwritespeed);
m_writetransfer_info.curspeed=tmp;
if(tmp>m_writetransfer_info.maxspeed)
{
m_writetransfer_info.maxspeed=tmp;
maxwritespeed.Format("%.1f",tmp);
((CStatic*)GetDlgItem(IDC_STATIC_MAXWRITESPEED))->SetWindowText(maxwritespeed);
}
tmp=(float)bytecount/(float)(curtime-m_starttime);
averwritespeed.Format("%.1f",tmp);
((CStatic*)GetDlgItem(IDC_STATIC_AVERWRITESPEED))->SetWindowText(averwritespeed);
m_writetransfer_info.averspeed=tmp;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -