基本信息
源码名称:CCD通讯 示例源码(c++)
源码大小:0.43M
文件格式:.rar
开发语言:C/C++
更新时间:2018-01-18
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
CCD通讯
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); }