// IRQSMDlg.cpp : implementation file // #include "stdafx.h" #include "IRQSAMP.h" #include "IRQSMDlg.h" #include "Win32IRQ.h" #include "ACCES32.h" #include "IRQThrd.h" CIRQThrd *thread; #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CIRQSAMPDlg dialog CIRQSAMPDlg::CIRQSAMPDlg(CWnd* pParent /*=NULL*/) : CDialog(CIRQSAMPDlg::IDD, pParent) { //{{AFX_DATA_INIT(CIRQSAMPDlg) m_BaseAddress = _T(""); m_BusNumber = 0; m_BusType = _T(""); m_IRQ = 0; m_IRQCount = _T(" IRQ Count: 0"); m_Status = _T(" Enter Base, IRQ and Clear Offset, then Initialize"); m_ClearOffset = _T(""); m_Offset = _T(""); m_Value = _T(""); m_ReadWriteRadio = 0; //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CIRQSAMPDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CIRQSAMPDlg) DDX_Control(pDX, IDC_STARTBUTTON, m_StartButton); DDX_Control(pDX, IDC_ABORTBUTTON, m_AbortButton); DDX_Control(pDX, IDC_WRITEBUTTON, m_WriteButton); DDX_Text(pDX, IDC_BASE, m_BaseAddress); DDX_Text(pDX, IDC_BUSNUMBER, m_BusNumber); DDX_CBString(pDX, IDC_BUSTYPE, m_BusType); DDX_Text(pDX, IDC_IRQ, m_IRQ); DDX_Text(pDX, IDC_LABEL, m_IRQCount); DDX_Text(pDX, IDC_STATUS, m_Status); DDX_Text(pDX, IDC_LATCH, m_ClearOffset); DDX_Text(pDX, IDC_OFFSET, m_Offset); DDX_Text(pDX, IDC_VALUE, m_Value); DDX_Radio(pDX, IDC_RADIO1, m_ReadWriteRadio); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CIRQSAMPDlg, CDialog) //{{AFX_MSG_MAP(CIRQSAMPDlg) ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_INITBUTTON, OnInitbutton) ON_BN_CLICKED(IDC_STARTBUTTON, OnStartbutton) ON_BN_CLICKED(IDC_WRITEBUTTON, OnWritebutton) ON_BN_CLICKED(IDC_EXITBUTTON, OnExitbutton) ON_BN_CLICKED(IDC_READBUTTON, OnReadbutton) ON_BN_CLICKED(IDC_ABORTBUTTON, OnAbortbutton) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CIRQSAMPDlg message handlers BOOL CIRQSAMPDlg::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 // TODO: Add extra initialization here 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); } m_AbortButton.EnableWindow(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 CIRQSAMPDlg::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 CIRQSAMPDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } // Note: Everything before this point was created by Visual C++ void CIRQSAMPDlg::OnInitbutton() { short BT = InterfaceTypeUndefined; unsigned long BaseAddress; unsigned short ClearOffset; UpdateData(true); if (m_BusType == "PCI") BT = PCIBus; else if (m_BusType == "ISA") BT = Isa; sscanf(m_BaseAddress, "%lx", &BaseAddress); sscanf(m_ClearOffset, "%lx", &ClearOffset); unsigned char Success; if (m_ReadWriteRadio == 0) Success = InitGenDriver(BaseAddress, m_IRQ, BT, m_BusNumber, ClearOffset, WRITE_TO_CLEAR); else Success = InitGenDriver(BaseAddress, m_IRQ, BT, m_BusNumber, ClearOffset, READ_TO_CLEAR); if (Success) m_Status = " Setup card using Write Port, then press Start Acquisition"; else m_Status = " Driver Error During Initialization"; UpdateData(false); } void CIRQSAMPDlg::OnStartbutton() { UpdateData(true); thread = (CIRQThrd*)AfxBeginThread(RUNTIME_CLASS(CIRQThrd),THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED,NULL); thread->InitWnd(m_hWnd); thread->ResumeThread(); m_StartButton.EnableWindow(false); m_AbortButton.EnableWindow(true); } void CIRQSAMPDlg::OnWritebutton() { unsigned long Base; unsigned short Offset; unsigned char Value; UpdateData(true); sscanf(m_BaseAddress, "%lx", &Base); sscanf(m_Offset, "%lx", &Offset); sscanf(m_Value, "%lx", &Value); OutPortB(Base + Offset, Value); } void CIRQSAMPDlg::OnExitbutton() { exit(0); } void CIRQSAMPDlg::OnReadbutton() { unsigned long Base; unsigned short Offset; unsigned short Value; char text[16]; UpdateData(true); sscanf(m_BaseAddress, "%lx", &Base); sscanf(m_Offset, "%lx", &Offset); Value = InPortB(Base + Offset); sprintf(text, "%x", Value); m_Value = text; UpdateData(false); } void CIRQSAMPDlg::OnAbortbutton() { thread->Terminated = true; AbortRequest(); m_Status = "Aborted - press Start Acquisition to resume"; UpdateData(false); m_StartButton.EnableWindow(true); m_AbortButton.EnableWindow(false); }