// 7k_dioDlg.cpp : implementation file // #include "stdafx.h" #include "7k_dio.h" #include "7k_dioDlg.h" #include "PACSDK.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // CMy7k_dioDlg dialog CMy7k_dioDlg::CMy7k_dioDlg(CWnd* pParent /*=NULL*/) : CDialog(CMy7k_dioDlg::IDD, pParent) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CMy7k_dioDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CMy7k_dioDlg, CDialog) #if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP) ON_WM_SIZE() #endif //}}AFX_MSG_MAP ON_BN_CLICKED(IDC_BUTTON1, &CMy7k_dioDlg::OnBnClickedButton1) ON_BN_CLICKED(IDC_BUTTON2, &CMy7k_dioDlg::OnBnClickedButton2) ON_BN_CLICKED(IDC_BUTTON3, &CMy7k_dioDlg::OnBnClickedButton3) ON_BN_CLICKED(IDC_BUTTON4, &CMy7k_dioDlg::OnBnClickedButton4) ON_BN_CLICKED(IDC_BUTTON5, &CMy7k_dioDlg::OnBnClickedButton5) ON_BN_CLICKED(IDC_BUTTON6, &CMy7k_dioDlg::OnBnClickedButton6) END_MESSAGE_MAP() // CMy7k_dioDlg message handlers BOOL CMy7k_dioDlg::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_COMBO1, L"COM3:"); SetDlgItemText(IDC_EDIT2, L"115200"); SetDlgItemText(IDC_EDIT1, L"01"); SetDlgItemText(IDC_EDIT3, L"4"); SetDlgItemText(IDC_EDIT4, L"8"); 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 CMy7k_dioDlg::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/) { if(AfxIsDRAEnabled()) { DRA::RelayoutDialog( AfxGetResourceHandle(), this->m_hWnd, DRA::GetDisplayMode() != DRA::Portrait ? MAKEINTRESOURCE(IDD_MY7K_DIO_DIALOG_WIDE) : MAKEINTRESOURCE(IDD_MY7K_DIO_DIALOG)); } } #endif HANDLE hPort; void CMy7k_dioDlg::OnBnClickedButton1() { // TODO: Add your control notification handler code here TCHAR OpenPort[10]; TCHAR temp[20]; char port[20]; //get user set com port and buad rate GetDlgItemText(IDC_COMBO1, OpenPort, 10); GetDlgItemText(IDC_EDIT2, temp, 20); int BuadRate = _wtoi(temp); //uart_Open parameter format is COMx,buadrate , for ex will set COM3 port and baud rate 9600 to uart_Open, //parameter is "COM3,9600" sprintf(port, "%ls,%d", OpenPort, BuadRate); hPort = uart_Open(port); //if hPort value is INVALID_HANDLE_VALUE , that is error if(hPort == INVALID_HANDLE_VALUE) { ::MessageBox(NULL, L"Open Port Error", L"7k_di", MB_OK); } else { GetDlgItem(IDC_BUTTON1)->EnableWindow(FALSE); GetDlgItem(IDC_BUTTON2)->EnableWindow(TRUE); GetDlgItem(IDC_BUTTON3)->EnableWindow(TRUE); GetDlgItem(IDC_BUTTON4)->EnableWindow(TRUE); GetDlgItem(IDC_BUTTON5)->EnableWindow(TRUE); GetDlgItem(IDC_BUTTON6)->EnableWindow(TRUE); } } void CMy7k_dioDlg::OnBnClickedButton2() { // TODO: Add your control notification handler code here //close com port if(!uart_Close(hPort)) { ::MessageBox(NULL, L"Close Port Error", L"7k_di", MB_OK); } else { GetDlgItem(IDC_BUTTON1)->EnableWindow(TRUE); GetDlgItem(IDC_BUTTON2)->EnableWindow(FALSE); GetDlgItem(IDC_BUTTON3)->EnableWindow(FALSE); GetDlgItem(IDC_BUTTON4)->EnableWindow(FALSE); GetDlgItem(IDC_BUTTON5)->EnableWindow(FALSE); GetDlgItem(IDC_BUTTON6)->EnableWindow(FALSE); } } void CMy7k_dioDlg::OnBnClickedButton3() { // TODO: Add your control notification handler code here TCHAR temp[20]; DWORD DIChannel, DOChannel, DIValue = 0, DOValue = 0; //get user set DI channel GetDlgItemText(IDC_EDIT3, temp, 20); DIChannel = _wtoi(temp); //get user set DO channel GetDlgItemText(IDC_EDIT4, temp, 20); DOChannel = _wtoi(temp); //get user set address GetDlgItemText(IDC_EDIT1, temp, 20); int address = _wtoi(temp); //use pac_ReadDIO functio to read DI and DO data BOOL iret = pac_ReadDIO(hPort, PAC_REMOTE_IO(address), DIChannel, DOChannel, &DIValue, &DOValue); if(!iret) { ::MessageBox(NULL, L"Read data error", L"7k_dio", MB_OK); } else { wsprintf(temp, L"0x%lx", DIValue); SetDlgItemText(IDC_EDIT5, temp); } } void CMy7k_dioDlg::OnBnClickedButton4() { // TODO: Add your control notification handler code here TCHAR temp[20]; DWORD DOChannel, DOValue; CString strTemp; char ctemp[20] = {0}; //get user set DO channel GetDlgItemText(IDC_EDIT4, temp, 20); DOChannel = _wtoi(temp); //get user set DO value GetDlgItemText(IDC_EDIT6, strTemp); for(int i = 0; i < strTemp.GetAllocLength(); i++) { ctemp[i] = strTemp[i]; } sscanf(ctemp, "%lx", &DOValue); //get user set address GetDlgItemText(IDC_EDIT1, temp, 20); int address = _wtoi(temp); //use pac_WriteDO functio to write DO data BOOL iret = pac_WriteDO(hPort, PAC_REMOTE_IO(address), DOChannel, DOValue); if(!iret) { ::MessageBox(NULL, L"Write data error", L"7k_dio", MB_OK); } } void CMy7k_dioDlg::OnBnClickedButton5() { // TODO: Add your control notification handler code here TCHAR temp[20]; DWORD DIChannel, DOChannel, DIValue = 0, DOValue = 0; //get user set DI channel GetDlgItemText(IDC_EDIT3, temp, 20); DIChannel = _wtoi(temp); //get user set DO channel GetDlgItemText(IDC_EDIT4, temp, 20); DOChannel = _wtoi(temp); //get user set address GetDlgItemText(IDC_EDIT1, temp, 20); int address = _wtoi(temp); //use pac_ReadDIO functio to read DI and DO data BOOL iret = pac_ReadDIO_MF(hPort, PAC_REMOTE_IO(address), DIChannel, DOChannel, &DIValue, &DOValue); if(!iret) { ::MessageBox(NULL, L"Read data error", L"7k_dio", MB_OK); } else { wsprintf(temp, L"0x%lx", DIValue); SetDlgItemText(IDC_EDIT5, temp); } } void CMy7k_dioDlg::OnBnClickedButton6() { // TODO: Add your control notification handler code here TCHAR temp[20]; DWORD DOChannel, DOValue; CString strTemp; char ctemp[20] = {0}; //get user set DO channel GetDlgItemText(IDC_EDIT4, temp, 20); DOChannel = _wtoi(temp); //get user set DO value GetDlgItemText(IDC_EDIT6, strTemp); for(int i = 0; i < strTemp.GetAllocLength(); i++) { ctemp[i] = strTemp[i]; } sscanf(ctemp, "%lx", &DOValue); //get user set address GetDlgItemText(IDC_EDIT1, temp, 20); int address = _wtoi(temp); //use pac_WriteDO functio to write DO data BOOL iret = pac_WriteDO_MF(hPort, PAC_REMOTE_IO(address), DOChannel, DOValue); if(!iret) { ::MessageBox(NULL, L"Write data error", L"7k_dio", MB_OK); } }