tchtc2008
驱动牛犊
驱动牛犊
  • 注册日期2004-06-30
  • 最后登录2012-11-22
  • 粉丝0
  • 关注0
  • 积分9分
  • 威望162点
  • 贡献值0点
  • 好评度13点
  • 原创分0分
  • 专家分0分
阅读:2081回复:2

紧急求助:为C#环境提供PCI板卡驱动

楼主#
更多 发布于:2008-06-16 15:15
我手头有PCI板卡,驱动是别人以前写的。程序开发环境采用VC6.0以上版本,系统需要安装DRIVERWORKS 2.7和2000DDK驱动开发工具。我看了好像是是用deviceiocontrol来实现通讯的。测试DEMO程序感觉没有使用DLL方式,好像就是增加了两个头文件然后编译的。现在C#不支持deviceiocontrol。我如何实现C#和我的驱动的连接?项目紧急,如果北京有谁精通,请直接联系我一下。程序任务比较单一:把我的VC的板卡测试DEMO改成一个C#的板卡测试DEMO即可。费用你说了算。我的电话:13261628976 陈先生. 不是北京的朋友,如果会的话,也请务必指点一下哟。在这里先谢谢了!
tchtc2008
驱动牛犊
驱动牛犊
  • 注册日期2004-06-30
  • 最后登录2012-11-22
  • 粉丝0
  • 关注0
  • 积分9分
  • 威望162点
  • 贡献值0点
  • 好评度13点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2008-06-16 15:19
DEMO程序
// Test_newfpga.cpp
//
// Generated by DriverWizard version DriverStudio 2.7.0 (Build 562)
//
// This console application demonstrates how to open a handle
// to a device in your driver, and communicate with the driver
// using Read, Write, and DeviceIoControl calls, as appropriate.
//
// This test program attempts to open the device using the
// GUID defined in "..\NewfpgaDeviceinterface.h"

#include <stdlib.h>
#include <stdio.h>
#include <windows.h>

#include <winioctl.h>
#include "..\newfpgaioctl.h"

#include "..\NewfpgaDeviceinterface.h"    // Has class GUID definition

// This function is found in module OpenByIntf.cpp
HANDLE OpenByInterface(GUID* pClassGuid, DWORD instance, PDWORD pError);
HANDLE IOWaiter;

typedef void VOIDFUNC();

// Prototypes
void Usage(void);
void ShowIoctlValues(void);

//    TODO:
//        You can redefine the IOCTL handler prototypes as needed, adding
//        appropriate parameters that can be collected from the command line.
//        To do this you must modify the command line parsing logic.  An
//        example of this is shown in comments throughout the test application.
//
//=== Parameterized IOCTL Example ===
// void Test_IOCTL_PARAMETERIZED(int nVal, ULONG dwVal);
void Test_NEWFPGA_IOCTL_800(void);
void Test_NEWFPGA_IOCTL_801(void);
ULONG Test_NEWFPGA_IOCTL_802(void);
void Test_NEWFPGA_IOCTL_803(void);
ULONG Test_NEWFPGA_IOCTL_804(ULONG ADD);
ULONG Test_NEWFPGA_IOCTL_805(ULONG ADD);
ULONG Test_NEWFPGA_IOCTL_806(void);
void Test_NEWFPGA_IOCTL_807(void);
void Test_NEWFPGA_IOCTL_808(ULONG ADD,ULONG DATA);
ULONG Test_NEWFPGA_IOCTL_809(ULONG ADD);
ULONG Test_NEWFPGA_IOCTL_80A(void);
void Test_NEWFPGA_IOCTL_80B(void);
void Test_NEWFPGA_IOCTL_80C(ULONG ADD,ULONG DATA);
ULONG Test_NEWFPGA_IOCTL_80D(ULONG ADD);
void Test_NEWFPGA_IOCTL_80E(ULONG mode);
ULONG Test_NEWFPGA_IOCTL_810(ULONG sel);
void Test_NEWFPGA_IOCTL_811(void);
void Test_NEWFPGA_IOCTL_812(void);
void Test_NEWFPGA_IOCTL_813(void);
void Test_NEWFPGA_IOCTL_814(void);
void Test_NEWFPGA_IOCTL_815(void);


void CloseIfOpen(void);
void doRead(int i);
void doWrite(int i);

// Global data


#define N_IOCODES    22

// Names of IOCTL codes
//
char *IOnames[N_IOCODES+1] =
{

//=== Parameterized IOCTL Example ===
//    "IOCTL_PARAMETERIZED",
    "NEWFPGA_IOCTL_800",
    "NEWFPGA_IOCTL_801",
    "NEWFPGA_IOCTL_802",
    "NEWFPGA_IOCTL_803",
    "NEWFPGA_IOCTL_804",
    "NEWFPGA_IOCTL_805",
    "NEWFPGA_IOCTL_806",
    "NEWFPGA_IOCTL_807",
    "NEWFPGA_IOCTL_808",
    "NEWFPGA_IOCTL_809",
    "NEWFPGA_IOCTL_80A",
    "NEWFPGA_IOCTL_80B",
    "NEWFPGA_IOCTL_80C",
    "NEWFPGA_IOCTL_80D",
    "NEWFPGA_IOCTL_80E",
    "NEWFPGA_IOCTL_80F",
    "NEWFPGA_IOCTL_810",
    "NEWFPGA_IOCTL_811",
    "NEWFPGA_IOCTL_812",
    "NEWFPGA_IOCTL_813",
    "NEWFPGA_IOCTL_814",
    "NEWFPGA_IOCTL_815",
    ""
};

