对模拟量输入的零点校正值及满量程对应的电压值进行输入。
1、在SenSet.h文件中添加代码
cpp
#include "BtnST.h"
#include "ShadeButtonST.h"
/
// SenSet dialog
class SenSet : public CDialog
{
// Construction
public:
SenSet(CWnd* pParent = NULL); // standard constructor
CFont m_font;
CString m_Path;
CString strFilePath;
int nSel;
CString nSel_str;
// Dialog Data
//{{AFX_DATA(SenSet)
enum { IDD = IDD_DIALOG_SEN_TEST };
CListCtrl m_IDC_LIST2;
CListBox m_IDC_LIST1;
CShadeButtonST m_bAdd_2;
CShadeButtonST m_bDel_2;
CShadeButtonST m_bParameter_2;
CShadeButtonST m_bReturn_2;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(SenSet)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(SenSet)
virtual BOOL OnInitDialog();
afx_msg void OnButton7();
afx_msg void OnSelchangeList1();
afx_msg void OnClickList2(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnButton1();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
2、在SenSet.cpp文件中添加代码
cpp
#include "stdafx.h"
#include "seal_pressure.h"
#include "SenSet.h"
#include "Data_2.h"
#include "PC60002K.H"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/
// SenSet dialog
SenSet::SenSet(CWnd* pParent /*=NULL*/)
: CDialog(SenSet::IDD, pParent)
{
m_font.CreateFont(-28,0,0,0,700,FALSE,FALSE,
0,134,OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
FF_SWISS,"楷体_GB2312");
TCHAR exeFullPath[MAX_PATH];
GetModuleFileName(NULL,exeFullPath,MAX_PATH);
m_Path = exeFullPath;
for(int i = m_Path.GetLength() - 1; i > 0 ; i --)
{
if(m_Path.GetAt(i) == '\\')
break;
}
SetCurrentDirectory(m_Path);
m_Path = m_Path.Left(i);
strFilePath= m_Path + "\\Test.ini";
nAddr_AD_2=0x110;
COMB_Data_AD_Number_2=(sizeof(COMB_Data_AD_2) / sizeof(COMB_Data_AD_2[1]));
}
void SenSet::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(SenSet)
DDX_Control(pDX, IDC_LIST2, m_IDC_LIST2);
DDX_Control(pDX, IDC_LIST1, m_IDC_LIST1);
DDX_Control(pDX, IDC_BUTTON1, m_bAdd_2);
DDX_Control(pDX, IDC_BUTTON2, m_bDel_2);
DDX_Control(pDX, IDC_BUTTON6, m_bParameter_2);
DDX_Control(pDX, IDC_BUTTON7, m_bReturn_2);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(SenSet, CDialog)
//{{AFX_MSG_MAP(SenSet)
ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
ON_LBN_SELCHANGE(IDC_LIST1, OnSelchangeList1)
ON_NOTIFY(NM_CLICK, IDC_LIST2, OnClickList2)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/
// SenSet message handlers
BOOL SenSet::OnInitDialog()
{
CDialog::OnInitDialog();
m_bAdd_2.SetShade(CShadeButtonST::SHS_HARDBUMP);
m_bDel_2.SetShade(CShadeButtonST::SHS_HARDBUMP);
m_bParameter_2.SetShade(CShadeButtonST::SHS_HARDBUMP);
m_bReturn_2.SetShade(CShadeButtonST::SHS_HARDBUMP);
DWORD dwExStyles = m_IDC_LIST2.GetExtendedStyle();
m_IDC_LIST2.SetExtendedStyle(
dwExStyles |
LVS_EX_GRIDLINES |
LVS_EX_FULLROWSELECT |
LVS_EX_FLATSB |
LVS_EX_ONECLICKACTIVATE
);
LVCOLUMN cloumn;
int i;
cloumn.mask = LVCF_TEXT|LVCF_WIDTH;
cloumn.pszText = "序号";
cloumn.cx =50;
i = m_IDC_LIST2.InsertColumn(0,&cloumn);
cloumn.mask = LVCF_TEXT|LVCF_WIDTH;
cloumn.pszText = "电压";
cloumn.cx =120;
i =m_IDC_LIST2.InsertColumn(1,&cloumn);
cloumn.pszText = "对应值";
cloumn.cx =120;
i = m_IDC_LIST2.InsertColumn(2,&cloumn);
for( i=0;i<COMB_Data_AD_Number_2;i++)
{
GetPrivateProfileString("AD输入",COMB_Data_AD_2[i],NULL,b_str_AD_2[i].GetBuffer(20),20,strFilePath);
if (b_str_AD_2[i]!="-1" )
{
// AD_2[i]=_ttoi(b_str_AD_2[i]);
m_IDC_LIST1.AddString(COMB_Data_AD_2[i]);
}
}
if( OpenDevice6K() != TRUE )
AfxMessageBox("Open device failed!");
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void SenSet::OnButton7()
{
EndDialog(IDD_DIALOG_BOA_TEST);
}
void SenSet::OnSelchangeList1()
{
m_bAdd_2.EnableWindow(true);
m_bParameter_2.EnableWindow(true);
nSel =m_IDC_LIST1.GetCurSel();
m_IDC_LIST1.GetText(nSel,nSel_str);
Sleep(500);
CString str;
str.Format("%d",nSel);
CString str6[16],str7[16],str8[16],str9[16];
GetPrivateProfileString("A/D设置",nSel_str+"零点电压",NULL,str6[16].GetBuffer(20),20,strFilePath);
GetPrivateProfileString("A/D设置",nSel_str+"零点数值",NULL,str7[16].GetBuffer(20),20,strFilePath);
GetPrivateProfileString("A/D设置",nSel_str+"量程电压",NULL,str8[16].GetBuffer(20),20,strFilePath);
GetPrivateProfileString("A/D设置",nSel_str+"量程数值",NULL,str9[16].GetBuffer(20),20,strFilePath);
m_IDC_LIST2.DeleteAllItems();
m_IDC_LIST2.InsertItem(0, _T("1"));
m_IDC_LIST2.SetItemText(0, 1,_T(str6[16]));
m_IDC_LIST2.SetItemText(0, 2,str7[16]);
m_IDC_LIST2.InsertItem(1, _T("2"));
m_IDC_LIST2.SetItemText(1, 1,str8[16]);
m_IDC_LIST2.SetItemText(1, 2,str9[16]);
// SetDlgItemText(IDC_STATIC99,str);
}
void SenSet::OnClickList2(NMHDR* pNMHDR, LRESULT* pResult)
{
m_bDel_2.EnableWindow(true);
*pResult = 0;
}
void SenSet::OnButton1()
{
CString str1,str2,str4,str5;
CString str6[16],str7[16],str8[16],str9[16];
GetDlgItemText(IDC_EDIT1,str1);
GetDlgItemText(IDC_EDIT2,str2);
GetDlgItemText(IDC_EDIT4,str4);
GetDlgItemText(IDC_EDIT5,str5);
WritePrivateProfileString("A/D设置",nSel_str+"零点电压",str1,strFilePath);
WritePrivateProfileString("A/D设置",nSel_str+"零点数值",str2,strFilePath);
WritePrivateProfileString("A/D设置",nSel_str+"量程电压",str4,strFilePath);
WritePrivateProfileString("A/D设置",nSel_str+"量程数值",str5,strFilePath);
Sleep(500);
GetPrivateProfileString("A/D设置",nSel_str+"零点电压",NULL,str6[16].GetBuffer(20),20,strFilePath);
GetPrivateProfileString("A/D设置",nSel_str+"零点数值",NULL,str7[16].GetBuffer(20),20,strFilePath);
GetPrivateProfileString("A/D设置",nSel_str+"量程电压",NULL,str8[16].GetBuffer(20),20,strFilePath);
GetPrivateProfileString("A/D设置",nSel_str+"量程数值",NULL,str9[16].GetBuffer(20),20,strFilePath);
Sleep(500);
m_IDC_LIST2.DeleteAllItems();
m_IDC_LIST2.InsertItem(0, _T("1"));
m_IDC_LIST2.SetItemText(0, 1,_T(str6[16]));
m_IDC_LIST2.SetItemText(0, 2,str7[16]);
// m_IDC_LIST2.DeleteAllItems();
m_IDC_LIST2.InsertItem(1, _T("2"));
m_IDC_LIST2.SetItemText(1, 1,str8[16]);
m_IDC_LIST2.SetItemText(1, 2,str9[16]);
}
运行程序