// 8k_87k_diDlg.cpp : implementation file // #include "stdafx.h" #include "8k_87k_di.h" #include "8k_87k_diDlg.h" #include "PACSDK.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // CMy8k_87k_diDlg dialog CMy8k_87k_diDlg::CMy8k_87k_diDlg(CWnd* pParent /*=NULL*/) : CDialog(CMy8k_87k_diDlg::IDD, pParent) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CMy8k_87k_diDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CMy8k_87k_diDlg, CDialog) #if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP) ON_WM_SIZE() #endif //}}AFX_MSG_MAP ON_BN_CLICKED(IDC_BUTTON1, &CMy8k_87k_diDlg::OnBnClickedButton1) ON_BN_CLICKED(IDC_BUTTON2, &CMy8k_87k_diDlg::OnBnClickedButton2) END_MESSAGE_MAP() // CMy8k_87k_diDlg message handlers BOOL CMy8k_87k_diDlg::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 // TODO: Add extra initialization here SetDlgItemText(IDC_EDIT7, 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 CMy8k_87k_diDlg::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/) { if (AfxIsDRAEnabled()) { DRA::RelayoutDialog( AfxGetResourceHandle(), this->m_hWnd, DRA::GetDisplayMode() != DRA::Portrait ? MAKEINTRESOURCE(IDD_MY8K_87K_DI_DIALOG_WIDE) : MAKEINTRESOURCE(IDD_MY8K_87K_DI_DIALOG)); } } #endif void CMy8k_87k_diDlg::OnBnClickedButton1() { // TODO: Add your control notification handler code here TCHAR temp[20]; DWORD DIValue; int slot,DIChannel; BOOL iret; //87k module must build com port HANDLE read data HANDLE hPort = uart_Open(""); //get user set slot GetDlgItemText(IDC_COMBO1,temp,20); slot = _wtoi(temp); //get user set total channel GetDlgItemText(IDC_EDIT1,temp,20); DIChannel = _wtoi(temp); //use pac_ReadDI functio to read DI data iret = pac_ReadDI(hPort,slot,DIChannel,&DIValue); uart_Close(hPort); if(!iret){ ::MessageBox(NULL,L"Read 87k DI module error",L"87k_8k_di",MB_OK); }else{ wsprintf(temp,L"%d",DIValue); SetDlgItemText(IDC_EDIT2,temp); wsprintf(temp,L"0x%lx",DIValue); SetDlgItemText(IDC_EDIT3,temp); } //get user set slot GetDlgItemText(IDC_COMBO2,temp,20); slot = _wtoi(temp); //get user set total channel GetDlgItemText(IDC_EDIT4,temp,20); DIChannel = _wtoi(temp); //use pac_ReadDI functio to read DI data,8k module haven't use com port HANDLE read data. iret = pac_ReadDI(0,slot,DIChannel,&DIValue); if(!iret){ ::MessageBox(NULL,L"Read 8k DI module error",L"87k_8k_di",MB_OK); }else{ wsprintf(temp,L"%d",DIValue); SetDlgItemText(IDC_EDIT5,temp); wsprintf(temp,L"0x%lx",DIValue); SetDlgItemText(IDC_EDIT6,temp); } } void CMy8k_87k_diDlg::OnBnClickedButton2() { // TODO: 在此加入控制項告知處理常式程式碼 // TODO: Add your control notification handler code here TCHAR temp[20]; DWORD DIValue; int slot,DIChannel; BOOL iret; //87k module must build com port HANDLE read data HANDLE hPort = uart_Open(""); //get user set slot GetDlgItemText(IDC_COMBO1,temp,20); slot = _wtoi(temp); //get user set total channel GetDlgItemText(IDC_EDIT1,temp,20); DIChannel = _wtoi(temp); //use pac_ReadDI functio to read DI data iret = pac_ReadDI_MF(hPort,slot,DIChannel,&DIValue); uart_Close(hPort); if(!iret){ ::MessageBox(NULL,L"Read 87k DI module error",L"87k_8k_di",MB_OK); }else{ wsprintf(temp,L"%d",DIValue); SetDlgItemText(IDC_EDIT2,temp); wsprintf(temp,L"0x%lx",DIValue); SetDlgItemText(IDC_EDIT3,temp); } //get user set slot GetDlgItemText(IDC_COMBO2,temp,20); slot = _wtoi(temp); //get user set total channel GetDlgItemText(IDC_EDIT4,temp,20); DIChannel = _wtoi(temp); //use pac_ReadDI functio to read DI data,8k module haven't use com port HANDLE read data. iret = pac_ReadDI(0,slot,DIChannel,&DIValue); if(!iret){ ::MessageBox(NULL,L"Read 8k DI module error",L"87k_8k_di",MB_OK); }else{ wsprintf(temp,L"%d",DIValue); SetDlgItemText(IDC_EDIT5,temp); wsprintf(temp,L"0x%lx",DIValue); SetDlgItemText(IDC_EDIT6,temp); } }