⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 di.c

📁 在dos下读写pci卡
💻 C
字号:
/*
   '**********************************************************************
   '*  Program  : DI.C                                                   *
   '*  Revision : 1.00                                                   *
   '*  Date     : 6/17/2002                Arbor Technology  Co., Ltd.  *
   '*====================================================================*
   '*                                                                    *
   '*  This demo program performs Digital Input of pDAQ-720/722/722E     *
   '*                                                                    *
   '**********************************************************************
*/

#include <dos.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include "PCI.C"
#include "pDAQ722.h"

void main(void)
{
   word  wVendorId, wDeviceId, wIndex;
   int   iErrCode;
   byte  ucBusNumber, ucDevAndFunc;
   dword dwData, dwBaseAddr;

   int   i;
   int   iPort;

   wVendorId = VENDOR_ID;
   wDeviceId = DEVICE_ID;

   //Description
   clrscr();
   printf("Arbor Technolog Corp.\n");
   printf("\npDAQ-720/722/722E Digital Input DOS demo program.");
   printf("\nFirst, connect desired signal to CN1");
   printf("\n      DI0:  DI_A0 (pin 30) and DI_B0 (pin 12)");
   printf("\n      DI1:  DI_A1 (pin 31) and DI_B1 (pin 13)");
   printf("\n      DI2:  DI_A2 (pin 32) and DI_B2 (pin 14)");
   printf("\n      DI3:  DI_A3 (pin 33) and DI_B3 (pin 15)");
   printf("\n      DI4:  DI_A4 (pin 34) and DI_B4 (pin 16)");
   printf("\n      DI5:  DI_A5 (pin 35) and DI_B5 (pin 17)");
   printf("\n      DI6:  DI_A6 (pin 36) and DI_B6 (pin 18)");
   printf("\n      DI7:  DI_A7 (pin 37) and DI_B7 (pin 19)\n");

   printf("\n      DIn means digital input channel n.\n\n");

   printf("Press any key to continue...");
   getch();
   clrscr();

  /***************************
   * Get pDAQ-72x's resource
   ***************************/
  //
  // Search pDAQ-72x
  //
  for( wIndex=0; wIndex < 32; wIndex++)
  {
    iErrCode = find_pci_device(
                  wDeviceId,
                  wVendorId,
                  wIndex,
                  &ucBusNumber,
                  &ucDevAndFunc );
    if (iErrCode == NOT_SUCCESSFUL )
    {
       printf("\n pDAQ-720/722 search fail.\n");
       exit(1);
    }
    iErrCode = read_configuration_dword(
                  ucBusNumber,
                  ucDevAndFunc,
                  PCI_CS_SUBSYSTEM_ID,
                  &dwData);
    if(dwData == SUBSYSTEM_ID)
      break;
  }

  //
  //Get base address, from PCI base address range 2
  //
  iErrCode = read_configuration_dword(
                ucBusNumber,
                ucDevAndFunc,
                PCI_CS_BASE_ADDRESS_2,
                &dwData);
  if (iErrCode == NOT_SUCCESSFUL)
  {
    printf("\npDAQ-72x gets base address failure.\n");
    exit(1);
  }
  else
    dwBaseAddr = dwData & 0xfffffffc;

   /************
    * Read DI data from port
    ************/
   //Select pDAQ-72x card number 0-3
   do
   {
     printf("Choose the Input digital data from port[0-3]:");
     scanf("%d",&iPort);
   }while(iPort > 3 || iPort < 0);

   //Read Relay Status
   printf("\nCheck current Relay status.");
   outportb(dwBaseAddr+(iPort+4), 0);
   for (i=0; i < 2 ; i++)
   {
     printf("\nPress any key to test Relay output and readback...");
     getch();
     outportb(dwBaseAddr+(iPort*2), 0x55 << i);
     delay(100);
     printf("\nRelay Port %d data = %xh", iPort, inportb(dwBaseAddr+(iPort*2)));
   }

   printf("\n\nPress any key to start DI reading...");
   getch();

   //Read data from digital isolation in
   printf("\nPress any key to stop DI funciton....\n");
   while(!kbhit())
   {
      gotoxy(1, wherey());
      printf("Digital in Port %d data = %xh", iPort, inportb(dwBaseAddr+(iPort*2+1)));
      delay(300);
   }
   getch();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -