发表于:2006-02-11 17:00:00
4楼
CPCI硬件介绍的文章很多,只要搜索compactPCI就能找到,但热插拔编程的资料不多。下面这个例子可以实现CPCI的热插拔功能。
/ HsInfo.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "conio.h"
#include "stdio.h"
#include "..\..\include\ahsm.h"
#define ESC 0x1b
void GetErrorStatus(ULONG retValue)
{
switch(retValue)
{
case InvalidDeviceHandle: printf("Invalid device handle! \n");
break;
case KeInvalidHandleValue: printf("Invalid handle value to kernel driver! \n");
break;
case KeFileNotFound: printf("No such device! \n");
break;
case KeInvalidParameter: printf("Invalid parameter to kernel driver! \n");
break;
case InvalidInputParam: printf("Invalid parameter to dll driver! \n");
break;
default:
printf("System error code = %x\n", retValue);
}
}
int main(int argc, char* argv[])
{
HANDLE hsHandle;
USHORT usHsStatus, usSlotNumber = 0;
ULONG retValue;
BOOLEAN bEnum, bLED=0;
char key;
retValue = HSM_DeviceOpen(&hsHandle);
if(retValue)
{
GetErrorStatus(retValue);
return 0;
}
printf("Input slot number:");
scanf("%d",&usSlotNumber);
printf("\n");
printf(" Advantech Hot Swap Testing \n");
printf("------------------------------------------------\n");
printf(" Press key:\n");
printf(" \t<1> Set LED on.\n");
printf(" \t<2> Set LED off.\n");
printf(" \t<3> Request device extraction.\n");
printf(" \t<ESC> Exit. \n");
printf("\n");
while(key != ESC)
{
retValue = 0;
key = 0;
if(kbhit()) key = getch();
switch(key)
{
case '1': retValue = HSM_SetLED(hsHandle, // IN, handle from HSM_DeviceOpen
usSlotNumber, // IN, slot number
TRUE); // IN, set LED ON
break;
case '2': retValue = HSM_SetLED(hsHandle, usSlotNumber, FALSE);
break;
case '3': retValue = HSM_RequestExtraction( hsHandle, // IN, handle from HSM_DeviceOpen
usSlotNumber);// IN, slot number
break;
}
// If error, show message
if(retValue)
GetErrorStatus(retValue);
// Get hot swap status of the slot
retValue = HSM_GetHsStatus(hsHandle, // IN, handle from HSM_DeviceOpen
usSlotNumber, // IN, slot number
&usHsStatus // OUT, hot swap status
);
if(retValue)
GetErrorStatus(retValue);
// Get enum status
retValue = HSM_GetEnumStatus(hsHandle, // IN, handle from HSM_DeviceOpen
&bEnum); // OUT, enum status
if(retValue)
GetErrorStatus(retValue);
// Get LED status
retValue = HSM_GetLED(hsHandle, // IN, handle from HSM_DeviceOpen
usSlotNumber, // IN, slot number
&bLED);
printf(" Hot Swap Status= %x Enum = %d LED = %d \r",
usHsStatus, bEnum, bLED);
Sleep(100);
}
HSM_DeviceClose(hsHandle);
return 0;
}