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);
}

运行程序

相关推荐
C+-C资深大佬41 分钟前
C++风格的命名转换
开发语言·c++
No0d1es43 分钟前
2025年粤港澳青少年信息学创新大赛 C++小学组复赛真题
开发语言·c++
点云SLAM1 小时前
C++内存泄漏检测之手动记录法(Manual Memory Tracking)
开发语言·c++·策略模式·内存泄漏检测·c++实战·new / delete
好评1241 小时前
【C++】二叉搜索树(BST):从原理到实现
数据结构·c++·二叉树·二叉搜索树
zylyehuo1 小时前
error: no matching function for call to ‘ros::NodeHandle::param(const char [11], std::string&, const char [34])’
c++·ros1
星火开发设计2 小时前
C++ 函数定义与调用:程序模块化的第一步
java·开发语言·c++·学习·函数·知识
天赐学c语言2 小时前
1.20 - x的平方根 && vector的扩容机制以及删除元素是否会释放内存
c++·算法·leecode
CC.GG2 小时前
【C++】用哈希表封装myunordered_map和 myunordered_set
java·c++·散列表
xiaoye-duck4 小时前
C++ string 类使用超全攻略(上):创建、遍历及容量操作深度解析
c++·stl
csdn_aspnet4 小时前
C++跨平台开发,分享一些用C++实现多平台兼容的工程难题与解决方案
c++