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

📄 do.c

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

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

#define  STR_INFO "Current relay output: "

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

  int   iOffset;
  word  wOutData;

  wVendorId = VENDOR_ID;
  wDeviceId = DEVICE_ID;

  clrscr();

  //Description
  printf("Arbor Technology Corp.\n");
  printf("\npDAQ-720/722/722E Digital Out DOS demo program.");
  printf("\nBefore running this program you should:");
  printf("\nConnect desired signal to CN1");
  printf("\n        RELAY1 :  NO0 (pin  1), COM0 (pin  2) and NC0 (pin  3)");
  printf("\n        RELAY2 :  NO1 (pin  4), COM1 (pin  5) and NC1 (pin  6)");
  printf("\n        RELAY3 :  NO2 (pin  7), COM2 (pin  8) and NC2 (pin  9)");
  printf("\n        RELAY4 :  NO3 (pin 20), COM3 (pin 21) and NC3 (pin 22)");
  printf("\n        RELAY5 :  NO4 (pin 23), COM4 (pin 24)");
  printf("\n        RELAY6 :  NO5 (pin 25), COM5 (pin 26)");
  printf("\n        RELAY7 :  NO6 (pin 27), COM6 (pin 28)");
  printf("\n        RELAY8 :  NO7 (pin 10), COM7 (pin 11)");

  printf("\n\nNCx, x=0-3:  Normal close pin of relay x.");
  printf("\nNOx, x=0-7:  Normal open pin of relay x.");
  printf("\nCOMx, x=0-7: Common pin of relay x.");
  printf("\n\n");

  /***************************
   * 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;

  /************
   * Output data to DO port
   ************/
  //
  // Select pDAQ-722 card number 0-3
  //
  do
  {
    printf("\nChoose the Output digital data to port [0-3]:");
    scanf("%d",&iOffset);
  }while(iOffset > 3 || iOffset < 0);
  iOffset += iOffset;

  printf("Press ESC key to quit this program.\n");

  //
  // Output data to relay cyclicly
  //
  printf("\n%s", STR_INFO);
  wIndex = 0;
  do{
    wOutData = inportb(dwBaseAddr+iOffset)+1;
    outportb(dwBaseAddr+iOffset, wOutData);

    //The relay action needs 10ms.
    //DOS system support 100ms delay min.
    delay(10);

    wOutData = inportb(dwBaseAddr+iOffset);
    gotoxy(sizeof(STR_INFO), wherey());
    for(i=0; i < 8; i++)
    {
      if(wOutData & 0x80)
        putch('1');
      else
        putch('0');
      wOutData <<= 1;
    }
    delay(500);

    if(kbhit())
      wIndex = getch();
  }while(wIndex != ESC);

}//Main

⌨️ 快捷键说明

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