// 87k_ao_poweron_safeDlg.cpp : implementation file // #include "stdafx.h" #include "87k_ao_poweron_safe.h" #include "87k_ao_poweron_safeDlg.h" #include "pacsdk.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg) //}}AFX_MSG DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMy87k_ao_poweron_safeDlg dialog CMy87k_ao_poweron_safeDlg::CMy87k_ao_poweron_safeDlg(CWnd* pParent /*=NULL*/) : CDialog(CMy87k_ao_poweron_safeDlg::IDD, pParent) { //{{AFX_DATA_INIT(CMy87k_ao_poweron_safeDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CMy87k_ao_poweron_safeDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CMy87k_ao_poweron_safeDlg) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CMy87k_ao_poweron_safeDlg, CDialog) //{{AFX_MSG_MAP(CMy87k_ao_poweron_safeDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_btnWrietAO, OnbtnWrietAO) ON_BN_CLICKED(IDC_btnReadAO, OnbtnReadAO) ON_BN_CLICKED(IDC_btnClearAO, OnbtnClearAO) ON_BN_CLICKED(IDC_btnConfigWDT, OnbtnConfigWDT) ON_BN_CLICKED(IDC_btnGetWDTConfig, OnbtnGetWDTConfig) ON_BN_CLICKED(IDC_btnResetWDT, OnbtnResetWDT) ON_BN_CLICKED(IDC_btnRefreshWDT, OnbtnRefreshWDT) ON_BN_CLICKED(IDC_btnReadPower, OnbtnReadPower) ON_BN_CLICKED(IDC_btnWritePower, OnbtnWritePower) ON_BN_CLICKED(IDC_btnReadSafe, OnbtnReadSafe) ON_BN_CLICKED(IDC_btnWrietSafe, OnbtnWrietSafe) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMy87k_ao_poweron_safeDlg message handlers BOOL CMy87k_ao_poweron_safeDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // 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_COMBOSlot, "3"); SetDlgItemText(IDC_EDITChs, "4"); SetDlgItemText(IDC_EDITCh, "1"); SetDlgItemText(IDC_EDITAOValue, "3.5"); return TRUE; // return TRUE unless you set the focus to a control } void CMy87k_ao_poweron_safeDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void CMy87k_ao_poweron_safeDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CMy87k_ao_poweron_safeDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CMy87k_ao_poweron_safeDlg::OnbtnWrietAO() { // TODO: Add your control notification handler code here HANDLE hPort = uart_Open(""); TCHAR temp[20]; CString strTemp; char ctemp[20]; float fValue = 0.0; //get slot GetDlgItemText(IDC_COMBOSlot, temp, 20); int slot = atoi(temp); //get total channels GetDlgItemText(IDC_EDITChs, temp, 20); int TotalChannel = atoi(temp); //get channel which is written GetDlgItemText(IDC_EDITCh, temp, 20); int WriteChannel = atoi(temp); //get written data GetDlgItemText(IDC_EDITAOValue, strTemp); for(int i = 0; i < sizeof(strTemp); i++) { ctemp[i] = strTemp[i]; } fValue = (float)atof(ctemp); //use pac_WriteAO function to write AO data BOOL iret = pac_WriteAO(hPort, slot, WriteChannel, TotalChannel, fValue); uart_Close(hPort); if(!iret) { ::MessageBox(NULL, "Write AO error", "87k_ao_poweron_safe", MB_OK); } } void CMy87k_ao_poweron_safeDlg::OnbtnReadAO() { // TODO: Add your control notification handler code here HANDLE hPort = uart_Open(""); TCHAR temp[20]; CString strTemp; float fValue = 0.0; //get slot GetDlgItemText(IDC_COMBOSlot, temp, 20); int slot = atoi(temp); //get total channels GetDlgItemText(IDC_EDITChs, temp, 20); int TotalChannel = atoi(temp); //get the channel which is written GetDlgItemText(IDC_EDITCh, temp, 20); int WriteChannel = atoi(temp); //use pac_ReadAO function to read AO value BOOL iret = pac_ReadAO(hPort, slot, WriteChannel, TotalChannel, &fValue); uart_Close(hPort); if(!iret) { ::MessageBox(NULL, "Read AO error", "87k_ao_poweron_safe", MB_OK); } else { sprintf(temp, "Read AO: %.4f", fValue); SetDlgItemText(IDC_EDITInfor, temp); } } void CMy87k_ao_poweron_safeDlg::OnbtnClearAO() { // TODO: Add your control notification handler code here //uart_Open function parameter is "", it open COM0 port and set baud rate to 115200 //COM0 port connects to backplane HANDLE hPort = uart_Open(""); TCHAR temp[20]; float fValue = 0.0; //get slot GetDlgItemText(IDC_COMBOSlot, temp, 20); int slot = atoi(temp); //get total channels GetDlgItemText(IDC_EDITChs, temp, 20); int TotalChannel = atoi(temp); //get the channel which is written GetDlgItemText(IDC_EDITCh, temp, 20); int WriteChannel = atoi(temp); //use pac_WriteAO function to write data BOOL iret = pac_WriteAO(hPort, slot, WriteChannel, TotalChannel, fValue); uart_Close(hPort); if(!iret) { ::MessageBox(NULL, "Clear AO error", "87k_ao_poweron_safe", MB_OK); } } void CMy87k_ao_poweron_safeDlg::OnbtnConfigWDT() { // TODO: Add your control notification handler code here HANDLE hPort = uart_Open(""); TCHAR temp[20]; CString strTemp; float fValue = 0.0; //get slot GetDlgItemText(IDC_COMBOSlot, temp, 20); int slot = atoi(temp); //get WTD Timeout GetDlgItemText(IDC_EDITTimeout, temp, 20); int WTDTimeout = atoi(temp); //use pac_SetModuleWDTConfig function BOOL iret = pac_SetModuleWDTConfig(hPort, slot, 1, WTDTimeout, 0); uart_Close(hPort); if(!iret) { ::MessageBox(NULL, "Config WDT error", "87k_ao_poweron_safe", MB_OK); } } void CMy87k_ao_poweron_safeDlg::OnbtnGetWDTConfig() { // TODO: Add your control notification handler code here HANDLE hPort = uart_Open(""); TCHAR temp[20]; //get slot GetDlgItemText(IDC_COMBOSlot, temp, 20); int slot = atoi(temp); short ebStatus; unsigned long WTDTimeout; int WTDOverwrite; //use pac_GetModuleWDTConfig function BOOL iret = pac_GetModuleWDTConfig(hPort, slot, &ebStatus, &WTDTimeout, &WTDOverwrite); uart_Close(hPort); if(!iret) { ::MessageBox(NULL, "Get Module WDT Config error", "87k_ao_poweron_safe", MB_OK); } else { wsprintf(temp, "%u", WTDTimeout); SetDlgItemText(IDC_EDITTimeout, temp); } } void CMy87k_ao_poweron_safeDlg::OnbtnResetWDT() { // TODO: Add your control notification handler code here HANDLE hPort = uart_Open(""); TCHAR temp[20]; CString strTemp; float fValue = 0.0; //get slot GetDlgItemText(IDC_COMBOSlot, temp, 20); int slot = atoi(temp); BOOL iret = pac_ResetModuleWDT(hPort, slot); uart_Close(hPort); if(!iret) { ::MessageBox(NULL, "Reset Module WDT error", "87k_ao_poweron_safe", MB_OK); } } void CMy87k_ao_poweron_safeDlg::OnbtnRefreshWDT() { // TODO: Add your control notification handler code here HANDLE hPort = uart_Open(""); TCHAR temp[20]; CString strTemp; float fValue = 0.0; //get slot GetDlgItemText(IDC_COMBOSlot, temp, 20); int slot = atoi(temp); BOOL iret = pac_RefreshModuleWDT(hPort, slot); uart_Close(hPort); if(!iret) { ::MessageBox(NULL, "Refresh Module WDT error", "87k_ao_poweron_safe", MB_OK); } } void CMy87k_ao_poweron_safeDlg::OnbtnReadPower() { // TODO: Add your control notification handler code here HANDLE hPort = uart_Open(""); TCHAR temp[20]; CString strTemp; float fValue = 0.0; //get slot GetDlgItemText(IDC_COMBOSlot, temp, 20); int slot = atoi(temp); //get total channels GetDlgItemText(IDC_EDITChs, temp, 20); int TotalChannel = atoi(temp); //get the channel which is read GetDlgItemText(IDC_EDITCh, temp, 20); int Channel = atoi(temp); BOOL iret = pac_ReadModulePowerOnValueAO(hPort, slot, Channel, TotalChannel, &fValue); uart_Close(hPort); if(!iret) { ::MessageBox(NULL, "Read PowerOn ValueAO error", "87k_ao_poweron_safe", MB_OK); } else { sprintf(temp, "Read PowerOn ValueAO: %.4f", fValue); SetDlgItemText(IDC_EDITInfor, temp); } } void CMy87k_ao_poweron_safeDlg::OnbtnWritePower() { // TODO: Add your control notification handler code here HANDLE hPort = uart_Open(""); TCHAR temp[20]; CString strTemp; char ctemp[20]; float fValue = 0.0; //get slot GetDlgItemText(IDC_COMBOSlot, temp, 20); int slot = atoi(temp); //get total channels GetDlgItemText(IDC_EDITChs, temp, 20); int TotalChannel = atoi(temp); //get the channel which is written GetDlgItemText(IDC_EDITCh, temp, 20); int WriteChannel = atoi(temp); //get written data GetDlgItemText(IDC_EDITAOValue, strTemp); for(int i = 0; i < sizeof(strTemp); i++) { ctemp[i] = strTemp[i]; } fValue = (float)atof(ctemp); BOOL iret = pac_WriteModulePowerOnValueAO(hPort, slot, WriteChannel, TotalChannel, fValue); uart_Close(hPort); if(!iret) { ::MessageBox(NULL, "Write PowerOn ValueAO error", "87k_ao_poweron_safe", MB_OK); } } void CMy87k_ao_poweron_safeDlg::OnbtnReadSafe() { // TODO: Add your control notification handler code here HANDLE hPort = uart_Open(""); TCHAR temp[20]; CString strTemp; float fValue = 0.0; //get slot GetDlgItemText(IDC_COMBOSlot, temp, 20); int slot = atoi(temp); //get total channels GetDlgItemText(IDC_EDITChs, temp, 20); int TotalChannel = atoi(temp); //get the channel which is read GetDlgItemText(IDC_EDITCh, temp, 20); int Channel = atoi(temp); BOOL iret = pac_ReadModuleSafeValueAO(hPort, slot, Channel, TotalChannel, &fValue); uart_Close(hPort); if(!iret) { ::MessageBox(NULL, "Read Safe ValueAO error", "87k_ao_poweron_safe", MB_OK); } else { sprintf(temp, "Read Safe ValueAO: %.4f", fValue); SetDlgItemText(IDC_EDITInfor, temp); } } void CMy87k_ao_poweron_safeDlg::OnbtnWrietSafe() { // TODO: Add your control notification handler code here HANDLE hPort = uart_Open(""); TCHAR temp[20]; CString strTemp; char ctemp[20]; float fValue = 0.0; //get slot GetDlgItemText(IDC_COMBOSlot, temp, 20); int slot = atoi(temp); //get total channels GetDlgItemText(IDC_EDITChs, temp, 20); int TotalChannel = atoi(temp); //get the channel which is written GetDlgItemText(IDC_EDITCh, temp, 20); int WriteChannel = atoi(temp); //get written data GetDlgItemText(IDC_EDITAOValue, strTemp); for(int i = 0; i < sizeof(strTemp); i++) { ctemp[i] = strTemp[i]; } fValue = (float)atof(ctemp); BOOL iret = pac_WriteModuleSafeValueAO(hPort, slot, WriteChannel, TotalChannel, fValue); uart_Close(hPort); if(!iret) { ::MessageBox(NULL, "Write Safe ValueAO error", "87k_ao_poweron_safe", MB_OK); } }