// IOCTL codes
//
int IOcodes[N_IOCODES+1] =
{

//=== Parameterized IOCTL Example ===
//    IOCTL_PARAMETERIZED,
    NEWFPGA_IOCTL_800,
    NEWFPGA_IOCTL_801,
    NEWFPGA_IOCTL_802,
    NEWFPGA_IOCTL_803,
    NEWFPGA_IOCTL_804,
    NEWFPGA_IOCTL_805,
    NEWFPGA_IOCTL_806,
    NEWFPGA_IOCTL_807,
    NEWFPGA_IOCTL_808,
    NEWFPGA_IOCTL_809,
    NEWFPGA_IOCTL_80A,
    NEWFPGA_IOCTL_80B,
    NEWFPGA_IOCTL_80C,
    NEWFPGA_IOCTL_80D,
    NEWFPGA_IOCTL_80E,
    NEWFPGA_IOCTL_80F,
    NEWFPGA_IOCTL_810,
    NEWFPGA_IOCTL_811,
    NEWFPGA_IOCTL_812,
    NEWFPGA_IOCTL_813,
    NEWFPGA_IOCTL_814,
    NEWFPGA_IOCTL_815,
    0
};


// Handle to device opened in driver.
//
HANDLE    hDevice = INVALID_HANDLE_VALUE;

// Class GUID used to open device
//
GUID ClassGuid = NewfpgaDevice_CLASS_GUID;


////////////////////////////////////////////////////////////////////////
// Exit
//
//        Print a message and exit
//
   void Exit(int res)
{
    printf("Exiting...\n\n");
    CloseIfOpen();
    exit(res);
}


