MFC工控项目实例之十五定时刷新PC6325A模拟量输入

承接专栏《MFC工控项目实例之十四模拟量信号名称从文件读写》

1、在BoardTest.h文件中添加代码

cpp 复制代码
class CBoardTest : public CDialog
{
public:
	short m_saveData[32];
	unsigned short m_cardAddr;
	CBoardTest(CWnd* pParent = NULL);   // standard constructor
	CButtonST   m_btnStart[16],m_btnStart_O[16];
	CWinThread* pThread; 
	bool isThreadBegin ;  //线程退出/执行控制
	void My_Func();
  static UINT My_TheradFunc(LPVOID lparam);
    

CString NO_Combox[16];
CString strTemp[16];//数据项名称
CString strRead[16];
int strReadId[16];
char strBuff[256];
CString	m_Path;
CString strFilePath;
...
protected:
unsigned short nAddr;

2、在BoardTest.cpp文件中添加代码

cpp 复制代码
UINT CBoardTest::My_TheradFunc(LPVOID lparam)//将窗口指针赋给无类型指针
 
{
 
     CBoardTest *dlg = (CBoardTest*)lparam;   //可以调用CBoardTest定义的类成员函数
     while (dlg->isThreadBegin)
	{
		dlg->My_Func(); //线程要执行的函数(调用CTheradtDlg定义的类成员函数)
	
	}
 return 0;
     
}

void CBoardTest::My_Func() //处理函数在这里写
{
	
int i;
	int b[16];
	CString	n[16];
    CString str1;
    int m1= rand() % 65537; 
    //int m1= 9; 
//	str1.Format("%d",m1);
//	SetDlgItemText(IDC_EDIT1,str1);
	for (i=0;i<16;i++)
	{
	//	b[i]=((m1>>i)& 1);
      b[i]=(( DI6408All(nAddr)>>i)& 1); 
    }
	for (i=0;i<16;i++)
	{
		n[i].Format("%d",b[i]);
    }
		for (i=0;i<16;i++)
		{
	if ( b[i] == 1)
	{
     m_btnStart[i].SetIcon(IDI_ICON_LedOn);	 
	}
	else  
	{
		m_btnStart[i].SetIcon(IDI_ICON_LedOff);
	}
		}
	
Sleep(500);
}




void CBoardTest::OnButton1() 
{
isThreadBegin  = false;            //停止线程执行
KillTimer(1); 
 Sleep(500);
EndDialog(IDD_DIALOG_BOA_TEST);	
}

void CBoardTest::OnTimer(UINT nIDEvent) 
{
// TODO: Add your message handler code here and/or call default
	if( nIDEvent == 1 )
	{
		//16通道,2 = -5000 -- 5000 mV采集
        AI6325AAllSingle(0X110, 2, m_saveData);
		CString tempStr;
		tempStr.Format("错误号: %d", GetDll_LastErrNO());
		SetWindowText(tempStr);        
		for(int i=0; i<16; i++)
		{
			tempStr.Format("%d mV", m_saveData[i]);
			SetDlgItemText(IDC_STATIC0+i, tempStr);
		}
		UpdateData(TRUE);
	}	

	CDialog::OnTimer(nIDEvent);
}

运行程序

相关推荐
励志不掉头发的内向程序员7 分钟前
STL库——string(类函数学习)
开发语言·c++
浮灯Foden2 小时前
算法-每日一题(DAY13)两数之和
开发语言·数据结构·c++·算法·leetcode·面试·散列表
淡海水3 小时前
【原理】Struct 和 Class 辨析
开发语言·c++·c#·struct·class
青草地溪水旁4 小时前
UML函数原型中stereotype的含义,有啥用?
c++·uml
青草地溪水旁4 小时前
UML函数原型中guard的含义,有啥用?
c++·uml
光头闪亮亮7 小时前
C++凡人修仙法典 - 宗门版-上
c++
光头闪亮亮7 小时前
C++凡人修仙法典 - 宗门版-下
c++
John_ToDebug7 小时前
Chromium base 库中的 Observer 模式实现:ObserverList 与 ObserverListThreadSafe 深度解析
c++·chrome·性能优化
科大饭桶7 小时前
C++入门自学Day11-- String, Vector, List 复习
c语言·开发语言·数据结构·c++·容器
点云SLAM8 小时前
C++中内存池(Memory Pool)详解和完整示例
开发语言·c++·内存管理·内存池·new/delete·malloc/free