实例介绍
【实例简介】CCD通讯
【实例截图】
【核心代码】
// CCDView.cpp : implementation of the CCCDView class
//
#include "stdafx.h"
#include "CCD.h"
#include "SetDlg.h"
#include "CCDDoc.h"
#include "CCDView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define DEFSCALE 0.5
#define MAX 65535
#define MAXX 5000
#define DEFSIZE 50
#define MIDDATA 30000
/////////////////////////////////////////////////////////////////////////////
// CCCDView
IMPLEMENT_DYNCREATE(CCCDView, CScrollView)
BEGIN_MESSAGE_MAP(CCCDView, CScrollView)
//{{AFX_MSG_MAP(CCCDView)
ON_WM_TIMER()
ON_COMMAND(ID_START, OnStart)
ON_COMMAND(ID_PAUSE, OnPause)
ON_COMMAND(ID_STOP, OnStop)
ON_COMMAND(ID_SET, OnSet)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCCDView construction/destruction
CCCDView::CCCDView()
{
RESET=1;
pData1=NULL;
pData2=NULL;
CWinApp* pApp = AfxGetApp();
m_nBaseAddr=pApp->GetProfileInt("CCD","BaseAddr",0);
m_nPixelNum1=pApp->GetProfileInt("CCD","PixelNum1",1000);
m_nPixelNum2=pApp->GetProfileInt("CCD","PixelNum2",1000);
m_time=pApp->GetProfileInt("CCD","Time",500);
m_UserScale=pApp->GetProfileInt("CCD","UserScale",1);
m_ShowType=pApp->GetProfileInt("CCD","ShowType",0);
hMod=LoadLibrary("ADA11GH2-AT.dll");
if(hMod!=NULL)
pfunc=(CCD_DATA)GetProcAddress(hMod,"CCD_DataAcquisition");
else
{
MessageBox("Can't load dll function!\r\nPrograme will stop!","Warning");
exit(0);
}
// TODO: add construction code here
}
CCCDView::~CCCDView()
{
if(hMod!=NULL)
FreeLibrary(hMod);
CWinApp* pApp = AfxGetApp();
pApp->WriteProfileInt("CCD","BaseAddr",m_nBaseAddr);
pApp->WriteProfileInt("CCD","PixelNum1",m_nPixelNum1);
pApp->WriteProfileInt("CCD","PixelNum2",m_nPixelNum2);
pApp->WriteProfileInt("CCD","Time",m_time);
pApp->WriteProfileInt("CCD","UserScale",m_UserScale);
pApp->WriteProfileInt("CCD","ShowType",m_ShowType);
}
BOOL CCCDView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CCCDView drawing
void CCCDView::OnDraw(CDC* pDC)
{
CCCDDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if(m_nNum)
{
CRect rect;
GetClientRect(&rect);
int rectx=rect.Width();
int recty=rect.Height();
CPen pen1,pen2;
CPen *OldPen;
CString str;
pen1.CreatePen(PS_DOT,1,RGB(125,125,125));
pen2.CreatePen(PS_SOLID,1,RGB(0,0,255));
int i,j,k;
if(m_ShowType)
{
CSize sizeTotal;
sizeTotal.cx=rect.Width();
sizeTotal.cy=(m_nNum 2)*10;
SetScrollSizes(MM_TEXT, sizeTotal);
OldPen=pDC->SelectObject(&pen1);
for(i=1;i<m_nNum 1;i )
{
pDC->MoveTo(0,i*20);
pDC->LineTo(rect.Width(),i*20);
}
pDC->MoveTo(rect.Width()/4,0);
pDC->LineTo(rect.Width()/4,sizeTotal.cy);
pDC->MoveTo(rect.Width()/2,0);
pDC->LineTo(rect.Width()/2,sizeTotal.cy);
pDC->MoveTo(rect.Width()*3/4,0);
pDC->LineTo(rect.Width()*3/4,sizeTotal.cy);
pDC->SelectObject(&pen2);
pDC->TextOut(0,0,"测量次数");
pDC->TextOut(rect.Width()/4,0,"测量数值");
pDC->TextOut(rect.Width()/2,0,"测量次数");
pDC->TextOut(rect.Width()*3/4,0,"测量数值");
for(i=1;i<(m_nNum 1);i )
{
k=i%2 ? 0:rect.Width()/2;
j=(i 1)/2;
str.Format("%d",i);
pDC->TextOut(0 k,j*20,str);
str.Format("%d",m_pData[i-1]);
pDC->TextOut(rect.Width()/4 k,j*20,str);
}
pDC->SelectObject(OldPen);
}else
{
double defscale=(double)(rectx)/20/m_UserScale;
CSize sizeTotal;
sizeTotal.cx=((m_nNum*defscale rectx/20)>rect.Width() ? (m_nNum*defscale rectx/20):rect.Width());
sizeTotal.cy = rect.Height();
SetScrollSizes(MM_TEXT, sizeTotal);
// TODO: add draw code for native data here
int startx=rectx/20;
int starty=sizeTotal.cy-recty/20;
OldPen=pDC->SelectObject(&pen1);
j=sizeTotal.cy*20/recty;
k=(sizeTotal.cx*20)/rectx (sizeTotal.cx*20)%rectx*2;
double scaley=((double)(MAX*j))/(sizeTotal.cy*(j-1));
double scalex=((double)(sizeTotal.cx-startx)/m_nNum);
double stepx=(double)rectx/20;
double stepy=(double)recty/20;
for(i=1;i<j;i )
{
pDC->MoveTo(0,stepy*i);
pDC->LineTo(sizeTotal.cx,stepy*i);
str.Format("%d",(j-i-1)*MAX/(j-1));
pDC->TextOut(0,stepy*i,str);
}
for(i=1;i<k;i )
{
pDC->MoveTo(stepx*i,0);
pDC->LineTo(stepx*i,sizeTotal.cy);
str.Format("%d",(i-1)*MAXX/(k-1));
pDC->TextOut(stepx*i,starty,str);
}
pDC->SelectObject(&pen2);
pDC->MoveTo(startx,0);
pDC->LineTo(startx,starty);
pDC->LineTo(sizeTotal.cx,starty);
pDC->MoveTo(startx,starty-m_pData[0]*scaley);
double tempx,tempy;
for(i=0;i<m_nNum;i )
{
tempx=i*scalex;
tempx =startx;
tempy=starty-m_pData[i]/scaley;
pDC->LineTo(tempx,tempy);
}
pDC->SelectObject(OldPen);
}
}
// TODO: add draw code for native data here
}
void CCCDView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CSize sizeTotal;
// TODO: calculate the total size of this view
sizeTotal.cx = sizeTotal.cy = 100;
SetScrollSizes(MM_TEXT, sizeTotal);
}
/////////////////////////////////////////////////////////////////////////////
// CCCDView printing
BOOL CCCDView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CCCDView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CCCDView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CCCDView diagnostics
#ifdef _DEBUG
void CCCDView::AssertValid() const
{
CScrollView::AssertValid();
}
void CCCDView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CCCDDoc* CCCDView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCCDDoc)));
return (CCCDDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CCCDView message handlers
void CCCDView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(pfunc(m_nBaseAddr,pData1,pData2,m_nPixelNum1,m_nPixelNum2))
{
int index1=0;
int index2=0;
UINT i=0;
for(i=0;i<m_nPixelNum1&&pData1[i]>=MIDDATA;i );
index1=i;
for(i=0;i<m_nPixelNum2&&pData2[i]<=MIDDATA;i );
index2=i;
if(m_nNowIndex>=m_nMax)
{
m_nMax*=2;
int *pTemp=new int[m_nMax];
delete m_pData;
m_pData=pTemp;
}
m_pData[m_nNowIndex]=m_nPixelNum1-index1 index2;
m_nNowIndex ;
m_nNum ;
}
InvalidateRect(NULL);
CScrollView::OnTimer(nIDEvent);
}
void CCCDView::OnStart()
{
// TODO: Add your command handler code here
if(RESET)
{
m_nNowIndex=0;
m_nNum=0;
if(m_pData!=NULL)
delete m_pData;
m_pData=new int[DEFSIZE];
m_nMax=DEFSIZE;
if(pData1!=NULL)
delete pData1;
if(pData2!=NULL)
delete pData2;
if(m_nPixelNum1)
pData1=new short int[m_nPixelNum1];
if(m_nPixelNum2)
pData2=new short int[m_nPixelNum2];
}
SetTimer(1,m_time,NULL);
}
void CCCDView::OnPause()
{
// TODO: Add your command handler code here
KillTimer(1);
RESET=0;
}
void CCCDView::OnStop()
{
// TODO: Add your command handler code here
KillTimer(1);
RESET=1;
}
void CCCDView::OnSet()
{
// TODO: Add your command handler code here
CSetDlg dlg;
dlg.m_intertime=m_time;
char szbase[256];
sprintf(szbase,"%x",m_nBaseAddr);
dlg.m_nBaseAddr=szbase;
dlg.m_nNum1=m_nPixelNum1;
dlg.m_nNum2=m_nPixelNum2;
dlg.m_nENum=m_UserScale;
dlg.m_ShowType=m_ShowType;
if(dlg.DoModal()==IDOK)
{
sscanf(dlg.m_nBaseAddr,"%x",&m_nBaseAddr);
m_nPixelNum1=dlg.m_nNum1;
m_nPixelNum2=dlg.m_nNum2;
m_time=dlg.m_intertime;
m_UserScale=dlg.m_nENum;
m_ShowType=dlg.m_ShowType;
}
InvalidateRect(NULL);
}
好例子网口号:伸出你的我的手 — 分享!
相关软件
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明


网友评论
我要评论