////////////////////////////////////////////////////////////////////////
// Main entry point
//
//
int __cdecl main(int argc, char *argv[])
{
    int        nArgIncrement = 0;
    int     mode=0;
    long    j=0;
    ULONG    k=0;
    int     i;
    ULONG   select;
    ULONG       nBytesRead;
    static char line[256];


//=== Parameterized IOCTL Example ===
//    int        nVal;
//    ULONG    dwVal;
    DWORD    Error;

    printf("Test application Test_newfpga starting...\n");

    hDevice = OpenByInterface( &ClassGuid, 0, &Error);
    if (hDevice == INVALID_HANDLE_VALUE)
    {
        printf("ERROR opening device: (%0x) returned from CreateFile\n", GetLastError());
        Exit(1);
    }
    else
    {
        printf("Device found, handle open.\n");
    }

    IOWaiter = CreateEvent(NULL, FALSE, FALSE, NULL);
    if (! DeviceIoControl(
    hDevice,
    NEWFPGA_IOCTL_80F,
    &IOWaiter,
    sizeof(IOWaiter),
    NULL,
    0,
    &nBytesRead,
    NULL
    ) )
    {
    printf("wrong event !\n");
    CloseHandle(hDevice);
    CloseHandle(IOWaiter);
    return 0;
    }

/*    unsigned int newbuf[20000];
    FILE *fpParam;
    fpParam = fopen("hello_led_1.elf","rb");
//    fpParam = fopen("1.txt","rb");
    for (long kk=0;kk<5842/2;kk++) {
    newbuf[kk]=0;
    fread(newbuf,2,1,fpParam);
    printf("0x%x ",newbuf[0]);
    }
    fclose(fpParam);*/
    do
    {
    printf("\n");
    printf("\n");
    printf("\n");
       printf("请输入测试功能 :\n");
    printf("0 : led测试 \n");
    printf("1 : 7段数码管测试 \n");
       printf("2 : 按键输入测试 \n");
    printf("3 : 16c450串口测试(115200波特率,发送)\n");
    printf("4 : 16c450串口测试(115200波特率,接收)\n");
    printf("6 : 开关量输入测试\n");
    printf("7 : 开关量输出测试\n");
    printf("8 : sram写测试\n");
    printf("9 : sram读测试\n");
    printf("a : flash id 测试\n");
    printf("b : flash 擦除测试\n");
    printf("c : flash 写测试\n");
    printf("d : flash 读测试\n");
    printf("e : sdram dma测试\n");
    printf("f : nios2 cpu 测试\n");
    printf("99 :  exit\n");

    fgets(line, sizeof(line), stdin);
    sscanf (line, "%x",&mode);
    if (mode==0) {
        printf("testing led ...\n");
        Test_NEWFPGA_IOCTL_800();
                    }
    if (mode==1) {
        printf("testing 7seg led ...\n");
        Test_NEWFPGA_IOCTL_801();
                    }
    if (mode==2) {
        do {
        printf("input is %lx\n",Test_NEWFPGA_IOCTL_802());
        j++;
        }
        while (j<30000);
                    }
    if (mode==3) {
        printf("send 1000 bytes ...\n");
        Test_NEWFPGA_IOCTL_803();
                    }
    j=0;
    if (mode==4) {
        printf("receive 100 bytes ...\n");
        do {
        if ((Test_NEWFPGA_IOCTL_804(0x34) & 0x1)==0x1)
        {
        printf("%c ",Test_NEWFPGA_IOCTL_804(0x20) & 0xff);
        j++;
        }
        }
        while (j<100);
                    }
 /*   if (mode==5) {
        do {
        int channel=0;//0对应ad通道1,1对应ad通道2,...
        printf("%x\n",Test_NEWFPGA_IOCTL_805(channel) & 0xff);
        j++;
        }
        while (j<10000);
                    }*/
    if (mode==6) {
        printf("input is %lx\n",Test_NEWFPGA_IOCTL_806());
        }
    if (mode==7) {
        printf("testing io output ...\n");
        Test_NEWFPGA_IOCTL_807();
                    }
    if (mode==8) {
        printf("testing SRAM writing ...\n");
        //32位方式,sram地址最后两位必须为0
        for (k=0;k<65536;k++) {
        printf("address %lx is write %lx\n",k<<2,k+(k<<16));
        Test_NEWFPGA_IOCTL_808(k<<2,k+(k<<16));
        } }
    if (mode==9) {
        printf("testing SRAM reading ...\n");
        //sram地址最后两位必须为0
        for (k=0;k<65536;k++)
        printf("address %lx is %lx\n",k<<2,Test_NEWFPGA_IOCTL_809(k<<2));
        //    if (Test_NEWFPGA_IOCTL_809(k<<2)!=k) {
    //    printf("wrong is %lx\n",Test_NEWFPGA_IOCTL_809(k<<2));
    //        }
    }
    if (mode==0xa) {
        if (Test_NEWFPGA_IOCTL_80A()==0x22490004) {
        printf("flash (29lv160bb) is found !\n");
        printf("编程前先擦除!!!\n");

        }
        else  if (Test_NEWFPGA_IOCTL_80A()==0x225b0004) {
        printf("flash (29lv800bb) is found !\n");
        printf("编程前先擦除!!!\n");
        }
        else  if (Test_NEWFPGA_IOCTL_80A()==0x225b0001) {
        printf("flash (29lv800db) is found !\n");
        printf("编程前先擦除!!!\n");
        }
        else
        {printf("flash (29lv160bb) not found !\n");
        printf("flash id is %x\n",Test_NEWFPGA_IOCTL_80A());
        }
    }

    if (mode==0xb) {
        printf("testing flash erasing ...\n");
        printf("等待 20 秒 ...\n");
          Test_NEWFPGA_IOCTL_80B();
                    }
    if (mode==0xc) {
        //flash 是16位方式
        printf("testing flash writing ...\n");
        printf("等待编程结束 ...\n");
/*    unsigned int newbuf[200000];
    FILE *fpParam;
    fpParam = fopen("onchip.hex","rb");
    for (long kk=0;kk<9886/2;kk++) {
    newbuf[kk]=0;
    fread(newbuf,2,1,fpParam);
//    printf("0x%x ",newbuf[0]);
    

        printf("address %lx is write %lx\n",kk,newbuf[0]);
        Test_NEWFPGA_IOCTL_80C(kk,(newbuf[0] & 0xffff)); */
    for (long kk=0;kk<524288;kk++) {
    
        printf("address %lx is write %lx\n",kk,(kk & 0xffff));
        Test_NEWFPGA_IOCTL_80C(kk,(kk & 0xffff));
        }
    }
    if (mode==0xd) {
        printf("testing flash reading ...\n");
        for (k=0;k<524288;k++)
        {
        printf("address %lx is %lx\n",k,Test_NEWFPGA_IOCTL_80D(k));
        }
//            if (Test_NEWFPGA_IOCTL_80D(k)!=(k & 0xffff)) {
//        printf("wrong is %lx  k is %lx\n",Test_NEWFPGA_IOCTL_80D(k) & 0xffff,k);
//            }
    }

    if (mode==0xf) {
        printf(" testing nios2 cpu ...\n");
        Test_NEWFPGA_IOCTL_811();
    }
    if (mode==0xe) {

    //添加中断事件消息触发



       printf("input dma test mode :\n");
    printf("0 : read ,1 : write \n");
    fgets(line, sizeof(line), stdin);
    sscanf (line, "%x",&mode);
    Test_NEWFPGA_IOCTL_80E(mode);
    select=0;
    i=0;
    do
    {  
    while(WaitForSingleObject(IOWaiter, 0)==0x0)
    //等待事件消息
    {
    //打印当前DMA传送地址
    printf("current physical transfer address is 0x%08X\n",    Test_NEWFPGA_IOCTL_810(select));
    printf("received interrupt is %d\n",i);
    i++;
    }
    }
    while (i<1500);
    }
    select=1;
    //退出测试
    Test_NEWFPGA_IOCTL_810(select);
    }
    while (mode!=0x99);
 
    CloseIfOpen();

    CloseHandle(IOWaiter);
    CloseHandle(hDevice);
    return 0;
}


////////////////////////////////////////////////////////////////////////
// CloseIfOpen
//
//        Close the device if we previously opened a handle to it.
//
void CloseIfOpen(void)
{
    if (hDevice != INVALID_HANDLE_VALUE)
    {
        // Close the handle to the driver
        if (!CloseHandle(hDevice))
        {
            printf("ERROR: CloseHandle returns %0x.\n", GetLastError());
        }
        hDevice = INVALID_HANDLE_VALUE;
    }
}


////////////////////////////////////////////////////////////////////////
// doRead
//
//        Read 'n' bytes of data from the device
//
// Note: This simple test app reads data from the device and displays the
//            data as characters.  This behavior can be modified as appropriate
//            for your device.
//
void doRead(int n)
{
    char    *buf;
    ULONG    nRead;
    int        i;
    int        j;

    buf = (char *) malloc(n);
    if (buf == NULL)
    {
        printf("Failed to allocate buffer for read");
        Exit(1);
    }

    // Read data from driver
    printf("Reading from device - ");
    ReadFile(hDevice, buf, n, &nRead, NULL);
    printf("%d bytes read from device (%d requested).\n", nRead, n);

    // Print what was read
    i = 0;
    while(i < n)
    {
        j = min((i+26),n);
        for(; i < j; i++)
        {
            printf("%c, ", buf);
        }
        printf("\n");
    }

    free(buf);
}


