// 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; int base = 0x300; ///////////////////////////////////////////////////////////////////////////// // CSample0Dlg dialog CSample0Dlg::CSample0Dlg(CWnd* pParent /*=NULL*/) : CDialog(CSample0Dlg::IDD, pParent) { //{{AFX_DATA_INIT(CSample0Dlg) m_BaseEdit = _T("300"); m_ChannelLabel = _T(""); m_Instructions = _T("Sample 0"); m_CardName = _T("AD12-8"); //}}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, IDOK, m_TestButton); DDX_Text(pDX, IDC_BASE_EDIT, m_BaseEdit); DDX_Text(pDX, IDC_ChannelLabels, m_ChannelLabel); DDX_Text(pDX, IDC_INSTRUCT_TEXT, m_Instructions); DDX_Text(pDX, IDC_TITLE_LABEL, m_CardName); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CSample0Dlg, CDialog) //{{AFX_MSG_MAP(CSample0Dlg) ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_WM_TIMER() ON_BN_CLICKED(IDCANCEL, OnExitButtonClick) ON_BN_CLICKED(IDOK, OnTestButtonClick) //}}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 InsCR(m_Instructions); m_Instructions += _T("This sample reads the eight analog inputs and displays them for you."); InsCR(m_Instructions); m_Instructions += _T("Please enter the base address (in hex) in the text box below, and click the 'Start Test' button to begin."); CString ThisLabel; int i = 0; for (i = 0; i <= 7; i++) { ThisLabel.Format("Channel %1X", i); m_ChannelLabel += ThisLabel; InsCR(m_ChannelLabel); InsCR(m_ChannelLabel); } 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); } UpdateData(false); // TODO: Add extra initialization here 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) { int channel, counts, i, j; double volts; CString ThisLabel = ""; CString RangeString = ""; sscanf(m_BaseEdit.GetBuffer(0), "%x", &base); for (channel = 0; channel <= 7; channel++) { OutPortB(base+2, channel); // Set channel if ((channel % 2) == 0) { // Set gain: OutPortB(base+3, 0x00); // +/-5v range on even channels RangeString = "±5V"; } // end if else { OutPortB(base+3, 0x08); // +/-10v range on odd channels RangeString = "±10v"; } // end else for (i = 0;i < 2000;i++); // Wait for settle count, this is an empty loop OutPortB(base+1, 0); // Start A/D conversion j = 0; // Wait for EOC or timeout while (((InPortB(base+2) & 0x80) >= 0x80) & (j < 2000)) j++; if (j >=2000) { m_ChannelLabel.Format("Timeout on channel %1X", channel); UpdateData(false); break; } // end if counts = InPort(base) >> 4; // Read count data // Scaling 5v range on 12 bit device = 0.00244v/count volts = (counts-2048.0)*0.00244; // Display results if (channel == 0) m_ChannelLabel.Format("Channel %1X %d %g %4s",channel,counts,volts,RangeString); else { ThisLabel.Format("Channel %1X %d %g %4s",channel,counts,volts,RangeString); InsCR(m_ChannelLabel); InsCR(m_ChannelLabel); m_ChannelLabel += ThisLabel; } // end else } // end for UpdateData(false); CDialog::OnTimer(nIDEvent); } void CSample0Dlg::OnExitButtonClick() { exit(0); } void CSample0Dlg::OnTestButtonClick() { static bool TimerEnabled = false; if (TimerEnabled) { TimerEnabled = false; int i = 0; CString ThisLabel = ""; m_ChannelLabel.Empty(); m_TestButton.SetWindowText("Start Test"); for (i = 0; i <= 7; i++) { ThisLabel.Format("Channel %1X 0 0 0", i); m_ChannelLabel += ThisLabel; InsCR(m_ChannelLabel); InsCR(m_ChannelLabel); } UpdateData(false); KillTimer(0); } else { TimerEnabled = true; m_TestButton.SetWindowText("Abort Test"); SetTimer(0, 100, NULL); } }