// DACDlg.cpp : implementation file // #include "stdafx.h" #include "DAC.h" #include "DACDlg.h" #include "ACCES32.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #define MaxCh 6 ///////////////////////////////////////////////////////////////////////////// // CDACDlg dialog CDACDlg::CDACDlg(CWnd* pParent /*=NULL*/) : CDialog(CDACDlg::IDD, pParent) { //{{AFX_DATA_INIT(CDACDlg) m_BaseAddress = _T("300"); m_Status = _T("Please configure the dialog options shown to reflect the settings on the card that is installed. The card's output voltage shown onscreen will only be correct if these settings are correct. Refer to the card's manual for specifics about jumper settings and switches."); m_Range = 0; m_Channel = 0; m_Output = _T("DACs update as you move the slider"); //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CDACDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CDACDlg) DDX_Control(pDX, IDC_SLIDER1, m_ValueSlider); DDX_Text(pDX, IDC_EDIT1, m_BaseAddress); DDX_Text(pDX, IDC_EDIT2, m_Status); DDX_Radio(pDX, IDC_RADIO1, m_Range); DDX_Radio(pDX, IDC_RADIO6, m_Channel); DDX_Text(pDX, IDC_OUTPUT, m_Output); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CDACDlg, CDialog) //{{AFX_MSG_MAP(CDACDlg) ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDOK, OnInit) ON_BN_CLICKED(IDCANCEL, OnExit) ON_WM_TIMER() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CDACDlg message handlers BOOL CDACDlg::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 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 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 CDACDlg::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 CDACDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CDACDlg::OnExit() { if (RunFlag) KillTimer(0); exit(0); } void CDACDlg::OnInit() { unsigned data = 0; RunFlag = 0; Span = 5.0; Offset = 2.5; CurrentValue = 0; m_ValueSlider.SetRange(0, 4095, true); m_ValueSlider.SetTicFreq(410); UpdateData(true); sscanf(m_BaseAddress, "%x", &data); if (data >= 0x100) { BaseAddress = data; RunFlag = 1; } else Beep(8000, 500); if (RunFlag) { m_ValueSlider.ShowWindow(SW_SHOW); SetTimer(0, 100, NULL); } } unsigned CDACDlg::ConvertForOutput(unsigned v) { if (m_Channel < MaxCh) OutPort(BaseAddress+(m_Channel*2),v); else for (int i=0; i=1;i--) temp += (input & (1<<(i-1))) ? '1' : '0'; temp += "xxxx "; f = input * Span/4096 - Offset; sprintf(text, "%3.3X", input); temp += text; sprintf(text, "%8.3f", f); temp += text; temp += (m_Range > 4) ? " mA" : " Volts"; return temp; } void CDACDlg::UpdateDAC() { switch(m_Range) { case 0: Offset = 2.5; Span = 5.0; break; case 1: Offset = 5.0; Span = 10.0; break; case 2: Offset = 10.0; Span = 20.0; break; case 3: Offset = 0.0; Span = 5.0; break; case 4: Offset = 0.0; Span = 10.0; break; case 5: Offset = -1.0; Span = 4.0; break; case 6: Offset = -4.0; Span = 16.0; break; } m_Output = IntToBin(ConvertForOutput(CurrentValue)); UpdateData(false); } void CDACDlg::OnTimer(UINT nIDEvent) { UpdateData(true); CurrentValue = m_ValueSlider.GetPos(); UpdateDAC(); CDialog::OnTimer(nIDEvent); }