// 87k_do_poweron_safeDlg.cpp : implementation file // #include "stdafx.h" #include "87k_do_poweron_safe.h" #include "87k_do_poweron_safeDlg.h" #include "PACSDK.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // CMy87k_do_poweron_safeDlg dialog CMy87k_do_poweron_safeDlg::CMy87k_do_poweron_safeDlg(CWnd* pParent /*=NULL*/) : CDialog(CMy87k_do_poweron_safeDlg::IDD, pParent) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CMy87k_do_poweron_safeDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Control(pDX, IDC_COMBO1, cmbSlot); DDX_Control(pDX, IDC_EDIT1, txtChannel); DDX_Control(pDX, IDC_EDIT2, txtDOValue); DDX_Control(pDX, IDC_BUTTON1, btnWrite); DDX_Control(pDX, IDC_BUTTON2, btnClear); } BEGIN_MESSAGE_MAP(CMy87k_do_poweron_safeDlg, CDialog) #if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP) ON_WM_SIZE() #endif //}}AFX_MSG_MAP ON_BN_CLICKED(IDC_BUTTON1, &CMy87k_do_poweron_safeDlg::OnBnClickedButton1) ON_BN_CLICKED(IDC_BUTTON2, &CMy87k_do_poweron_safeDlg::OnBnClickedButton2) ON_BN_CLICKED(IDC_BUTTON3, &CMy87k_do_poweron_safeDlg::OnBnClickedButton3) ON_BN_CLICKED(IDC_BUTTON4, &CMy87k_do_poweron_safeDlg::OnBnClickedButton4) ON_BN_CLICKED(IDC_BUTTON5, &CMy87k_do_poweron_safeDlg::OnBnClickedButton5) ON_BN_CLICKED(IDC_BUTTON6, &CMy87k_do_poweron_safeDlg::OnBnClickedButton6) ON_BN_CLICKED(IDC_BUTTON7, &CMy87k_do_poweron_safeDlg::OnBnClickedButton7) ON_BN_CLICKED(IDC_BUTTON8, &CMy87k_do_poweron_safeDlg::OnBnClickedButton8) ON_BN_CLICKED(IDC_BUTTON9, &CMy87k_do_poweron_safeDlg::OnBnClickedButton9) ON_BN_CLICKED(IDC_BUTTON10, &CMy87k_do_poweron_safeDlg::OnBnClickedButton10) ON_BN_CLICKED(IDC_BUTTON11, &CMy87k_do_poweron_safeDlg::OnBnClickedButton11) ON_BN_CLICKED(IDC_BUTTON14, &CMy87k_do_poweron_safeDlg::OnBnClickedButton14) ON_BN_CLICKED(IDC_BUTTON12, &CMy87k_do_poweron_safeDlg::OnBnClickedButton12) ON_BN_CLICKED(IDC_BUTTON13, &CMy87k_do_poweron_safeDlg::OnBnClickedButton13) ON_BN_CLICKED(IDC_BUTTON15, &CMy87k_do_poweron_safeDlg::OnBnClickedButton15) ON_BN_CLICKED(IDC_BUTTON16, &CMy87k_do_poweron_safeDlg::OnBnClickedButton16) ON_BN_CLICKED(IDC_BUTTON17, &CMy87k_do_poweron_safeDlg::OnBnClickedButton17) ON_BN_CLICKED(IDC_BUTTON18, &CMy87k_do_poweron_safeDlg::OnBnClickedButton18) END_MESSAGE_MAP() // CMy87k_do_poweron_safeDlg message handlers BOOL CMy87k_do_poweron_safeDlg::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 //set default value SetDlgItemText(IDC_COMBO1, L"1"); SetDlgItemText(IDC_EDIT1, L"16"); SetDlgItemText(IDC_EDIT2, L"0"); 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 CMy87k_do_poweron_safeDlg::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/) { if(AfxIsDRAEnabled()) { DRA::RelayoutDialog( AfxGetResourceHandle(), this->m_hWnd, DRA::GetDisplayMode() != DRA::Portrait ? MAKEINTRESOURCE(IDD_MY87k_do_poweron_safe_DIALOG_WIDE) : MAKEINTRESOURCE(IDD_MY87k_do_poweron_safe_DIALOG)); } } #endif void CMy87k_do_poweron_safeDlg::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]; DWORD DOValue = 0; CString strTemp; char ctemp[20] = {0}; //get user set slot GetDlgItemText(IDC_COMBO1, temp, 10); int slot = _wtoi(temp); //get user set DO channel GetDlgItemText(IDC_EDIT1, temp, 20); int channel = _wtoi(temp); //get user set DO value GetDlgItemText(IDC_EDIT2, strTemp); for(int i = 0; i < strTemp.GetAllocLength(); i++) { ctemp[i] = strTemp[i]; } sscanf(ctemp, "%lx", &DOValue); //use pac_WriteDO functio to write DO data BOOL iret = pac_WriteDO(hPort, slot, channel, DOValue); uart_Close(hPort); if(!iret) { ::MessageBox(NULL, L"Write DO error", L"87k_do_poweron_safe", MB_OK); } } void CMy87k_do_poweron_safeDlg::OnBnClickedButton2() { // TODO: Add your control notification handler code here HANDLE hPort = uart_Open(""); TCHAR temp[20]; GetDlgItemText(IDC_COMBO1, temp, 10); int slot = _wtoi(temp); //get user set DO channel GetDlgItemText(IDC_EDIT1, temp, 20); int channel = _wtoi(temp); //use pac_WriteDO functio and set DO value be 0 to clear BOOL iret = pac_WriteDO(hPort, slot, channel, 0); uart_Close(hPort); if(!iret) { ::MessageBox(NULL, L"Clear DO error", L"87k_do_poweron_safe", MB_OK); } } void CMy87k_do_poweron_safeDlg::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]; DWORD DOValue = 0; //get user set slot GetDlgItemText(IDC_COMBO1, temp, 10); int slot = _wtoi(temp); //get user set DO channel GetDlgItemText(IDC_EDIT1, temp, 20); int channel = _wtoi(temp); //use pac_WriteDO functio to write DO data BOOL iret = pac_ReadDO(hPort, slot, channel, &DOValue); uart_Close(hPort); if(!iret) { ::MessageBox(NULL, L"READ DO error", L"87k_do_poweron_safe", MB_OK); } else { wsprintf(temp, L"Read DO: %d", DOValue); SetDlgItemText(IDC_EDIT4, temp); } } void CMy87k_do_poweron_safeDlg::OnBnClickedButton4() { // TODO: 北兜矪瞶盽Α祘Α絏 HANDLE hPort = uart_Open(""); TCHAR temp[20]; CString strTemp; //get user set slot GetDlgItemText(IDC_COMBO1, temp, 20); int slot = _wtoi(temp); //get user set WTD Timeout GetDlgItemText(IDC_EDIT5, temp, 20); int WTDTimeout = _wtoi(temp); //use pac_SetModuleWDTConfig function BOOL iret = pac_SetModuleWDTConfig(hPort, slot, 1, WTDTimeout, 0); uart_Close(hPort); if(!iret) { ::MessageBox(NULL, L"Config WDT error", L"87k_do_poweron_safe", MB_OK); } } void CMy87k_do_poweron_safeDlg::OnBnClickedButton5() { // TODO: 北兜矪瞶盽Α祘Α絏 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 TotalChannel = _wtoi(temp); short ebStatus; ulong WTDTimeout; int WTDOverwrite; //use pac_GetModuleWDTConfig function BOOL iret = pac_GetModuleWDTConfig(hPort, slot, &ebStatus, &WTDTimeout, &WTDOverwrite); uart_Close(hPort); if(!iret) { ::MessageBox(NULL, L"Get Module WDT Config error", L"87k_do_poweron_safe", MB_OK); } else { wsprintf(temp, L"%u", WTDTimeout); SetDlgItemText(IDC_EDIT5, temp); } } void CMy87k_do_poweron_safeDlg::OnBnClickedButton6() { // TODO: 北兜矪瞶盽Α祘Α絏 HANDLE hPort = uart_Open(""); TCHAR temp[20]; CString strTemp; //get user set slot GetDlgItemText(IDC_COMBO1, temp, 20); int slot = _wtoi(temp); //use pac_SetModuleWDTConfig function BOOL iret = pac_ResetModuleWDT(hPort, slot); uart_Close(hPort); if(!iret) { ::MessageBox(NULL, L"Reset Module WDT error", L"87k_do_poweron_safe", MB_OK); } } void CMy87k_do_poweron_safeDlg::OnBnClickedButton7() { // TODO: 北兜矪瞶盽Α祘Α絏 HANDLE hPort = uart_Open(""); TCHAR temp[20]; CString strTemp; //get user set slot GetDlgItemText(IDC_COMBO1, temp, 20); int slot = _wtoi(temp); //use pac_SetModuleWDTConfig function BOOL iret = pac_RefreshModuleWDT(hPort, slot); uart_Close(hPort); if(!iret) { ::MessageBox(NULL, L"Refresh Module WDT error", L"87k_do_poweron_safe", MB_OK); } } void CMy87k_do_poweron_safeDlg::OnBnClickedButton8() { // TODO: 北兜矪瞶盽Α祘Α絏 HANDLE hPort = uart_Open(""); TCHAR temp[20]; CString strTemp; DWORD fValue = 0; //get user set slot GetDlgItemText(IDC_COMBO1, temp, 20); int slot = _wtoi(temp); //get user set total channel GetDlgItemText(IDC_EDIT1, temp, 20); int TotalChannel = _wtoi(temp); //use pac_ReadDO function BOOL iret = pac_ReadModulePowerOnValueDO(hPort, slot, TotalChannel, &fValue); uart_Close(hPort); if(!iret) { ::MessageBox(NULL, L"Read PowerOn ValuedO error", L"87k_do_poweron_safe", MB_OK); } else { wsprintf(temp, L"Read PowerOn ValuedO: %d", fValue); SetDlgItemText(IDC_EDIT4, temp); } } void CMy87k_do_poweron_safeDlg::OnBnClickedButton9() { // 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]; DWORD DOValue = 0; CString strTemp; char ctemp[20] = {0}; //get user set slot GetDlgItemText(IDC_COMBO1, temp, 10); int slot = _wtoi(temp); //get user set DO channel GetDlgItemText(IDC_EDIT1, temp, 20); int channel = _wtoi(temp); //get user set DO value GetDlgItemText(IDC_EDIT2, strTemp); for(int i = 0; i < strTemp.GetAllocLength(); i++) { ctemp[i] = strTemp[i]; } sscanf(ctemp, "%lx", &DOValue); //use pac_WriteDO functio to write DO data BOOL iret = pac_WriteModulePowerOnValueDO(hPort, slot, channel, DOValue); uart_Close(hPort); if(!iret) { ::MessageBox(NULL, L"Write PowerOn ValueDO error", L"87k_do_poweron_safe", MB_OK); } } void CMy87k_do_poweron_safeDlg::OnBnClickedButton10() { // TODO: 北兜矪瞶盽Α祘Α絏 HANDLE hPort = uart_Open(""); TCHAR temp[20]; CString strTemp; DWORD fValue = 0; //get user set slot GetDlgItemText(IDC_COMBO1, temp, 20); int slot = _wtoi(temp); //get user set total channel GetDlgItemText(IDC_EDIT1, temp, 20); int TotalChannel = _wtoi(temp); //use pac_ReadDO function BOOL iret = pac_ReadModuleSafeValueDO(hPort, slot, TotalChannel, &fValue); uart_Close(hPort); if(!iret) { ::MessageBox(NULL, L"Read Safe ValuedO error", L"87k_do_poweron_safe", MB_OK); } else { wsprintf(temp, L"Read Safe ValuedO: %d", fValue); SetDlgItemText(IDC_EDIT4, temp); } } void CMy87k_do_poweron_safeDlg::OnBnClickedButton11() { // 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]; DWORD DOValue = 0; CString strTemp; char ctemp[20] = {0}; //get user set slot GetDlgItemText(IDC_COMBO1, temp, 10); int slot = _wtoi(temp); //get user set DO channel GetDlgItemText(IDC_EDIT1, temp, 20); int channel = _wtoi(temp); //get user set DO value GetDlgItemText(IDC_EDIT2, strTemp); for(int i = 0; i < strTemp.GetAllocLength(); i++) { ctemp[i] = strTemp[i]; } sscanf(ctemp, "%lx", &DOValue); //use pac_WriteDO functio to write DO data BOOL iret = pac_WriteModuleSafeValueDO(hPort, slot, channel, DOValue); uart_Close(hPort); if(!iret) { ::MessageBox(NULL, L"Write Safe ValueDO error", L"87k_do_poweron_safe", MB_OK); } } void CMy87k_do_poweron_safeDlg::OnBnClickedButton14() { // 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]; DWORD DOValue = 0; //get user set slot GetDlgItemText(IDC_COMBO1, temp, 10); int slot = _wtoi(temp); //get user set DO channel GetDlgItemText(IDC_EDIT1, temp, 20); int channel = _wtoi(temp); //use pac_WriteDO functio to write DO data BOOL iret = pac_ReadDO(hPort, slot, channel, &DOValue); uart_Close(hPort); if(!iret) { ::MessageBox(NULL, L"READ DO error", L"87k_do_poweron_safe", MB_OK); } else { wsprintf(temp, L"Read DO: %d", DOValue); SetDlgItemText(IDC_EDIT4, temp); } } void CMy87k_do_poweron_safeDlg::OnBnClickedButton12() { // 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]; DWORD DOValue = 0; CString strTemp; char ctemp[20] = {0}; //get user set slot GetDlgItemText(IDC_COMBO1, temp, 10); int slot = _wtoi(temp); //get user set DO channel GetDlgItemText(IDC_EDIT1, temp, 20); int channel = _wtoi(temp); //get user set DO value GetDlgItemText(IDC_EDIT2, strTemp); for(int i = 0; i < strTemp.GetAllocLength(); i++) { ctemp[i] = strTemp[i]; } sscanf(ctemp, "%lx", &DOValue); //use pac_WriteDO functio to write DO data BOOL iret = pac_WriteDO_MF(hPort, slot, channel, DOValue); uart_Close(hPort); if(!iret) { ::MessageBox(NULL, L"Write DO error", L"87k_do_poweron_safe", MB_OK); } } void CMy87k_do_poweron_safeDlg::OnBnClickedButton13() { // TODO: Add your control notification handler code here HANDLE hPort = uart_Open(""); TCHAR temp[20]; GetDlgItemText(IDC_COMBO1, temp, 10); int slot = _wtoi(temp); //get user set DO channel GetDlgItemText(IDC_EDIT1, temp, 20); int channel = _wtoi(temp); //use pac_WriteDO functio and set DO value be 0 to clear BOOL iret = pac_WriteDO_MF(hPort, slot, channel, 0); uart_Close(hPort); if(!iret) { ::MessageBox(NULL, L"Clear DO error", L"87k_do_poweron_safe", MB_OK); } } void CMy87k_do_poweron_safeDlg::OnBnClickedButton15() { // TODO: 北兜矪瞶盽Α祘Α絏 HANDLE hPort = uart_Open(""); TCHAR temp[20]; CString strTemp; DWORD fValue = 0; //get user set slot GetDlgItemText(IDC_COMBO1, temp, 20); int slot = _wtoi(temp); //get user set total channel GetDlgItemText(IDC_EDIT1, temp, 20); int TotalChannel = _wtoi(temp); //use pac_ReadDO function BOOL iret = pac_ReadModulePowerOnValueDO_MF(hPort, slot, TotalChannel, &fValue); uart_Close(hPort); if(!iret) { ::MessageBox(NULL, L"Read PowerOn ValuedO error", L"87k_do_poweron_safe", MB_OK); } else { wsprintf(temp, L"Read PowerOn ValuedO: %d", fValue); SetDlgItemText(IDC_EDIT4, temp); } } void CMy87k_do_poweron_safeDlg::OnBnClickedButton16() { // 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]; DWORD DOValue = 0; CString strTemp; char ctemp[20] = {0}; //get user set slot GetDlgItemText(IDC_COMBO1, temp, 10); int slot = _wtoi(temp); //get user set DO channel GetDlgItemText(IDC_EDIT1, temp, 20); int channel = _wtoi(temp); //get user set DO value GetDlgItemText(IDC_EDIT2, strTemp); for(int i = 0; i < strTemp.GetAllocLength(); i++) { ctemp[i] = strTemp[i]; } sscanf(ctemp, "%lx", &DOValue); //use pac_WriteDO functio to write DO data BOOL iret = pac_WriteModulePowerOnValueDO_MF(hPort, slot, channel, DOValue); uart_Close(hPort); if(!iret) { ::MessageBox(NULL, L"Write PowerOn ValueDO error", L"87k_do_poweron_safe", MB_OK); } } void CMy87k_do_poweron_safeDlg::OnBnClickedButton17() { // TODO: 北兜矪瞶盽Α祘Α絏 HANDLE hPort = uart_Open(""); TCHAR temp[20]; CString strTemp; DWORD fValue = 0; //get user set slot GetDlgItemText(IDC_COMBO1, temp, 20); int slot = _wtoi(temp); //get user set total channel GetDlgItemText(IDC_EDIT1, temp, 20); int TotalChannel = _wtoi(temp); //use pac_ReadDO function BOOL iret = pac_ReadModuleSafeValueDO_MF(hPort, slot, TotalChannel, &fValue); uart_Close(hPort); if(!iret) { ::MessageBox(NULL, L"Read Safe ValuedO error", L"87k_do_poweron_safe", MB_OK); } else { wsprintf(temp, L"Read Safe ValuedO: %d", fValue); SetDlgItemText(IDC_EDIT4, temp); } } void CMy87k_do_poweron_safeDlg::OnBnClickedButton18() { // 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]; DWORD DOValue = 0; CString strTemp; char ctemp[20] = {0}; //get user set slot GetDlgItemText(IDC_COMBO1, temp, 10); int slot = _wtoi(temp); //get user set DO channel GetDlgItemText(IDC_EDIT1, temp, 20); int channel = _wtoi(temp); //get user set DO value GetDlgItemText(IDC_EDIT2, strTemp); for(int i = 0; i < strTemp.GetAllocLength(); i++) { ctemp[i] = strTemp[i]; } sscanf(ctemp, "%lx", &DOValue); //use pac_WriteDO functio to write DO data BOOL iret = pac_WriteModuleSafeValueDO_MF(hPort, slot, channel, DOValue); uart_Close(hPort); if(!iret) { ::MessageBox(NULL, L"Write Safe ValueDO error", L"87k_do_poweron_safe", MB_OK); } }