⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addemoview.cpp

📁 我们可以采用两种编程方法,一种是自己编写控制各种寄存器代码进行数据的采集和输出,另外一种就是利用他封装的DLL的方法访问相应的函数进行完成.为了节省时间提高开发效率,当然使用第二种方法了
💻 CPP
字号:
// ADDemoView.cpp : implementation of the CADDemoView class
//

#include "stdafx.h"
#include "ADDemo.h"

#include "ADDemoDoc.h"
#include "ADDemoView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CADDemoView

IMPLEMENT_DYNCREATE(CADDemoView, CView)

BEGIN_MESSAGE_MAP(CADDemoView, CView)
	//{{AFX_MSG_MAP(CADDemoView)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CADDemoView construction/destruction

CADDemoView::CADDemoView()
{
	// TODO: add construction code here
	nVal = 0;
	m_pThread = NULL;
	DriverHandle = (LONG)NULL;
}

CADDemoView::~CADDemoView()
{
}

BOOL CADDemoView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CADDemoView drawing

void CADDemoView::OnDraw(CDC* pDC)
{
	CADDemoDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CADDemoView printing

BOOL CADDemoView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CADDemoView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CADDemoView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CADDemoView diagnostics

#ifdef _DEBUG
void CADDemoView::AssertValid() const
{
	CView::AssertValid();
}

void CADDemoView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CADDemoDoc* CADDemoView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CADDemoDoc)));
	return (CADDemoDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CADDemoView message handlers

UINT WINAPI CADDemoView::Main_Thread_AD(LPVOID pParam)//AD线程
{
	CADDemoView * pView=(CADDemoView *)pParam;
	while(1)
	{ 
		pView->ptDeviceReadADByte();
		pView->nVal++; 
		pView->ShowMsg(); 
	}
	return 0;
}

void CADDemoView::OnInitialUpdate() 
{
	CView::OnInitialUpdate();
	
	// TODO: Add your specialized code here and/or call the base class
	m_Info = new tagSYSTEMSTATE[32]; 
	for(int i=0;i<32;i++)
	{  
		m_Info[i].fState = 0.00f;
		m_Info[i].bState = FALSE;
	}
	 
	unsigned int nDummy;
	m_pThread=(HANDLE) _beginthreadex(NULL,0,Main_Thread_AD,this,CREATE_SUSPENDED,&nDummy);//开辟DI线程 
	
	if (!m_pThread) 
		TRACE(_T(" Couldn't start a  thread\n")); 
	else
		ResumeThread(m_pThread); 
}



void CADDemoView::ptDeviceReadADByte()
{	
	USHORT      gwChannel = 0;                      // input channel 
	float       gwValue; 	
	SHORT       gnNumOfDevices; 
	static      PT_AIConfig     ptAIConfig;     // structure for AIConfig table
	static      PT_AIVoltageIn  ptAIVoltageIn;  // structure for AIVoltageIn table
	static      PT_DeviceGetFeatures  ptDevFeatures;
	static      DEVFEATURES     DevFeatures;    // structure for device features
	
	gnNumOfDevices = 0; 
	DRV_DeviceOpen(gnNumOfDevices,//板号0;
		(LONG far *)&DriverHandle);
	
	ptDevFeatures.buffer = (LPDEVFEATURES)&DevFeatures;
	ptDevFeatures.size = sizeof(DEVFEATURES);
	DRV_DeviceGetFeatures(DriverHandle,//句标市柄
		(LPT_DeviceGetFeatures)&ptDevFeatures); 
	for(gwChannel = 0; gwChannel < 32;gwChannel ++)
	{
		Sleep(1);
		ptAIVoltageIn.chan = gwChannel;
		ptAIVoltageIn.gain = 0;
		ptAIVoltageIn.TrigMode = 0;               // internal trigger
		ptAIVoltageIn.voltage = (FLOAT far *)&gwValue;		
		DRV_AIVoltageIn(DriverHandle,(LPT_AIVoltageIn)&ptAIVoltageIn);  
		m_Info[gwChannel].fState = gwValue; 		
	}
	
	DRV_DeviceClose((LONG far *)&DriverHandle);
}



void CADDemoView::ShowMsg()
{
	CDC *pDC;
	pDC = GetDC();
	CRect rect;
	GetClientRect(&rect);
	CString strText;
	CBrush pNewBrush,*pOldBrush;
	pNewBrush.CreateSolidBrush(RGB(128,128,255));
	pOldBrush=pDC->SelectObject(&pNewBrush);
	pDC->FillRect(&rect,&pNewBrush);	
	COLORREF *oldCol;
	oldCol=(COLORREF *)pDC->SetTextColor(RGB(255,0,0));
	pDC->SetBkColor(RGB(128,128,255));
	pDC->TextOut(10,10,"采集模拟点显示信息:");
	strText.Format("线程采集程序运行了%d次",nVal);
	pDC->TextOut(10,35,strText);
	for(int i=0;i<32;i++)
	{
		strText.Format("第%.2d个结点的数据是:%.2f",i+1,m_Info[i].fState);
		int nHeight= (i/4)*25;
		int nWidth = (i%4)*200; 
		pDC->TextOut(10+nWidth,70+nHeight,strText);
	}
	pDC->SelectObject(&oldCol);
	pDC->SelectObject(&pOldBrush);
	pNewBrush.DeleteObject(); 
	pDC->DeleteDC(); 
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -