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

📄 scan.cpp

📁 VHPD1394 V1.15驅動程序源碼
💻 CPP
字号:
/************************************************************************
 *  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
 *  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
 *  PURPOSE.
 ************************************************************************/

/************************************************************************
 *
 *  Module:       scan.cpp
 *  Long name:    VHPD1394 list available devices example
 *  Description:  This sample demonstrates how to scan for available
 *                VHPD1394 devices.
 *                This sample is based on the VHPDLib C++ class library.
 *
 *  Runtime Env.: implemented as Win32 console application
 *  Used link libraries:
 *                vhpdlib.lib, setupapi.lib, user32.lib
 *  Author(s):    Frank Senf
 *  Company:      Thesycon GmbH, Ilmenau
 ************************************************************************/

// standard includes
#include <stdio.h>
#include <conio.h>

// definitions of used classes
#include "CVhpd.h"


// print prefixes
#define PFX   "SCAN: "
#define PFXERR  "SCAN Error: "


/*******************************************************************/
// support functions
/*******************************************************************/

// swap bytes
void SwapBytes(unsigned long* val)
{
  unsigned char Byte0, Byte1, Byte2, Byte3;

  Byte0 = (unsigned char)(*val & 0xff);
  Byte1 = (unsigned char)((*val & 0xff00) >> 8);
  Byte2 = (unsigned char)((*val & 0xff0000) >> 16);
  Byte3 = (unsigned char)((*val & 0xff000000) >> 24);

  *val =  ((Byte0 << 24) & 0xff000000)
        | ((Byte1 << 16) & 0xff0000)
        | ((Byte2 << 8) & 0xff00)
        | (Byte3 & 0xff);

} // SwapBytes


/*******************************************************************/
// main function
/*******************************************************************/
int __cdecl main(int argc, char *argv[])
{


/*******************************************************************/
// create device list

  // prepare an OS-internal device list used for the open call
  HDEVINFO DevList; DevList = NULL;
  // device list will contain devices that provide the VHPD_IID interface
  // please refer to to the documentation (chapter 7.4) for details on how 
  // to define your private interface (strongly recommended)
  const GUID VhpdDefaultIID = VHPD_IID;
  DevList = CVhpd::CreateDeviceList(&VhpdDefaultIID);
  if ( DevList == NULL ) {
    // ERROR !!!
    fprintf(stderr, PFXERR"CreateDeviceList failed\n");
    return 10;
  }

/*******************************************************************/
// open all available devices, query device identification

  fprintf(stdout, PFX"Scanning for available devices ...\n");

  int i;
  CVhpd Device;
  unsigned long Status;
  VHPD_GET_ADDR_FROM_DO adr;
  VHPD_CONFIG_INFO_PARAMS info;
  VHPD_DRIVER_INFO driver;
  
  for ( i=0; i<63; i++ ) {
    // open a handle to the device
    Status = Device.Open(i,DevList,&VhpdDefaultIID);
    if ( Status == VHPD_STATUS_SUCCESS ) {
      // device opened, query device identification
      // IEEE 1394 node ID of the device
      memset(&adr, 0x0, sizeof(VHPD_GET_ADDR_FROM_DO));
      Status = Device.GetNodeAddress(&adr);
      if ( Status != VHPD_STATUS_SUCCESS ) {
        // ERROR !!!
        fprintf(stderr, PFXERR"Failed to get address for device %d (0x%08X)\n",i,Status);
        // close device handle and exit
        Device.Close();
        break;
      }
      // some contents of Configuration ROM
      memset(&info, 0x0, sizeof(VHPD_CONFIG_INFO_PARAMS));
      Status = Device.GetDeviceInfoParams(&info);
      if ( Status != VHPD_STATUS_SUCCESS ) {
        // ERROR !!!
        fprintf(stderr, PFXERR"Failed to get Config ROM for device %d (0x%08X)\n",i,Status);
        // close device handle and exit
        Device.Close();
        break;
      }
      // all information available, print it on screen
      if ( i == 0 ) {
        // print driver version
        memset(&driver,0x0,sizeof(VHPD_DRIVER_INFO));
        Status = Device.GetDriverInfo(&driver);
        if ( Status != VHPD_STATUS_SUCCESS ) {
          // ERROR !!!
          fprintf(stderr, PFXERR"Failed to get driver information (0x%08X)\n",Status);
          // close device handle and exit
          Device.Close();
          break;
        }
        fprintf(stdout, "\n VHPD1394 Version %d.%02d (Build %d) %s%s\n",
          (unsigned short)((driver.DriverVersion>>8)&0x00FF), (unsigned short)(driver.DriverVersion&0xff),
          driver.DriverBuildNumber,
          (driver.Flags &  VHPD_INFOFLAG_CHECKED_BUILD ) ? "checked build" : "release build",
          (driver.Flags &  VHPD_INFOFLAG_DEMO_VERSION ) ? " (demo version)" : ""
          );
        fprintf(stdout, "  Interface Version %d.%02d\n",
          (unsigned short)((driver.IFVersion>>8)&0x00FF), (unsigned short)(driver.IFVersion&0x000000ff)
          );

        // print header
        fprintf(stdout, "\n Dev   Node ID   Vendor ID   Chip ID\n");
      }
      SwapBytes(&info.ConfigRomHead.NodeID[0]);
      SwapBytes(&info.ConfigRomHead.NodeID[1]);
      fprintf(stdout, " %02d    %02d        0x%06X    0x%02X%08X\n",
        i,(unsigned short)(adr.NodeAddr.NodeNmb),
        (info.ConfigRomHead.NodeID[0]>>8)&0x00FFFFFF,
        info.ConfigRomHead.NodeID[0]&0x000000FF,info.ConfigRomHead.NodeID[1]);

      // done with this device handle, close it
      Device.Close();
    } else {
      // error while opening device i, check if we have reached the and of the list
      if ( Status == VHPD_STATUS_NO_SUCH_DEV_INSTANCE ) {
        // end of list reached
        break;
      } else {
        // ERROR !!!
        fprintf(stderr, PFXERR"Failed to open device %d (0x%08X)\n",i,Status);
        // try to continue with next device
      }
    }
  } // for

  if ( i == 0 ) {
    fprintf(stdout, PFX"No devices available\n");
  }
  fprintf(stdout,"\nPress any key to continue\n");
  getch();


/*******************************************************************/
// destroy device list

  CVhpd::DestroyDeviceList(DevList);
  DevList = NULL;

  return 0;

} // main

/*************************** EOF **************************************/

⌨️ 快捷键说明

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