// ScanDlg.cpp : implementation file // #include "stdafx.h" #include "Scan.h" #include "ScanDlg.h" #include "ACCES32.h" #define MyKey "Software\\PCIFIND\\NTioPCI\\Parameters" #define InsCR(x) x += 0x0d; x += 0x0a; TPCI_COMMON_CONFIG buf[64]; unsigned long Address16; unsigned long Address8; bool done = false; #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CScanDlg dialog CScanDlg::CScanDlg(CWnd* pParent /*=NULL*/) : CDialog(CScanDlg::IDD, pParent) { //{{AFX_DATA_INIT(CScanDlg) m_Address16 = _T(""); m_Address8 = _T(""); m_StatusLabel = _T("Enter Addresses of PCI-AI16-16A then press Start."); m_OutMemo = _T(""); //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CScanDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CScanDlg) DDX_Control(pDX, IDC_OutMemo, m_OutMemoCtrl); DDX_Control(pDX, IDC_StopButton, m_StopButtonCtrl); DDX_Control(pDX, IDC_StartButton, m_StartButtonCtrl); DDX_Text(pDX, IDC_Address16Edit, m_Address16); DDX_Text(pDX, IDC_Address8Edit, m_Address8); DDX_Text(pDX, IDC_StatusLabel, m_StatusLabel); DDX_Text(pDX, IDC_OutMemo, m_OutMemo); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CScanDlg, CDialog) //{{AFX_MSG_MAP(CScanDlg) ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_StartButton, OnStartButtonClick) ON_BN_CLICKED(IDC_StopButton, OnStopButtonClick) ON_BN_CLICKED(IDC_ExitButton, OnExitButtonClick) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CScanDlg message handlers BOOL CScanDlg::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; bool found; HKEY Key; unsigned long DataType, DataLength; long Num; char AddStr[255]; found = false; RegOpenKeyEx(HKEY_LOCAL_MACHINE, MyKey, 0, KEY_READ, &Key); DataLength = sizeof(Num); if (RegQueryValueEx(Key, "NumDevices", NULL, &DataType, (PUCHAR)&Num, &DataLength) != ERROR_SUCCESS) Num = 0; if (Num > 0) { DataLength = Num * sizeof(TPCI_COMMON_CONFIG); RegQueryValueEx(Key, "PCICommonConfig", NULL, &DataType, (PUCHAR)buf, &DataLength); } for (i=0; i> 8; OutPortB(Base + c, temp); } unsigned CScanDlg::CtrRead(unsigned int Base, unsigned int c) { OutPortB(Base + 3, c << 6); return InPortB(Base + c) + (InPortB(Base + c) << 8); } void CScanDlg::ProcessMessages() { CWinApp* pApp = AfxGetApp(); MSG msg; while ( PeekMessage ( &msg, NULL, 0, 0, PM_NOREMOVE )) pApp->PumpMessage(); } void CScanDlg::OnStartButtonClick() { int i, j; CString HeaderString, TempString, TempString2; int maxchan; double span; bool bipolar; int length; UpdateData(true); sscanf(m_Address16.GetBuffer(0), "%X", &Address16); sscanf(m_Address8.GetBuffer(0), "%X", &Address8); m_StartButtonCtrl.ShowWindow(SW_HIDE); m_StopButtonCtrl.ShowWindow(SW_SHOW); done = false; m_OutMemo.Empty(); UpdateData(false); TempString = "Card is configured for "; if ((InPortB(Address8 + 8) & 1) == 1) { maxchan = 15; TempString += "Single Ended (16CH), "; } else { maxchan = 7; TempString += "Differential (8CH), "; } // end if/else if ((InPortB(Address8+8) & 4) == 4) span = 10.0; else span = 20.0; if ((InPortB(Address8 + 8) & 2) == 2) { bipolar = true; TempString2.Format("±%.2f (Bipolar) Volt Range.", span / 2); TempString += TempString2; } else { bipolar = false; TempString2.Format("0 - %.2f (Unipolar) Volt Range.", span); TempString += TempString2; } // end if/else m_StatusLabel = TempString; UpdateData(false); UpdateData(true); OutPortB(Address8 + 0xD, 1); //turn on 2s complement. CtrMode(Address8 + 0x14, 0, 2); //set counter 0 mode 2 CtrMode(Address8 + 0x14, 1, 2); //set counter 1 mode 2 CtrMode(Address8 + 0x14, 2, 2); //set counter 2 mode 2 CtrLoad(Address8 + 0x14, 0, 5); CtrLoad(Address8 + 0x14, 1, 1000); //divide counter source by (1000x1000) to get 10Hz CtrLoad(Address8 + 0x14, 2, 1000); OutPortB(Address8 + 0x1E, 0xC0); //counter enable OutPortB(Address8 + 0x3, 0); //disable burst //0x20 half //0x80 half while ((InPortB(Address8 + 0x8) & 0x80) != 0x80) InPort(Address16); //read fifo until empty OutPortB(Address8 + 0x2, (maxchan << 4)); //write high and low scan limits OutPortB(Address8 + 0x1B, 0x01); //gate timer, start timing OutPortB(Address8 + 0x1A, 0x11); //GO! 1 sample per channel HeaderString = ""; for (i = 0; i <= maxchan; i++) { TempString2.Format("%d\t", i); HeaderString += TempString2; if (i == 7) HeaderString = HeaderString; } // end for i m_OutMemo += HeaderString; TempString = ""; UpdateData(false); do { while((InPortB(Address8 + 0x8) & 0x80) > 0) ProcessMessages(); // wait for not empty TempString = ""; while (!((InPortB(Address8 + 0x8) & 0x80) > 0)) { //drain until empty j = InPort(Address16); if (bipolar) j = (short)(j); TempString2.Format("%6.3f\t", (j / 65536.0) * span); TempString += TempString2; }; // end while not InPortB UpdateData(false); UpdateData(true); length = m_OutMemo.GetLength(); if (length > 943) { m_OutMemo.Delete(0, 74); m_OutMemo = HeaderString + m_OutMemo; } InsCR(m_OutMemo); m_OutMemo += TempString; UpdateData(false); ProcessMessages(); } while (!done); CtrMode(Address8 + 0x14, 2, 2); //stop data InsCR(m_OutMemo); m_OutMemo += "Program done."; UpdateData(false); } void CScanDlg::OnStopButtonClick() { UpdateData(true); done = true; m_StartButtonCtrl.ShowWindow(SW_SHOW); m_StopButtonCtrl.ShowWindow(SW_HIDE); UpdateData(false); } void CScanDlg::OnExitButtonClick() { OnStopButtonClick(); exit(0); }