////////////////////////////////////////////////////////////////////////
// doWrite
//
//        Write 'n' bytes of data to the device
//
// Note: This simple test app writes sequential characters to the
//             device.  This behavior can be modified as appropriate
//            for your device.
//
void doWrite(int n)
{
    char    *buf;
    ULONG    nWritten;
    int        i;
    int        j;

    buf = (char *) malloc(n);
    if (buf == NULL)
    {
        printf("Failed to allocate buffer for write");
        Exit(1);
    }

    // start with the mod26 letter of the number of bytes to write
    j = (n % 26);
    // load buffer with dummy data (abcdefg...)
    for (i=0; i<n; i++, j=(j + 1)%26)
    {
        buf = 'a' + j;
    }

    // Write data to driver
    printf("Writing to device - ");
    WriteFile(hDevice, buf, n, &nWritten, NULL);
    printf("%d bytes written to device (%d attempted).\n", nWritten, n);

    // Print what was written
    i = 0;
    while(i < n)
    {
        j = min((i+26),n);
        for(; i < j; i++)
        {
            printf("%c, ", buf);
        }
        printf("\n");
    }

    free(buf);
}


////////////////////////////////////////////////////////////////////////
// Usage
//
//        Print a usage message describing arguments to this program
//
void Usage(void)
{
    printf("Usage: Test_newfpga [r n] [w n] [i n]\n");
    printf("       r initiates a read of specified number of bytes\n");
    printf("       w initiates a write of specified number of bytes\n");
    printf("       i initiates an IO Control Code message with specified index value\n");
    ShowIoctlValues();
    printf("Example:\n");
    printf("    Test_newfpga r 32 w 32\n");
    printf("        read 32 bytes, then write 32 bytes\n");

    Exit(1);
}



#define    IOCTL_INBUF_SIZE    512
#define    IOCTL_OUTBUF_SIZE    512

//=== Parameterized IOCTL Example ===
//void Test_IOCTL_PARAMETERIZED(int nVal, ULONG dwVal)
//{
//  Function body same as other IOCTL handlers, with command line
//    parameters 'nVal' and 'dwVal' available as input.
//}

////////////////////////////////////////////////////////////////////////
// Test_NEWFPGA_IOCTL_800
//
//        Test one Io Control Code
//
// TODO:
//        Pass appropriate arguments to your device and check
//        the return value
//
void Test_NEWFPGA_IOCTL_800(void)
{
// Note that Input and Output are named from the point of view
// of the DEVICE:
//        bufInput  supplies data to the device
//        bufOutput is written by the device to return data to this application

    CHAR    bufInput[IOCTL_INBUF_SIZE];        // Input to device
    CHAR    bufOutput[IOCTL_OUTBUF_SIZE];    // Output from device
    ULONG    nOutput;                        // Count written to bufOutput

    // Call device IO Control interface (NEWFPGA_IOCTL_800) in driver
    if (!DeviceIoControl(hDevice,
                         NEWFPGA_IOCTL_800,
                         bufInput,
                         IOCTL_INBUF_SIZE,
                         bufOutput,
                         IOCTL_OUTBUF_SIZE,
                         &nOutput,
                         NULL)
       )
    {
        printf("ERROR: DeviceIoControl returns %0x.", GetLastError());
        Exit(1);
    }
}

////////////////////////////////////////////////////////////////////////
// Test_NEWFPGA_IOCTL_801
//
//        Test one Io Control Code
//
// TODO:
//        Pass appropriate arguments to your device and check
//        the return value
//
void Test_NEWFPGA_IOCTL_801(void)
{
// Note that Input and Output are named from the point of view
// of the DEVICE:
//        bufInput  supplies data to the device
//        bufOutput is written by the device to return data to this application

    CHAR    bufInput[IOCTL_INBUF_SIZE];        // Input to device
    CHAR    bufOutput[IOCTL_OUTBUF_SIZE];    // Output from device
    ULONG    nOutput;                        // Count written to bufOutput

    // Call device IO Control interface (NEWFPGA_IOCTL_801) in driver
    if (!DeviceIoControl(hDevice,
                         NEWFPGA_IOCTL_801,
                         bufInput,
                         IOCTL_INBUF_SIZE,
                         bufOutput,
                         IOCTL_OUTBUF_SIZE,
                         &nOutput,
                         NULL)
       )
    {
        printf("ERROR: DeviceIoControl returns %0x.", GetLastError());
        Exit(1);
    }
}

////////////////////////////////////////////////////////////////////////
// Test_NEWFPGA_IOCTL_802
//
//        Test one Io Control Code
//
// TODO:
//        Pass appropriate arguments to your device and check
//        the return value
//
ULONG Test_NEWFPGA_IOCTL_802(void)
{
// Note that Input and Output are named from the point of view
// of the DEVICE:
//        bufInput  supplies data to the device
//        bufOutput is written by the device to return data to this application

    TEST_MESSAGE test;
    CHAR    bufInput[IOCTL_INBUF_SIZE];        // Input to device
    ULONG    nOutput;                        // Count written to bufOutput

    test.Outdata = 0;

    // Call device IO Control interface (NEWPCI_IOCTL_803) in driver
//    printf("Issuing Ioctl to device - ");
    if (!DeviceIoControl(hDevice,
                         NEWFPGA_IOCTL_802,
                         bufInput,
                         IOCTL_INBUF_SIZE,
                         &test,
                         sizeof(test),
                         &nOutput,
                         NULL)
       )
    {
        printf("ERROR: DeviceIoControl returns %0x.", GetLastError());
        Exit(1);
    }
        return test.Outdata;
}

