// IIRO8Dlg.cpp : implementation file // // Calls to OutPortB() InPortB() have been changed to RelOutPortB() RelInPortB() // They now use CardNum = 0, and address "Offset" instead of just "Address" #include "stdafx.h" #include "IIRO8.h" #include "IIRO8Dlg.h" #include "AIOWDM.h" //#define MyKey "Software\\PCIFIND\\NTioPCI\\Parameters" #define InsCR(x) x += 0x0d; x += 0x0a; // One and only Device: unsigned int Status = 0; int NumCards = 0; // We will only handle one card long CardNum = 0; // new dirver uses card number int Channels = 8; // num channels on the card struct TCardData { bool IsValid; bool IsSelected; unsigned long DeviceID; unsigned long Base; // This the result of findcards and the base address of the card }; struct TCardData CardData; // only set up for one card here bool RunFlag; unsigned long Address; #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CIIRO8Dlg dialog CIIRO8Dlg::CIIRO8Dlg(CWnd* pParent /*=NULL*/) : CDialog(CIIRO8Dlg::IDD, pParent) { //{{AFX_DATA_INIT(CIIRO8Dlg) m_StatusEdit = _T(""); m_CardName = _T(""); m_IsaEdit = _T("300"); m_BaseStatic = _T(""); m_RelayOutput = _T("00000000"); m_RelayReadback = _T("00000000"); m_OptoInput = _T("00000000"); //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CIIRO8Dlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CIIRO8Dlg) DDX_Control(pDX, IDC_ISA_STATIC, m_IsaStatic); DDX_Control(pDX, IDC_STATUS, m_StatusControl); DDX_Control(pDX, IDC_ISA_EDIT, m_IsaEditCtrl); DDX_Control(pDX, IDOK, m_TimerButton); DDX_Text(pDX, IDC_STATUS, m_StatusEdit); DDX_Text(pDX, IDC_CARD_NAME, m_CardName); DDX_Text(pDX, IDC_ISA_EDIT, m_IsaEdit); DDX_Text(pDX, IDC_BASESTATIC, m_BaseStatic); DDX_Text(pDX, IDC_OUTPUTA, m_RelayOutput); DDX_Text(pDX, IDC_INPUTA, m_RelayReadback); DDX_Text(pDX, IDC_INPUTB, m_OptoInput); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CIIRO8Dlg, CDialog) //{{AFX_MSG_MAP(CIIRO8Dlg) ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDCANCEL, OnExitButton) ON_BN_CLICKED(IDOK, OnBeginButton) ON_WM_TIMER() ON_WM_SHOWWINDOW() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CIIRO8Dlg message handlers BOOL CIIRO8Dlg::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 //This is still an absolute port address value writen to the driver to test for card and error return 0xAA55 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 CIIRO8Dlg::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 CIIRO8Dlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CIIRO8Dlg::OnExitButton() { exit(0); } void CIIRO8Dlg::FindCards(void) { // Vars for QueryCardInfo() : unsigned long DeviceID, Base; unsigned long NameSize = 256; unsigned char Name[256]; CString strname; bool found; found = false; RunFlag = true; // Set CardData to 0 as needed: CardData.IsValid = false; CardData.IsSelected = false; CardData.DeviceID = 0; CardData.Base = 0; // Get the total number of cards installed: NumCards = GetNumCards(); if (NumCards == 0) // no cards present { m_CardName = "No Card Found"; m_StatusEdit = "No cards were found!"; m_StatusEdit += "This may mean the card is not installed. "; m_StatusEdit += "Check Device Manager for a card and its status"; m_StatusEdit += "You may consider rebooting your system."; RunFlag = false; } else { // This gets all the card info were only going to use DeviceID: Status = QueryCardInfo(CardNum, &DeviceID, &Base, &NameSize, Name); CardData.DeviceID = DeviceID; CardData.Base = Base; switch (DeviceID) { case 0x0F00: m_CardName = "PCI-IIRO-8 Digital Input/Relay Output Card"; found = true; break; case 0x0F08: m_CardName = "PCI-IIRO-16 Digital Input/Relay Output Card"; found = true; break; case 0x0DC8: m_CardName = "PCI-IDIO-16 Solid-State Input/Output Card"; found = true; break; case 0x0F02: m_CardName = "PCIe-IIRO-8 Digital Input/Relay Output Card"; found = true; break; case 0x0F09: m_CardName = "PCIe-IIRO-16 Digital Input/Relay Output Card"; found = true; break; } } //} if (!found) { m_CardName = "No Card Found In Registry"; InsCR(m_StatusEdit); m_StatusEdit = "No Card Found."; InsCR(m_StatusEdit); InsCR(m_StatusEdit); m_IsaStatic.ModifyStyle(0, WS_VISIBLE, 0); m_IsaEditCtrl.ModifyStyle(0, WS_VISIBLE, 0); m_IsaEditCtrl.SetFocus(); m_StatusControl.LineScroll(999); RunFlag = false; } m_StatusEdit += "This sample program will sequentially turn on all bits of the relay input and sequentially turn them off. Each time it sets a new bit, both the relay output and the relay input are read and the data is displayed. This demonstrates how to read and write to the relays, and to use the readback function of the board."; UpdateData(false); } void CIIRO8Dlg::OnBeginButton() { static bool TimerEnabled = false; if (TimerEnabled) { TimerEnabled = false; m_TimerButton.SetWindowText("Perform I/O"); KillTimer(0); } else { TimerEnabled = true; m_TimerButton.SetWindowText("Stop I/O"); SetTimer(0, 1000, NULL); } } void CIIRO8Dlg::OnTimer(UINT nIDEvent) { static int value[3] = {0,0,0}, i = 0; int j; char msg[9] = "00000000"; unsigned long Offset = 0; // For this card there is no base address offset value[0] = 1 << i++; RelOutPortB(CardNum, Offset, value[0]); //You may wait to let the relays switch before we read and display values //Useful when testing with a loopback test fixture Sleep(10); value[1] = RelInPortB(CardNum, Offset); value[2] = RelInPortB(CardNum, Offset+1); i %= 8; for (j=0; j<8; j++) msg[7-j] = (((value[0] & (1 << j))>0) + 0x30); m_RelayOutput = msg; for (j=0; j<8; j++) msg[7-j] = (((value[1] & (1 << j))>0) + 0x30); m_RelayReadback = msg; for (j=0; j<8; j++) msg[7-j] = (((value[2] & (1 << j))>0) + 0x30); m_OptoInput = msg; UpdateData(false); CDialog::OnTimer(nIDEvent); } void CIIRO8Dlg::OnShowWindow(BOOL bShow, UINT nStatus) { CDialog::OnShowWindow(bShow, nStatus); InsCR(m_StatusEdit); FindCards(); }