// Sample0Dlg.cpp : implementation file // #include "stdafx.h" #include "Sample0.h" #include "Sample0Dlg.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; CString ChannelLabels[16]; ///////////////////////////////////////////////////////////////////////////// // CSample0Dlg dialog CSample0Dlg::CSample0Dlg(CWnd* pParent /*=NULL*/) : CDialog(CSample0Dlg::IDD, pParent) { //{{AFX_DATA_INIT(CSample0Dlg) m_BaseEdit = _T("300"); m_CardTitle = _T("A12-16E"); m_Instructions = _T("Sample 0"); m_ChannelLabel = _T(""); //}}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_INSTRUCT_TEXT, m_InstructControl); DDX_Control(pDX, IDOK, m_TestButton); DDX_Text(pDX, IDC_BASE_EDIT, m_BaseEdit); DDX_Text(pDX, IDC_TITLE_LABEL, m_CardTitle); DDX_Text(pDX, IDC_INSTRUCT_TEXT, m_Instructions); DDX_Text(pDX, IDC_ChannelLabel, m_ChannelLabel); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CSample0Dlg, CDialog) //{{AFX_MSG_MAP(CSample0Dlg) ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDCANCEL, OnExitButtonClick) ON_BN_CLICKED(IDOK, OnTestButtonClick) ON_WM_TIMER() ON_WM_SHOWWINDOW() //}}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 int i = 0; CString ThisLabel = ""; InsCR(m_Instructions); m_Instructions += _T("This sample will read data from all sixteen channels on the A/D card."); InsCR(m_Instructions); m_Instructions += _T("Board Configuration Requirements:"); InsCR(m_Instructions); m_Instructions += _T("CHANNEL SELECTION: 16 Channel Single-Ended"); 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."); for (i = 0; i <= 15; i++) { ThisLabel.Format("Channel %1X", i); m_ChannelLabel += ThisLabel; 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::OnExitButtonClick() { exit(0); } // end OnExitButtonClick void CSample0Dlg::OnTestButtonClick() { static bool TimerEnabled = false; if (TimerEnabled) { TimerEnabled = false; int i = 0; CString ThisLabel = ""; m_TestButton.SetWindowText("Start Test"); m_ChannelLabel.Empty(); for (i = 0; i <= 15; i++) { ThisLabel.Format("Channel %1X 0", i); m_ChannelLabel += ThisLabel; InsCR(m_ChannelLabel); } UpdateData(false); KillTimer(0); } else { TimerEnabled = true; m_TestButton.SetWindowText("Abort Test"); SetTimer(0, 100, NULL); } } // end OnTestButtonClick void CSample0Dlg::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default int channel, timeout; double data; CString ThisLabel = ""; sscanf(m_BaseEdit.GetBuffer(0), "%x", &base); for (channel=0; channel<=15; channel++) { timeout = 1000; OutPortB(base+2, channel); Sleep (2); OutPortB(base+3, 0); while (!((InPortB(base+2) & 0x80) == 0) & (timeout >= 0)) timeout--; if (timeout < 0){ m_ChannelLabel.Format("Timeout on channel %1X", channel); UpdateData(false); break; } data=InPort(base+6) >> 4; if (channel == 0) m_ChannelLabel.Format("Channel %1X %g",channel,data); else { ThisLabel.Format("Channel %1X %g",channel,data); InsCR(m_ChannelLabel); m_ChannelLabel += ThisLabel; } // end else } // end for UpdateData(false); CDialog::OnTimer(nIDEvent); } void CSample0Dlg::OnShowWindow(BOOL bShow, UINT nStatus) { CDialog::OnShowWindow(bShow, nStatus); }