////////////////////////////////////////////////////////////////////////
// Test_NEWFPGA_IOCTL_803
//
//        Test one Io Control Code
//
// TODO:
//        Pass appropriate arguments to your device and check
//        the return value
//
void Test_NEWFPGA_IOCTL_803(void)
{
// Note that Input and Output are named from the point of view
// of the DEVICE:
//        bufInput  supplies data to the device
//        bufOutput is written by the device to return data to this application

    CHAR    bufInput[IOCTL_INBUF_SIZE];        // Input to device
    CHAR    bufOutput[IOCTL_OUTBUF_SIZE];    // Output from device
    ULONG    nOutput;                        // Count written to bufOutput

    // Call device IO Control interface (NEWFPGA_IOCTL_803) in driver
//    printf("Issuing Ioctl to device - ");
    if (!DeviceIoControl(hDevice,
                         NEWFPGA_IOCTL_803,
                         bufInput,
                         IOCTL_INBUF_SIZE,
                         bufOutput,
                         IOCTL_OUTBUF_SIZE,
                         &nOutput,
                         NULL)
       )
    {
        printf("ERROR: DeviceIoControl returns %0x.", GetLastError());
        Exit(1);
    }
}

////////////////////////////////////////////////////////////////////////
// Test_NEWFPGA_IOCTL_804
//
//        Test one Io Control Code
//
// TODO:
//        Pass appropriate arguments to your device and check
//        the return value
//
ULONG Test_NEWFPGA_IOCTL_804(ULONG ADD)
{
// Note that Input and Output are named from the point of view
// of the DEVICE:
//        bufInput  supplies data to the device
//        bufOutput is written by the device to return data to this application
    KS_PASSTHRU pInput;
    ULONG    nOutput;                        // Count written to bufOutput
    pInput.Add=ADD;
    // Call device IO Control interface (NEWFPGA_IOCTL_804) in driver
    if (!DeviceIoControl(hDevice,
                         NEWFPGA_IOCTL_804,
                         &pInput,
                         sizeof(pInput),
                         &pInput,
                         sizeof(pInput),
                         &nOutput,
                         NULL)
       )
    {
        printf("ERROR: DeviceIoControl returns %0x.", GetLastError());
        Exit(1);
    }
    return pInput.Data;
}

////////////////////////////////////////////////////////////////////////
// Test_NEWFPGA_IOCTL_805
//
//        Test one Io Control Code
//
// TODO:
//        Pass appropriate arguments to your device and check
//        the return value
//
ULONG Test_NEWFPGA_IOCTL_805(ULONG ADD)
{
// Note that Input and Output are named from the point of view
// of the DEVICE:
//        bufInput  supplies data to the device
//        bufOutput is written by the device to return data to this application

    KS_PASSTHRU pInput;
    ULONG    nOutput;                        // Count written to bufOutput
    pInput.Add=ADD;
    // Call device IO Control interface (NEWFPGA_IOCTL_804) in driver
    if (!DeviceIoControl(hDevice,
                         NEWFPGA_IOCTL_805,
                         &pInput,
                         sizeof(pInput),
                         &pInput,
                         sizeof(pInput),
                         &nOutput,
                         NULL)
       )
    {
        printf("ERROR: DeviceIoControl returns %0x.", GetLastError());
        Exit(1);
    }
    return pInput.Data;
}

////////////////////////////////////////////////////////////////////////
// Test_NEWFPGA_IOCTL_806
//
//        Test one Io Control Code
//
// TODO:
//        Pass appropriate arguments to your device and check
//        the return value
//
ULONG Test_NEWFPGA_IOCTL_806(void)
{
// Note that Input and Output are named from the point of view
// of the DEVICE:
//        bufInput  supplies data to the device
//        bufOutput is written by the device to return data to this application

    KS_PASSTHRU pInput;
    ULONG    nOutput;                        // Count written to bufOutput
    pInput.Add=0;
    // Call device IO Control interface (NEWFPGA_IOCTL_804) in driver
    if (!DeviceIoControl(hDevice,
                         NEWFPGA_IOCTL_805,
                         &pInput,
                         sizeof(pInput),
                         &pInput,
                         sizeof(pInput),
                         &nOutput,
                         NULL)
       )
    {
        printf("ERROR: DeviceIoControl returns %0x.", GetLastError());
        Exit(1);
    }
    return pInput.Data;

}

////////////////////////////////////////////////////////////////////////
// Test_NEWFPGA_IOCTL_807
//
//        Test one Io Control Code
//
// TODO:
//        Pass appropriate arguments to your device and check
//        the return value
//
void Test_NEWFPGA_IOCTL_807(void)
{
// Note that Input and Output are named from the point of view
// of the DEVICE:
//        bufInput  supplies data to the device
//        bufOutput is written by the device to return data to this application

    CHAR    bufInput[IOCTL_INBUF_SIZE];        // Input to device
    CHAR    bufOutput[IOCTL_OUTBUF_SIZE];    // Output from device
    ULONG    nOutput;                        // Count written to bufOutput

    // Call device IO Control interface (NEWFPGA_IOCTL_807) in driver
//    printf("Issuing Ioctl to device - ");
    if (!DeviceIoControl(hDevice,
                         NEWFPGA_IOCTL_807,
                         bufInput,
                         IOCTL_INBUF_SIZE,
                         bufOutput,
                         IOCTL_OUTBUF_SIZE,
                         &nOutput,
                         NULL)
       )
    {
        printf("ERROR: DeviceIoControl returns %0x.", GetLastError());
        Exit(1);
    }
}

