本文主要是介绍MFC读取PC6408板卡输入信号实例,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
本程序基于前期我的博客文章《MFC用信号灯模拟工控机数字量输入信号实时采集实例(源码下载》
1、在TheradDlg.h中相关代码
...
private:unsigned short nAddr;
...
TheradDlg.cpp中相关代码
#include "pc60002k.h"BOOL CTheradDlg::OnInitDialog()
{
...
nAddr = 0x100; //设置板卡基地址if( OpenDevice6K() != TRUE )AfxMessageBox("Open device failed!");
...
}
void CTheradDlg::My_Func() //处理函数在这里写
{int i;int b[16];CString n[16];CString str1;str1.Format("开关量输入状态%d",DI6408All(nAddr));SetDlgItemText(IDC_EDIT1,str1);for (i=0;i<16;i++){b[i]=(( DI6408All(nAddr)>>i)& 1);}for (i=0;i<16;i++){n[i].Format("%d",b[i]);}SetDlgItemText(IDC_EDIT2, n[15]);SetDlgItemText(IDC_EDIT3, n[14]);SetDlgItemText(IDC_EDIT4, n[13]);SetDlgItemText(IDC_EDIT5, n[12]);SetDlgItemText(IDC_EDIT6, n[11]);SetDlgItemText(IDC_EDIT7, n[10]);SetDlgItemText(IDC_EDIT8, n[9]);SetDlgItemText(IDC_EDIT9, n[8]);SetDlgItemText(IDC_EDIT10, n[7]);SetDlgItemText(IDC_EDIT11, n[6]);SetDlgItemText(IDC_EDIT12, n[5]);SetDlgItemText(IDC_EDIT13, n[4]);SetDlgItemText(IDC_EDIT14, n[3]);SetDlgItemText(IDC_EDIT15, n[2]);SetDlgItemText(IDC_EDIT16, n[1]);SetDlgItemText(IDC_EDIT17, n[0]); 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(1000);
}
这篇关于MFC读取PC6408板卡输入信号实例的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!