// 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 Bits (m_Resolution == 0 ? 12 : 16) #define MyKey "Software\\PCIFIND\\NTioPCI\\Parameters" #define InsCR(x) x += 0x0d; x += 0x0a; TPCI_COMMON_CONFIG buf[64]; unsigned long WhichAddress[64]; int NumChannels[64]; bool RunFlag; ///////////////////////////////////////////////////////////////////////////// // CDACDlg dialog CDACDlg::CDACDlg(CWnd* pParent /*=NULL*/) : CDialog(CDACDlg::IDD, pParent) { //{{AFX_DATA_INIT(CDACDlg) m_BaseAddress = _T("300"); m_Status = _T(""); m_Range = 1; m_Channel = 0; m_Output = _T("DACs update as you move the slider"); m_Resolution = 0; // m_CardName = _T("No PCI DAC Card Found In Registry"); m_PciAddress = _T(""); //}}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_EDIT2, m_StatusControl); DDX_Control(pDX, IDC_PCICOMBO1, m_CardComboControl); DDX_Control(pDX, IDC_PCISTATIC, m_PciStaticControl); DDX_Control(pDX, IDC_ISASTATIC, m_IsaStatic); DDX_Control(pDX, IDC_ISAGROUP, m_IsaGroup); DDX_Control(pDX, IDC_ISAEDIT, m_IsaEdit); 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); DDX_Radio(pDX, IDC_RADIO9, m_Resolution); DDX_Text(pDX, IDC_CARD, m_CardName); //}}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() ON_CBN_SELCHANGE(IDC_PCICOMBO1, OnSelchangePcicombo1) //}}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 FindCards(); // 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); } 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; Span = 10.0; Offset = 5.0; CurrentValue = 0; MaxCh = 16; m_ValueSlider.SetRange(0, 65535, true); m_ValueSlider.SetTicFreq(6554); UpdateData(true); UpdateData(false); try { if (!RunFlag) sscanf(m_BaseAddress, "%x", &data); } catch(...) { data = 0; } if (data>0x100) { BaseAddress=data; RunFlag=1; } if (RunFlag) { InPortB(BaseAddress+2); //remove simul mode InPortB(BaseAddress+15); //remove zero latch m_ValueSlider.ShowWindow(SW_SHOW); SetTimer(0, 100, NULL); } } // This function accepts a value of 0-65535 and returns // the value scaled for the current DAC settings. //12 bit is 0-4095 and 16-bit is 0-65535. unsigned CDACDlg::ConvertForOutput(unsigned v) { v = unsigned(((double(v) / 65535.0) * ((1 << Bits) - 1)));//scale for 12 or 16 bits if (m_Channel < MaxCh) OutPort(BaseAddress+(m_Channel*2),v); else { InPortB(BaseAddress);//enter simultaneous mode without updating DACs for (int i=0; i=1; i--) temp += (input & (1<<(i-1))) ? '1' : '0'; if (Bits == 12) temp += "xxxx "; else temp += " "; f = (((1<<(Bits + 1)) - 1) & input) * (Span/(1< 5) ? " mA" : " Volts"; return temp; } void CDACDlg::UpdateDAC() { switch(m_Range) { case 0: Offset = 10.0; Span = 20.0; break; case 1: Offset = 5.0; Span = 10.0; break; case 2: Offset = 2.5; Span = 5.0; break; case 3: Offset = 0.0; Span = 10.0; break; case 4: Offset = 0.0; Span = 5.0; break; case 5: Offset = 0.0; Span = 2.5; 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); } void CDACDlg::FindCards(void) { int i, n = 0; HKEY Key; unsigned long DataType, DataLength; long Num; char AddStr[255]; InsCR(m_Status); RegOpenKeyEx(HKEY_LOCAL_MACHINE, MyKey, 0, KEY_ALL_ACCESS, &Key); DataLength = sizeof(Num); RegQueryValueEx(Key, "NumDevices", NULL, &DataType, (PUCHAR)&Num, &DataLength); if (Num > 0) { DataLength = Num * sizeof(TPCI_COMMON_CONFIG); RegQueryValueEx(Key, "PCICommonConfig", NULL, &DataType, (PUCHAR)buf, &DataLength); RunFlag = true; } for (i=0; i