////////////////////////////////////////////////////////////////////////
// Test_NEWFPGA_IOCTL_808
//
//        Test one Io Control Code
//
// TODO:
//        Pass appropriate arguments to your device and check
//        the return value
//
void Test_NEWFPGA_IOCTL_808(ULONG ADD,ULONG DATA)
{
// Note that Input and Output are named from the point of view
// of the DEVICE:
//        bufInput  supplies data to the device
//        bufOutput is written by the device to return data to this application

    KS_PASSTHRU pInput;
    ULONG    nOutput;                        // Count written to bufOutput
    pInput.Add=ADD;
    pInput.Data=DATA;
    // Call device IO Control interface (NEWFPGA_IOCTL_804) in driver
    if (!DeviceIoControl(hDevice,
                         NEWFPGA_IOCTL_808,
                         &pInput,
                         sizeof(pInput),
                         &pInput,
                         sizeof(pInput),
                         &nOutput,
                         NULL)
       )
    {
        printf("ERROR: DeviceIoControl returns %0x.", GetLastError());
        Exit(1);
    }
}

////////////////////////////////////////////////////////////////////////
// Test_NEWFPGA_IOCTL_809
//
//        Test one Io Control Code
//
// TODO:
//        Pass appropriate arguments to your device and check
//        the return value
//
ULONG Test_NEWFPGA_IOCTL_809(ULONG ADD)
{
// Note that Input and Output are named from the point of view
// of the DEVICE:
//        bufInput  supplies data to the device
//        bufOutput is written by the device to return data to this application

    KS_PASSTHRU pInput;
    ULONG    nOutput;                        // Count written to bufOutput
    pInput.Add=ADD;
    // Call device IO Control interface (NEWFPGA_IOCTL_804) in driver
    if (!DeviceIoControl(hDevice,
                         NEWFPGA_IOCTL_809,
                         &pInput,
                         sizeof(pInput),
                         &pInput,
                         sizeof(pInput),
                         &nOutput,
                         NULL)
       )
    {
        printf("ERROR: DeviceIoControl returns %0x.", GetLastError());
        Exit(1);
    }
    return pInput.Data;
}

////////////////////////////////////////////////////////////////////////
// Test_NEWFPGA_IOCTL_80A
//
//        Test one Io Control Code
//
// TODO:
//        Pass appropriate arguments to your device and check
//        the return value
//
ULONG Test_NEWFPGA_IOCTL_80A(void)
{
// Note that Input and Output are named from the point of view
// of the DEVICE:
//        bufInput  supplies data to the device
//        bufOutput is written by the device to return data to this application

    KS_PASSTHRU pInput;
    ULONG    nOutput;                        // Count written to bufOutput
    pInput.Add=0;
    // Call device IO Control interface (NEWFPGA_IOCTL_804) in driver
    if (!DeviceIoControl(hDevice,
                         NEWFPGA_IOCTL_80A,
                         &pInput,
                         sizeof(pInput),
                         &pInput,
                         sizeof(pInput),
                         &nOutput,
                         NULL)
       )
    {
        printf("ERROR: DeviceIoControl returns %0x.", GetLastError());
        Exit(1);
    }
    return pInput.Data;
}

////////////////////////////////////////////////////////////////////////
// Test_NEWFPGA_IOCTL_80B
//
//        Test one Io Control Code
//
// TODO:
//        Pass appropriate arguments to your device and check
//        the return value
//
void Test_NEWFPGA_IOCTL_80B(void)
{
// Note that Input and Output are named from the point of view
// of the DEVICE:
//        bufInput  supplies data to the device
//        bufOutput is written by the device to return data to this application

    CHAR    bufInput[IOCTL_INBUF_SIZE];        // Input to device
    CHAR    bufOutput[IOCTL_OUTBUF_SIZE];    // Output from device
    ULONG    nOutput;                        // Count written to bufOutput

    // Call device IO Control interface (NEWFPGA_IOCTL_80B) in driver
    if (!DeviceIoControl(hDevice,
                         NEWFPGA_IOCTL_80B,
                         bufInput,
                         IOCTL_INBUF_SIZE,
                         bufOutput,
                         IOCTL_OUTBUF_SIZE,
                         &nOutput,
                         NULL)
       )
    {
        printf("ERROR: DeviceIoControl returns %0x.", GetLastError());
        Exit(1);
    }
}

////////////////////////////////////////////////////////////////////////
// Test_NEWFPGA_IOCTL_80C
//
//        Test one Io Control Code
//
// TODO:
//        Pass appropriate arguments to your device and check
//        the return value
//
void Test_NEWFPGA_IOCTL_80C(ULONG ADD,ULONG DATA)
{
// Note that Input and Output are named from the point of view
// of the DEVICE:
//        bufInput  supplies data to the device
//        bufOutput is written by the device to return data to this application
    KS_PASSTHRU pInput;
    ULONG    nOutput;                        // Count written to bufOutput
    pInput.Add=ADD;
    pInput.Data=DATA;
    // Call device IO Control interface (NEWFPGA_IOCTL_804) in driver
    if (!DeviceIoControl(hDevice,
                         NEWFPGA_IOCTL_80C,
                         &pInput,
                         sizeof(pInput),
                         &pInput,
                         sizeof(pInput),
                         &nOutput,
                         NULL)
       )
    {
        printf("ERROR: DeviceIoControl returns %0x.", GetLastError());
        Exit(1);
    }
}

////////////////////////////////////////////////////////////////////////
// Test_NEWFPGA_IOCTL_80D
//
//        Test one Io Control Code
//
// TODO:
//        Pass appropriate arguments to your device and check
//        the return value
//
ULONG Test_NEWFPGA_IOCTL_80D(ULONG ADD)
{
// Note that Input and Output are named from the point of view
// of the DEVICE:
//        bufInput  supplies data to the device
//        bufOutput is written by the device to return data to this application

    KS_PASSTHRU pInput;
    ULONG    nOutput;                        // Count written to bufOutput
    pInput.Add=ADD;
    // Call device IO Control interface (NEWFPGA_IOCTL_804) in driver
    if (!DeviceIoControl(hDevice,
                         NEWFPGA_IOCTL_80D,
                         &pInput,
                         sizeof(pInput),
                         &pInput,
                         sizeof(pInput),
                         &nOutput,
                         NULL)
       )
    {
        printf("ERROR: DeviceIoControl returns %0x.", GetLastError());
        Exit(1);
    }
    return pInput.Data;
}

