📄 smallcomdlg.cpp
字号:
m_com.SetPortOpen(false);
m_ctrlOpenCom.SetWindowText("打开串口");
strStatus.Format("串口%d关闭!9600,n,8,1",vCom);
m_ctrlComStatus.SetWindowText(strStatus);
m_ComStateIcon.SetIcon(m_HiconOff);
m_ctrlTxLed.SetIcon(m_HiconLedOff);
m_ctrlRxLed.SetIcon(m_HiconLedOff);
}
}
}
void CSmallComDlg::OnSelendokCOMBOComSelect()
{
if(m_com.GetPortOpen())
{
m_bPortOpenFlag=true;
}
else
{
AfxMessageBox("没有发现此串口或被占用");
m_ctrlOpenCom.SetWindowText("打开串口");
m_ComStateIcon.SetIcon(m_HiconOff);
}
// TODO: Add your control notification handler code here // TODO: Add your control notification handler code here
}
void CSmallComDlg::OnBUTTONClearRxData()
{
m_strRxData.Empty();
UpdateData(FALSE);
}
void CSmallComDlg::OnCHECKAutoSend()
{
// TODO: Add your control notification handler code here
m_bAutoSend =! m_bAutoSend;
if(m_bAutoSend)
{
if(!m_com.GetPortOpen())
{
m_bAutoSend =!m_bAutoSend;
m_ctrlAutoSend.SetCheck(0);
AfxMessageBox("请先打开串口!");
}
else
{
SetTimer(1,m_nCycleTime,NULL);
}
}
else
{
KillTimer(1);
}
}
void CSmallComDlg::OnTimer(UINT nIDEvent)
{
CString TxCount;
switch(nIDEvent)
{
case 1:
//AfxMessageBox("sssssss");
if(m_com.GetPortOpen())
{
UpdateData(true);
if(m_ctrlSendHex.GetCheck())
{
CByteArray data;
int len = Str2Hex(m_strTxData,data);
VTxCount+=(long)len;
m_ctrlTxLed.SetIcon(m_HiconLedOn);
TxCount.Format("TX: %d",VTxCount);
m_ctrlTxCount.SetWindowText(TxCount);
m_com.SetOutput(COleVariant(data));
//AfxMessageBox("ddddd");
}
else
{
m_ctrlTxLed.SetIcon(m_HiconLedOn);
VTxCount += m_strTxData.GetLength();
TxCount.Format("TX: %d",VTxCount);
m_ctrlTxCount.SetWindowText(TxCount);
m_com.SetOutput(COleVariant(m_strTxData));
}
}
else
{
AfxMessageBox("请先打开串口!");
}
UpdateData(false);
}
CDialog::OnTimer(nIDEvent);
}
void CSmallComDlg::OnChangeEDITAutoSend()
{
if(m_ctrlAutoSend.GetCheck())
{
AfxMessageBox("请先关闭自动发送后,再打开!");
m_ctrlAutoSend.SetCheck(0);
CEdit* pEdit=(CEdit*)GetDlgItem(IDC_EDIT_AutoSend);
CString strText;
pEdit->GetWindowText(strText);
m_nCycleTime=atoi(strText);
m_ctrlAutoSend.SetCheck(1);
}
}
void CSmallComDlg::OnFileOpen()
{
UpdateData(true);
m_bHZKOpened =!m_bHZKOpened;
CFileDialog dlg(TRUE,0,0,NULL,"*.txt|*.DAT",this);
if(dlg.DoModal()==IDOK)
{
FilePathName =dlg.GetPathName();
}
m_strFilePathName = FilePathName;
// m_file.Open(LPCTSTR(m_strFilePathName),CFile::modeRead|CFile::typeBinary);
if(!m_file.Open(LPCTSTR(m_strFilePathName),CFile::modeRead|CFile::typeBinary))
{
AfxMessageBox("打开字库失败!");
m_bHZKOpened =!m_bHZKOpened;
return;
}
m_nFileBytes = m_file.GetLength();
UpdateData(false);
}
void CSmallComDlg::OnGuoTest()
{
char buffer[32];
register i,j,k;
int x=0,y=0,jj=0;
unsigned char qh,wh;
unsigned long location;
if(!m_bHZKOpened)
{
//===============扫描字库中的“河”字并显示=============
// TODO: Add your control notification handler code here
// 设备上下文
CPaintDC dc(this);
// 获取绘制坐标的文本框
CWnd* pWnd = GetDlgItem(IDC_STATIC_Display);
// 创建画笔对象
CPen* pPenBlue = new CPen;
// 蓝色画笔
pPenBlue->CreatePen(PS_SOLID,1,RGB(0,0,0));
// 指针
CDC* pDC = pWnd->GetDC();
pWnd->Invalidate();
pWnd->UpdateWindow();
CRect rect; // 绘制汉字显示的区域
//pDC->Rectangle(0,0,32,32);
for(i=0;i<16;i++)
for(j=0;j<16;j++)
{
rect.SetRect(j*8,i*8,j*8,i*8);
rect.InflateRect(4,4);
pDC->Ellipse(rect);
}
// 选择画笔
pDC->SelectObject(pPenBlue);
CBrush brush(RGB(0,255,0));
CBrush *old = pDC->SelectObject(&brush);
// pDC->setcl
// brush(RGB(0,255,0));
// *old = pDC->SelectObject(&brush);
//===============显示汉字图像=============
UpdateData();
if(m_strInputHz.IsEmpty())
{
AfxMessageBox(" 请输入汉字!");
return;
}
BYTE s[3];
lstrcpyn((char*)s,m_strInputHz,sizeof(s));
if(!IsDBCSLeadByte(*s))
{
AfxMessageBox("请输入有效汉字!");
return;
}
//AfxMessageBox(*s);
qh=*s-0xa0;
wh=*(s+1)-0xa0;
location=(94*(qh-1)+(wh-1))*32L;
m_file.Seek(location,CFile::begin);
m_file.Read(buffer,32);
//pWnd->Invalidate();
// pWnd->UpdateWindow();
for(i=0;i<16;i++)
for(j=0;j<2;j++)
for(k=0;k<8;k++)
if(((buffer[i*2+j]>>(7-k))&0x1)!=NULL)
//pDC->SetPixel(x+8*j+k,y+i,255);
// for(i=0;i<8;i++)
// for(j=0;j<8;j++)
{
rect.SetRect((x+8*j+k)*8,(y+i)*8,(x+8*j+k)*8,(y+i)*8);
rect.InflateRect(4,4);
pDC->Ellipse(rect);
}
// pDC->SelectObject(old);
x+=16;
UpdateData(true);
m_FLocation=location;
m_nQh=qh;
m_nWh=wh;
UpdateData(false);
}
else
{
AfxMessageBox("请先打开汉字库!");
return;
}
}
unsigned int location=80000;
//bool m_bStop=false;
void CSmallComDlg::OnZkTest()
{
// TODO: Add your control notification handler code here
//===============扫描字库并显示=============
//location为所要显示的汉字在字库中位置
long i;
int j=0;
// m_bStop = !m_bStop;
// if(m_bStop)
// {
if(!m_bHZKOpened)
{
while(j<10)
{
UpdateData(TRUE);
m_FLocation=location;
UpdateData(FALSE);
ShowHanZi(location);
for(i=0;i<59999999;i++)
;
location+=32;
j++;
// }
}
// MessageBox("硬件汉字库测试成功!", "恭喜你!" , MB_ICONINFORMATION | MB_OK);
}
else
{
AfxMessageBox("请先打开汉字库!");
return;
}
}
void CSmallComDlg::ShowHanZi(unsigned long location)
{
char ShowBuffer[32];
register i,j,k;
int x=0,y=0;
CPaintDC dc(this);
// 获取绘制坐标的文本框
CWnd* pWnd = GetDlgItem(IDC_STATIC_Display);
// 创建画笔对象
CPen* pPenBlue = new CPen;
// 蓝色画笔
pPenBlue->CreatePen(PS_SOLID,1,RGB(0,0,0));
// 指针
CDC* pDC = pWnd->GetDC();
pWnd->Invalidate();
pWnd->UpdateWindow();
CRect rect;
for(i=0;i<16;i++)
for(j=0;j<16;j++)
{
rect.SetRect(j*8,i*8,j*8,i*8);
rect.InflateRect(4,4);
pDC->Ellipse(rect);
}
// 绘制汉字显示的区域
// pDC->Rectangle(0,0,32,32);
// 选择画笔
// pDC->SelectObject(pPenBlue);
// pDC->SelectObject(pPenBlue);
CBrush brush(RGB(0,255,0));
CBrush *old = pDC->SelectObject(&brush);
m_file.Seek(location,CFile::begin);
m_file.Read(ShowBuffer,32);
for(i=0;i<16;i++)
for(j=0;j<2;j++)
for(k=0;k<8;k++)
if(((ShowBuffer[i*2+j]>>(7-k))&0x1)!=NULL)
{
rect.SetRect((x+8*j+k)*8,(y+i)*8,(x+8*j+k)*8,(y+i)*8);
rect.InflateRect(4,4);
pDC->Ellipse(rect);
}
delete pPenBlue;
}
char CSmallComDlg::HexChar(char c)
{
if((c>='0')&&(c<='9'))
return c-0x30;
else if((c>='A')&&(c<='F'))
return c-'A'+10;
else if((c>='a')&&(c<='f'))
return c-'a'+10;
else
return 0x10;
}
int CSmallComDlg::Str2Hex(CString str, CByteArray &senddata)
{
int hexdata,lowhexdata;
int hexdatalen=0;
int len=str.GetLength();
senddata.SetSize(len/2);
for(int i=0;i<len;)
{
char lstr,hstr=str[i];
if(hstr==' ')
{
i++;
continue;
}
i++;
if(i>=len)
break;
lstr=str[i];
hexdata=HexChar(hstr);
lowhexdata=HexChar(lstr);
if((hexdata==16)||(lowhexdata==16))
break;
else
hexdata=hexdata*16+lowhexdata;
i++;
senddata[hexdatalen]=(char)hexdata;
hexdatalen++;
}
senddata.SetSize(hexdatalen);
return hexdatalen;
}
void CSmallComDlg::OnBUTTONCLRCount()
{
CString TxCount,RxCount;
VTxCount = 0;
VRxCount = 0;
TxCount.Format("TX: %d",VTxCount);
m_ctrlTxCount.SetWindowText(TxCount);
RxCount.Format("RX: %d",VRxCount);
m_ctrlRxCount.SetWindowText(RxCount);
UpdateData(true);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -