串口接收ov7620灰度值并在pc上显示图像vc6.0编程

    本文涉及的采用的技术要点:

1.mscomm控件串口通信

可以看看这篇:http://blog.csdn.net/tianhen791/article/details/6039315

2.用SetPixel()函数显示图像

 

 

具体方法如下:

   1.添加mscomm控件(百度谷歌搜索提供很多教程,以下同)

   2.串口的打开(包括初始化)

void CImageShowDlg::OnOpen() { code here m_Comm.SetCommPort(1); m_Comm.SetInputMode(1); m_Comm.SetSettings("115200,n,8,1"); m_Comm.SetRThreshold(1); m_Comm.SetInputLen(0); if(!m_Comm.GetPortOpen()) { m_Comm.SetPortOpen(TRUE); } else AfxMessageBox("Open The Serial Port1 Failurre!"); }

 

3.图像显示区的初始化

void CImageShowDlg::OnReset() { // TODO: Add your control notification handler code here CDC * pDC=GetDC(); int m_gray=255; unsigned long mcolor=RGB(m_gray,m_gray,m_gray); // TODO: add draw code for native data here for(int j=100;j<100+64;j++) for(int i=100;i<=100+107;i++) { pDC->SetPixel(i,j,mcolor); } }

4.串口接收并显示图像

void CImageShowDlg::OnComm() { // TODO: Add your control notification handler code here int nEvent; nEvent=m_Comm.GetCommEvent(); switch(nEvent) { case 2: { VARIANT data; data=m_Comm.GetInput(); //m_message=data.bstrVal; CDC * pDC=GetDC(); int m_gray; unsigned char * pdata=(unsigned char *)data.parray->pvData; // m_edit.SetWindowText(m_message); int k=0; // TODO: add draw code for native data here for(int j=100;j<100+64;j++) for(int i=100;i<=100+107;i++) { m_gray=*pdata++; unsigned long mcolor=RGB(m_gray,m_gray,m_gray); pDC->SetPixel(i,j,mcolor); } ReleaseDC(pDC); } } }

 

 

参考书:visual c++串口通信技术详解  李景峰  机械工业出版

            visual c++开发技术大全 明日科技

           visual c++程序开发范例宝典  (第二版 )P217  明日科技

 

你可能感兴趣的:(串口接收ov7620灰度值并在pc上显示图像vc6.0编程)