////////////////////////////////////////////////////////////////////////
// Test_NEWFPGA_IOCTL_80E
//
//        Test one Io Control Code
//
// TODO:
//        Pass appropriate arguments to your device and check
//        the return value
//
void Test_NEWFPGA_IOCTL_80E(ULONG mode)
{
// Note that Input and Output are named from the point of view
// of the DEVICE:
//        bufInput  supplies data to the device
//        bufOutput is written by the device to return data to this application

    KS_PASSTHRU pthru;
    KS_PASSTHRU pthru1;

    pthru.Data = mode;
    pthru.Add = 0x9999;
    pthru1.Data = 0x0;
    pthru1.Add = 0x0;
    ULONG    nOutput;                        // Count written to bufOutput

    // Call device IO Control interface (NEWPCI_IOCTL_807) in driver
//    printf("Issuing Ioctl to device - ");
    if (!DeviceIoControl(hDevice,
                         NEWFPGA_IOCTL_80E,
                         &pthru,
                         sizeof(pthru),
                         &pthru1,
                         sizeof(pthru1),
                         &nOutput,
                         NULL)
       )
    {
        printf("ERROR: DeviceIoControl returns %0x.", GetLastError());
        Exit(1);
    }
}


////////////////////////////////////////////////////////////////////////
// Test_NEWFPGA_IOCTL_810
//
//        Test one Io Control Code
//
// TODO:
//        Pass appropriate arguments to your device and check
//        the return value
//
ULONG Test_NEWFPGA_IOCTL_810(ULONG sel)
{
// Note that Input and Output are named from the point of view
// of the DEVICE:
//        bufInput  supplies data to the device
//        bufOutput is written by the device to return data to this application

    KS_MAILBOX_MESSAGE message;

    message.MessageMailBox = 0;
    message.MessageValue = sel;
    ULONG    nOutput;                        // Count written to bufOutput

    if (!DeviceIoControl(hDevice,
                         NEWFPGA_IOCTL_810,
                         &message,
                         sizeof(message),
                         &message,
                         sizeof(message),
                         &nOutput,
                         NULL)
       )
    {
        printf("ERROR: DeviceIoControl returns %0x.", GetLastError());
        Exit(1);
    }
    return message.MessageValue;
}

////////////////////////////////////////////////////////////////////////
// Test_NEWFPGA_IOCTL_811
//
//        Test one Io Control Code
//
// TODO:
//        Pass appropriate arguments to your device and check
//        the return value
//
void Test_NEWFPGA_IOCTL_811(void)
{
// Note that Input and Output are named from the point of view
// of the DEVICE:
//        bufInput  supplies data to the device
//        bufOutput is written by the device to return data to this application

    CHAR    bufInput[IOCTL_INBUF_SIZE];        // Input to device
    CHAR    bufOutput[IOCTL_OUTBUF_SIZE];    // Output from device
    ULONG    nOutput;                        // Count written to bufOutput

    // Call device IO Control interface (NEWFPGA_IOCTL_80B) in driver
//    printf("Issuing Ioctl to device - ");
    if (!DeviceIoControl(hDevice,
                         NEWFPGA_IOCTL_811,
                         bufInput,
                         IOCTL_INBUF_SIZE,
                         bufOutput,
                         IOCTL_OUTBUF_SIZE,
                         &nOutput,
                         NULL)
       )
    {
        printf("ERROR: DeviceIoControl returns %0x.", GetLastError());
        Exit(1);
    }
}

////////////////////////////////////////////////////////////////////////
// Test_NEWFPGA_IOCTL_812
//
//        Test one Io Control Code
//
// TODO:
//        Pass appropriate arguments to your device and check
//        the return value
//
void Test_NEWFPGA_IOCTL_812(void)
{
// Note that Input and Output are named from the point of view
// of the DEVICE:
//        bufInput  supplies data to the device
//        bufOutput is written by the device to return data to this application

    CHAR    bufInput[IOCTL_INBUF_SIZE];        // Input to device
    CHAR    bufOutput[IOCTL_OUTBUF_SIZE];    // Output from device
    ULONG    nOutput;                        // Count written to bufOutput

    // Call device IO Control interface (NEWFPGA_IOCTL_80C) in driver
//    printf("Issuing Ioctl to device - ");
    if (!DeviceIoControl(hDevice,
                         NEWFPGA_IOCTL_812,
                         bufInput,
                         IOCTL_INBUF_SIZE,
                         bufOutput,
                         IOCTL_OUTBUF_SIZE,
                         &nOutput,
                         NULL)
       )
    {
        printf("ERROR: DeviceIoControl returns %0x.", GetLastError());
        Exit(1);
    }
}

