承接专栏《MFC工控项目实例之十九手动测试界面输出信号切换》
根据板卡设置界面组合框选项设定的AD输入信号,通过读取文件中保存的键值,用定时器实时显示模拟量输入数值。
1、在Data_1.h文件中添加代码
CString COMB_Data_AD_1[]={"AD输入1","AD输入2","AD输入3","AD输入4","AD输入5","AD输入6","AD输入7","AD输入8","AD输入9","AD输入10","AD输入11","AD输入12","AD输入13","AD输入14","AD输入15","AD输入16"};
int COMB_Data_AD_Number_1;
unsigned char b_AD_1[16];
CString b_str_AD_1[16];
unsigned short AD_1[16];
2、在JogTest.cpp中添加代码
BOOL CJogTest::OnInitDialog()
{CDialog::OnInitDialog();...for( i=0;i<=COMB_Data_AD_Number_1;i++){GetPrivateProfileString("AD输入",COMB_Data_AD_1[i],NULL,b_str_AD_1[i].GetBuffer(20),20,strFilePath); AD_1[i]=_ttoi(b_str_AD_1[i]);}SetTimer(1,500,NULL);...
}void CJogTest::OnTimer(UINT nIDEvent)
{
if( nIDEvent == 1 ){//16通道,2 = -5000 -- 5000 mV采集AI6325AAllSingle(nAddr_AD_1, 2, m_saveData_AD_1);CString tempStr;CString str[30];tempStr.Format("%d",m_saveData_AD_1[AD_1[0]]);for ( int i=0 ; i<4 ; i++){ GetDlgItem(m_nCounterID[i])->SetFont(&m_font);str[i]=tempStr.Mid(i,1);SetDlgItemText(m_nCounterID[i],str[i]);}}CDialog::OnTimer(nIDEvent);}