// Util6208Dlg.cpp : implementation file // #include "stdafx.h" #include "math.h" #include "Util6208.h" #include "Util6208Dlg.h" #ifdef _DEBUG #define new DEBUG_NEW #endif #ifndef M_PI #define M_PI 3.14159265359 #endif // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data enum { IDD = IDD_ABOUTBOX }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support // Implementation protected: DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) END_MESSAGE_MAP() // CUtil6208Dlg dialog CUtil6208Dlg::CUtil6208Dlg(I16 hCard, CWnd* pParent /*=NULL*/) : CDialog(CUtil6208Dlg::IDD, pParent) { int i; m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); m_hCard = hCard; for( i=0; iAppendMenu(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 m_cbAOMode0.SetCurSel( m_DAMode[0] ); m_cbAOMode1.SetCurSel( m_DAMode[1] ); m_cbAOMode2.SetCurSel( m_DAMode[2] ); m_cbAOMode3.SetCurSel( m_DAMode[3] ); m_cbAOMode4.SetCurSel( m_DAMode[4] ); m_cbAOMode5.SetCurSel( m_DAMode[5] ); m_cbAOMode6.SetCurSel( m_DAMode[6] ); m_cbAOMode7.SetCurSel( m_DAMode[7] ); m_sdAOLevel0.SetRange( -32768, 32767, TRUE ); m_sdAOLevel0.SetTicFreq( 5 ); m_sdAOLevel1.SetRange( -32768, 32767, TRUE ); m_sdAOLevel1.SetTicFreq( 5 ); m_sdAOLevel2.SetRange( -32768, 32767, TRUE ); m_sdAOLevel2.SetTicFreq( 5 ); m_sdAOLevel3.SetRange( -32768, 32767, TRUE ); m_sdAOLevel3.SetTicFreq( 5 ); m_nTimer = SetTimer( 1, 200, NULL ); return TRUE; // return TRUE unless you set the focus to a control } void CUtil6208Dlg::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 CUtil6208Dlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, reinterpret_cast(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 function to obtain the cursor to display while the user drags // the minimized window. HCURSOR CUtil6208Dlg::OnQueryDragIcon() { return static_cast(m_hIcon); } void CUtil6208Dlg::OnDO0Clicked() { // TODO: Add your control notification handler code here int CheckSts; CheckSts = ((CButton*)GetDlgItem( IDC_CHECK_DO0 ))->GetCheck(); if( CheckSts == BST_CHECKED ) { m_bDOData |= 0x01; } else if( CheckSts == BST_UNCHECKED ) { m_bDOData &= (~0x01); } DO_WritePort( m_hCard, 0, m_bDOData ); } void CUtil6208Dlg::OnDO1Clicked() { // TODO: Add your control notification handler code here int CheckSts; CheckSts = ((CButton*)GetDlgItem( IDC_CHECK_DO1 ))->GetCheck(); if( CheckSts == BST_CHECKED ) { m_bDOData |= 0x02; } else if( CheckSts == BST_UNCHECKED ) { m_bDOData &= (~0x02); } DO_WritePort( m_hCard, 0, m_bDOData ); } void CUtil6208Dlg::OnDO2Clicked() { // TODO: Add your control notification handler code here int CheckSts; CheckSts = ((CButton*)GetDlgItem( IDC_CHECK_DO2 ))->GetCheck(); if( CheckSts == BST_CHECKED ) { m_bDOData |= 0x04; } else if( CheckSts == BST_UNCHECKED ) { m_bDOData &= (~0x04); } DO_WritePort( m_hCard, 0, m_bDOData ); } void CUtil6208Dlg::OnDO3Clicked() { // TODO: Add your control notification handler code here int CheckSts; CheckSts = ((CButton*)GetDlgItem( IDC_CHECK_DO3 ))->GetCheck(); if( CheckSts == BST_CHECKED ) { m_bDOData |= 0x08; } else if( CheckSts == BST_UNCHECKED ) { m_bDOData &= (~0x08); } DO_WritePort( m_hCard, 0, m_bDOData ); } void CUtil6208Dlg::OnTimer(UINT_PTR nIDEvent) { // TODO: Add your message handler code here and/or call default U32 dwPortData; int i; I16 p; double m; DI_ReadPort( m_hCard, 0, &dwPortData); dwPortData = ( dwPortData & 0x0F ); if( dwPortData != m_bDIData ) { m_bDIData = (U8)( dwPortData & 0xFF ); if( (dwPortData & 0x01) == 0x01 ) { m_DI0_ON.SetIcon( AfxGetApp()->LoadIcon(IDI_ICON_RED) ) ; } else { m_DI0_ON.SetIcon( AfxGetApp()->LoadIcon(IDI_ICON_BLACK) ) ; } if( (dwPortData & 0x02) == 0x02 ) { m_DI1_ON.SetIcon( AfxGetApp()->LoadIcon(IDI_ICON_RED) ) ; } else { m_DI1_ON.SetIcon( AfxGetApp()->LoadIcon(IDI_ICON_BLACK) ) ; } if( (dwPortData & 0x04) == 0x04 ) { m_DI2_ON.SetIcon( AfxGetApp()->LoadIcon(IDI_ICON_RED) ) ; } else { m_DI2_ON.SetIcon( AfxGetApp()->LoadIcon(IDI_ICON_BLACK) ) ; } if( (dwPortData & 0x08) == 0x08 ) { m_DI3_ON.SetIcon( AfxGetApp()->LoadIcon(IDI_ICON_RED) ) ; } else { m_DI3_ON.SetIcon( AfxGetApp()->LoadIcon(IDI_ICON_BLACK) ) ; } } /* Analog Output */ for (i=0; i