// Sample 0Dlg.cpp : implementation file // #include "stdafx.h" #include "Sample 0.h" #include "Sample 0Dlg.h" #include "ACCES32.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #define InsCR(x) x += 0x0d; x += 0x0a; unsigned int BaseAddress; bool TestRunning = false; UINT TestTimer; CString *VoltsLabels[8]; CString *CountsLabels[8]; ///////////////////////////////////////////////////////////////////////////// // CSample0Dlg dialog CSample0Dlg::CSample0Dlg(CWnd* pParent /*=NULL*/) : CDialog(CSample0Dlg::IDD, pParent) { //{{AFX_DATA_INIT(CSample0Dlg) m_CountsLabel0 = _T(""); m_CountsLabel1 = _T(""); m_CountsLabel2 = _T(""); m_CountsLabel3 = _T(""); m_CountsLabel4 = _T(""); m_CountsLabel5 = _T(""); m_CountsLabel6 = _T(""); m_CountsLabel7 = _T(""); m_Instructions = _T(""); m_VoltsLabel0 = _T(""); m_VoltsLabel1 = _T(""); m_VoltsLabel2 = _T(""); m_VoltsLabel3 = _T(""); m_VoltsLabel4 = _T(""); m_VoltsLabel5 = _T(""); m_VoltsLabel6 = _T(""); m_VoltsLabel7 = _T(""); m_BaseEdit = _T("300"); //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CSample0Dlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CSample0Dlg) DDX_Control(pDX, IDC_BaseEdit, m_BaseEditCtrl); DDX_Control(pDX, IDOK, m_TestButtonCtrl); DDX_Text(pDX, IDC_CountsLabel0, m_CountsLabel0); DDX_Text(pDX, IDC_CountsLabel1, m_CountsLabel1); DDX_Text(pDX, IDC_CountsLabel2, m_CountsLabel2); DDX_Text(pDX, IDC_CountsLabel3, m_CountsLabel3); DDX_Text(pDX, IDC_CountsLabel4, m_CountsLabel4); DDX_Text(pDX, IDC_CountsLabel5, m_CountsLabel5); DDX_Text(pDX, IDC_CountsLabel6, m_CountsLabel6); DDX_Text(pDX, IDC_CountsLabel7, m_CountsLabel7); DDX_Control(pDX, IDC_ErrorStatus, m_ErrorStatus); DDX_Text(pDX, IDC_Instructions, m_Instructions); DDX_Text(pDX, IDC_VoltsLabel0, m_VoltsLabel0); DDX_Text(pDX, IDC_VoltsLabel1, m_VoltsLabel1); DDX_Text(pDX, IDC_VoltsLabel2, m_VoltsLabel2); DDX_Text(pDX, IDC_VoltsLabel3, m_VoltsLabel3); DDX_Text(pDX, IDC_VoltsLabel4, m_VoltsLabel4); DDX_Text(pDX, IDC_VoltsLabel5, m_VoltsLabel5); DDX_Text(pDX, IDC_VoltsLabel6, m_VoltsLabel6); DDX_Text(pDX, IDC_VoltsLabel7, m_VoltsLabel7); DDX_Text(pDX, IDC_BaseEdit, m_BaseEdit); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CSample0Dlg, CDialog) //{{AFX_MSG_MAP(CSample0Dlg) ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_WM_TIMER() ON_BN_CLICKED(IDOK, OnStartButtonClick) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CSample0Dlg message handlers BOOL CSample0Dlg::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 CountsLabels[0] = &m_CountsLabel0; CountsLabels[1] = &m_CountsLabel1; CountsLabels[2] = &m_CountsLabel2; CountsLabels[3] = &m_CountsLabel3; CountsLabels[4] = &m_CountsLabel4; CountsLabels[5] = &m_CountsLabel5; CountsLabels[6] = &m_CountsLabel6; CountsLabels[7] = &m_CountsLabel7; VoltsLabels[0] = &m_VoltsLabel0; VoltsLabels[1] = &m_VoltsLabel1; VoltsLabels[2] = &m_VoltsLabel2; VoltsLabels[3] = &m_VoltsLabel3; VoltsLabels[4] = &m_VoltsLabel4; VoltsLabels[5] = &m_VoltsLabel5; VoltsLabels[6] = &m_VoltsLabel6; VoltsLabels[7] = &m_VoltsLabel7; m_Instructions = "Sample 0"; InsCR(m_Instructions); m_Instructions += "This sample reads from all channels on the A/D card and displays them for you."; InsCR(m_Instructions); m_Instructions += "Board Configuration Requirements:"; InsCR(m_Instructions); m_Instructions += "RANGE: 5 Volt Range"; InsCR(m_Instructions); m_Instructions += "POLARITY: Bipolar"; InsCR(m_Instructions); m_Instructions += "Please enter the base address (in hex) in the text box below, and click the 'Start Test' button to begin."; if (InPortB(0x61) == 0xAA55) { MessageBox("ACCESNT.SYS not detected. Please copy ACCESNT.SYS into [NT]/system32/drivers and re-run this sample.", "Warning", MB_OK); } // TODO: Add extra initialization here UpdateData(false); return TRUE; // return TRUE unless you set the focus to a control } // 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 CSample0Dlg::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 CSample0Dlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CSample0Dlg::OnTimer(UINT nIDEvent) { // TestRunning = true; int chan, counts; unsigned int timeout; double volts; char TempString[255]; UpdateData(true); for (chan = 0; chan <= 7; chan++) { timeout = 65535; OutPortB(BaseAddress + 2, chan | 0x08); // write channel while (!CheckForEOC(BaseAddress) && (timeout > 0)) timeout--; if (timeout == 0) { m_ErrorStatus.SetWindowText("A/D timeout on Channel " + chan); *CountsLabels[chan] = "A/D Timeout"; *VoltsLabels[chan] = "A/D Timeout"; } // end if timeout else { counts = InPort(BaseAddress + 2); volts = ((counts ^ 2048) - 2048.0) * 0.00244; sprintf(TempString, "%4d", counts); *CountsLabels[chan] = TempString; sprintf(TempString, "%9.8f", volts); *VoltsLabels[chan] = TempString; } // end else } // end for chan UpdateData(false); CDialog::OnTimer(nIDEvent); } void CSample0Dlg::OnStartButtonClick() { if (TestRunning) { m_ErrorStatus.SetWindowText(""); m_TestButtonCtrl.SetWindowText("Start Test"); m_BaseEditCtrl.EnableWindow(true); KillTimer(TestTimer); TestRunning = false; } // end if else { sscanf(m_BaseEdit.GetBuffer(0), "%x", &BaseAddress); m_TestButtonCtrl.SetWindowText("Abort Test"); m_BaseEditCtrl.EnableWindow(false); TestRunning = true; TestTimer = SetTimer(1, 100, NULL); } // end else UpdateData(false); } bool CSample0Dlg::CheckForEOC(int Address) { unsigned short EOCCheck; EOCCheck = InPortB(Address); return ((EOCCheck & 0x80) == 0x80); }