////////////////////////////////////////////////////////////////////////
// Test_NEWFPGA_IOCTL_813
//
//        Test one Io Control Code
//
// TODO:
//        Pass appropriate arguments to your device and check
//        the return value
//
void Test_NEWFPGA_IOCTL_813(void)
{
// Note that Input and Output are named from the point of view
// of the DEVICE:
//        bufInput  supplies data to the device
//        bufOutput is written by the device to return data to this application

    CHAR    bufInput[IOCTL_INBUF_SIZE];        // Input to device
    CHAR    bufOutput[IOCTL_OUTBUF_SIZE];    // Output from device
    ULONG    nOutput;                        // Count written to bufOutput

    // Call device IO Control interface (NEWFPGA_IOCTL_80D) in driver
    printf("Issuing Ioctl to device - ");
    if (!DeviceIoControl(hDevice,
                         NEWFPGA_IOCTL_813,
                         bufInput,
                         IOCTL_INBUF_SIZE,
                         bufOutput,
                         IOCTL_OUTBUF_SIZE,
                         &nOutput,
                         NULL)
       )
    {
        printf("ERROR: DeviceIoControl returns %0x.", GetLastError());
        Exit(1);
    }
}

////////////////////////////////////////////////////////////////////////
// Test_NEWFPGA_IOCTL_814
//
//        Test one Io Control Code
//
// TODO:
//        Pass appropriate arguments to your device and check
//        the return value
//
void Test_NEWFPGA_IOCTL_814(void)
{
// Note that Input and Output are named from the point of view
// of the DEVICE:
//        bufInput  supplies data to the device
//        bufOutput is written by the device to return data to this application

    CHAR    bufInput[IOCTL_INBUF_SIZE];        // Input to device
    CHAR    bufOutput[IOCTL_OUTBUF_SIZE];    // Output from device
    ULONG    nOutput;                        // Count written to bufOutput

    // Call device IO Control interface (NEWFPGA_IOCTL_80E) in driver
    printf("Issuing Ioctl to device - ");
    if (!DeviceIoControl(hDevice,
                         NEWFPGA_IOCTL_814,
                         bufInput,
                         IOCTL_INBUF_SIZE,
                         bufOutput,
                         IOCTL_OUTBUF_SIZE,
                         &nOutput,
                         NULL)
       )
    {
        printf("ERROR: DeviceIoControl returns %0x.", GetLastError());
        Exit(1);
    }
}

////////////////////////////////////////////////////////////////////////
// Test_NEWFPGA_IOCTL_815
//
//        Test one Io Control Code
//
// TODO:
//        Pass appropriate arguments to your device and check
//        the return value
//
void Test_NEWFPGA_IOCTL_815(void)
{
// Note that Input and Output are named from the point of view
// of the DEVICE:
//        bufInput  supplies data to the device
//        bufOutput is written by the device to return data to this application

    CHAR    bufInput[IOCTL_INBUF_SIZE];        // Input to device
    CHAR    bufOutput[IOCTL_OUTBUF_SIZE];    // Output from device
    ULONG    nOutput;                        // Count written to bufOutput

    // Call device IO Control interface (NEWFPGA_IOCTL_80F) in driver
    printf("Issuing Ioctl to device - ");
    if (!DeviceIoControl(hDevice,
                         NEWFPGA_IOCTL_815,
                         bufInput,
                         IOCTL_INBUF_SIZE,
                         bufOutput,
                         IOCTL_OUTBUF_SIZE,
                         &nOutput,
                         NULL)
       )
    {
        printf("ERROR: DeviceIoControl returns %0x.", GetLastError());
        Exit(1);
    }
}

////////////////////////////////////////////////////////////////////////
// Test_NEWFPGA_IOCTL_816
//
//        Test one Io Control Code
//
// TODO:
//        Pass appropriate arguments to your device and check
//        the return value
//
void Test_NEWFPGA_IOCTL_816(void)
{
// Note that Input and Output are named from the point of view
// of the DEVICE:
//        bufInput  supplies data to the device
//        bufOutput is written by the device to return data to this application

    CHAR    bufInput[IOCTL_INBUF_SIZE];        // Input to device
    CHAR    bufOutput[IOCTL_OUTBUF_SIZE];    // Output from device
    ULONG    nOutput;                        // Count written to bufOutput

    // Call device IO Control interface (NEWFPGA_IOCTL_80F) in driver
    printf("Issuing Ioctl to device - ");
    if (!DeviceIoControl(hDevice,
                         NEWFPGA_IOCTL_816,
                         bufInput,
                         IOCTL_INBUF_SIZE,
                         bufOutput,
                         IOCTL_OUTBUF_SIZE,
                         &nOutput,
                         NULL)
       )
    {
        printf("ERROR: DeviceIoControl returns %0x.", GetLastError());
        Exit(1);
    }
}

////////////////////////////////////////////////////////////////////////
// ShowIoctlValues
//
//        Print list of IO Control Code values for usage display
//
void ShowIoctlValues(void)
{
    int i;

    for (i=0; i<N_IOCODES; i++)
    {
        if (i==0)
            printf( "         IO control code index\n");
        printf( "           %d is code %s [%x]\n", i, IOnames, IOcodes);

//=== Parameterized IOCTL Example ===
//        if (IOcodes == IOCTL_PARAMETERIZED)
//        {
//            printf( "               and has two arguments: <arg1 desc.> <arg1 desc.>\n");
//            printf( "               Example: i %d <IOCTL index> <ex. arg1> <ex. arg2>\n", i);
//        }
    }
}
akcw007
驱动牛犊
驱动牛犊
  • 注册日期2005-09-02
  • 最后登录2009-02-13
  • 粉丝0
  • 关注0
  • 积分59分
  • 威望15点
  • 贡献值0点
  • 好评度5点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2008-10-17 08:58
[DllImport("XXXXX.dll")]
extern static  xxxx    function(para 1,para2,.........);

C#下可以用API的,就是上面这个形式.
WINDOWS API 都是在几个动态连接库里的,kernel32.dll user32,dll,gid32.dll........等等.
C#调用API,就如上面的形式.
游客

返回顶部