// 87k_di_cntDlg.cpp : implementation file // #include "stdafx.h" #include "87k_di_cnt.h" #include "87k_di_cntDlg.h" #include "PACSDK.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // CMy87k_di_cntDlg dialog CMy87k_di_cntDlg::CMy87k_di_cntDlg(CWnd* pParent /*=NULL*/) : CDialog(CMy87k_di_cntDlg::IDD, pParent) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CMy87k_di_cntDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Control(pDX, IDC_COMBO1, cmbSlot); DDX_Control(pDX, IDC_EDIT1, txtChannel); DDX_Control(pDX, IDC_EDIT2, txtDIValue); DDX_Control(pDX, IDC_BUTTON1, btnRead); } BEGIN_MESSAGE_MAP(CMy87k_di_cntDlg, CDialog) #if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP) ON_WM_SIZE() #endif //}}AFX_MSG_MAP ON_BN_CLICKED(IDC_BUTTON1, &CMy87k_di_cntDlg::OnBnClickedButton1) ON_BN_CLICKED(IDC_BUTTON2, &CMy87k_di_cntDlg::OnBnClickedButton2) ON_BN_CLICKED(IDC_BUTTON3, &CMy87k_di_cntDlg::OnBnClickedButton3) ON_BN_CLICKED(IDC_BUTTON4, &CMy87k_di_cntDlg::OnBnClickedButton4) ON_BN_CLICKED(IDC_BUTTON6, &CMy87k_di_cntDlg::OnBnClickedButton6) ON_BN_CLICKED(IDC_BUTTON5, &CMy87k_di_cntDlg::OnBnClickedButton5) END_MESSAGE_MAP() // CMy87k_di_cntDlg message handlers BOOL CMy87k_di_cntDlg::OnInitDialog() { CDialog::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon //set default value SetDlgItemText(IDC_COMBO1,L"1"); SetDlgItemText(IDC_EDIT1,L"16"); // TODO: Add extra initialization here SetDlgItemText(IDC_EDIT6, L"What is pac_xxx_MF?\r\nMF is the abbreviation of Multi-function.\r\npac_xxx_MF is used to access DIO channels of the Multi-function module.\r\nAIO or counter modules equipped with DI or DO channel is known as Multi-function module.\r\nCall pac_xxxx function to access DIO channels of the DCON module equipped only with DI or DO channel.\r\nCall pac_xxx_MF functions to access DIO channel of the Multi-function module.\r\n"); return TRUE; // return TRUE unless you set the focus to a control } #if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP) void CMy87k_di_cntDlg::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/) { if (AfxIsDRAEnabled()) { DRA::RelayoutDialog( AfxGetResourceHandle(), this->m_hWnd, DRA::GetDisplayMode() != DRA::Portrait ? MAKEINTRESOURCE(IDD_MY87k_di_cnt_DIALOG_WIDE) : MAKEINTRESOURCE(IDD_MY87k_di_cnt_DIALOG)); } } #endif void CMy87k_di_cntDlg::OnBnClickedButton1() { // TODO: Add your control notification handler code here //uart_Open function parameter is "", it's open COM0 port and baud rate set 115200 //COM0 port connect to backplane HANDLE hPort = uart_Open(""); TCHAR temp[20]; //get user set slot GetDlgItemText(IDC_COMBO1,temp,20); int slot = _wtoi(temp); //get user set total channel GetDlgItemText(IDC_EDIT1,temp,20); int channel = _wtoi(temp); DWORD DIValue; //use pac_ReadAI functio to read DI data BOOL iret = pac_ReadDI(hPort,slot,channel,&DIValue); uart_Close(hPort); if(!iret){ ::MessageBox(NULL,L"Read data error",L"87k_di_cnt",MB_OK); }else{ wsprintf(temp,L"%d",DIValue); SetDlgItemText(IDC_EDIT2,temp); wsprintf(temp,L"0x%lx",DIValue); SetDlgItemText(IDC_EDIT3,temp); } } void CMy87k_di_cntDlg::OnBnClickedButton2() { // TODO: 在此加入控制項告知處理常式程式碼 //uart_Open function parameter is "", it's open COM0 port and baud rate set 115200 //COM0 port connect to backplane HANDLE hPort = uart_Open(""); TCHAR temp[20]; //get user set slot GetDlgItemText(IDC_COMBO1,temp,20); int slot = _wtoi(temp); //get user set total channel GetDlgItemText(IDC_EDIT1,temp,20); int channel = _wtoi(temp); GetDlgItemText(IDC_EDIT5,temp,20); int DICNTchannel = _wtoi(temp); DWORD DIValue; //use pac_ReadAI functio to read DI data BOOL iret = pac_ReadDICNT(hPort,slot,DICNTchannel,channel,&DIValue); uart_Close(hPort); if(!iret){ ::MessageBox(NULL,L"Read data error",L"87k_di_cnt",MB_OK); }else{ wsprintf(temp,L"%d",DIValue); SetDlgItemText(IDC_EDIT4,temp); } } void CMy87k_di_cntDlg::OnBnClickedButton3() { // TODO: 在此加入控制項告知處理常式程式碼 //uart_Open function parameter is "", it's open COM0 port and baud rate set 115200 //COM0 port connect to backplane HANDLE hPort = uart_Open(""); TCHAR temp[20]; //get user set slot GetDlgItemText(IDC_COMBO1,temp,20); int slot = _wtoi(temp); //get user set total channel GetDlgItemText(IDC_EDIT1,temp,20); int channel = _wtoi(temp); GetDlgItemText(IDC_EDIT5,temp,20); int DICNTchannel = _wtoi(temp); //use pac_ReadAI functio to read DI data BOOL iret = pac_ClearDICNT(hPort,slot,DICNTchannel,channel); uart_Close(hPort); if(!iret){ ::MessageBox(NULL,L"Read data error",L"87k_di_cnt",MB_OK); } } void CMy87k_di_cntDlg::OnBnClickedButton4() { // TODO: Add your control notification handler code here //uart_Open function parameter is "", it's open COM0 port and baud rate set 115200 //COM0 port connect to backplane HANDLE hPort = uart_Open(""); TCHAR temp[20]; //get user set slot GetDlgItemText(IDC_COMBO1,temp,20); int slot = _wtoi(temp); //get user set total channel GetDlgItemText(IDC_EDIT1,temp,20); int channel = _wtoi(temp); DWORD DIValue; //use pac_ReadAI functio to read DI data BOOL iret = pac_ReadDI_MF(hPort,slot,channel,&DIValue); uart_Close(hPort); if(!iret){ ::MessageBox(NULL,L"Read data error",L"87k_di_cnt",MB_OK); }else{ wsprintf(temp,L"%d",DIValue); SetDlgItemText(IDC_EDIT2,temp); wsprintf(temp,L"0x%lx",DIValue); SetDlgItemText(IDC_EDIT3,temp); } } void CMy87k_di_cntDlg::OnBnClickedButton6() { // TODO: 在此加入控制項告知處理常式程式碼 //uart_Open function parameter is "", it's open COM0 port and baud rate set 115200 //COM0 port connect to backplane HANDLE hPort = uart_Open(""); TCHAR temp[20]; //get user set slot GetDlgItemText(IDC_COMBO1,temp,20); int slot = _wtoi(temp); //get user set total channel GetDlgItemText(IDC_EDIT1,temp,20); int channel = _wtoi(temp); GetDlgItemText(IDC_EDIT5,temp,20); int DICNTchannel = _wtoi(temp); //use pac_ReadAI functio to read DI data BOOL iret = pac_ClearDICNT_MF(hPort,slot,DICNTchannel,channel); uart_Close(hPort); if(!iret){ ::MessageBox(NULL,L"Read data error",L"87k_di_cnt",MB_OK); } } void CMy87k_di_cntDlg::OnBnClickedButton5() { // TODO: 在此加入控制項告知處理常式程式碼 //uart_Open function parameter is "", it's open COM0 port and baud rate set 115200 //COM0 port connect to backplane HANDLE hPort = uart_Open(""); TCHAR temp[20]; //get user set slot GetDlgItemText(IDC_COMBO1,temp,20); int slot = _wtoi(temp); //get user set total channel GetDlgItemText(IDC_EDIT1,temp,20); int channel = _wtoi(temp); GetDlgItemText(IDC_EDIT5,temp,20); int DICNTchannel = _wtoi(temp); DWORD DIValue; //use pac_ReadAI functio to read DI data BOOL iret = pac_ReadDICNT_MF(hPort,slot,DICNTchannel,channel,&DIValue); uart_Close(hPort); if(!iret){ ::MessageBox(NULL,L"Read data error",L"87k_di_cnt",MB_OK); }else{ wsprintf(temp,L"%d",DIValue); SetDlgItemText(IDC_EDIT4,temp); } }