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

📄 usbfxtest.cpp

📁 基于vc++6.0环境的cypress USB 驱动源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
///////////////////////////////////////////////////////////////////////////////
//
//    (C) Copyright 1995 - 2003 OSR Open Systems Resources, Inc.
//    All Rights Reserved
//
//    This sofware is supplied for instructional purposes only.
//
//    OSR Open Systems Resources, Inc. (OSR) expressly disclaims any warranty
//    for this software.  THIS SOFTWARE IS PROVIDED  "AS IS" WITHOUT WARRANTY
//    OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
//    THE IMPLIED WARRANTIES OF MECHANTABILITY OR FITNESS FOR A PARTICULAR
//    PURPOSE.  THE ENTIRE RISK ARISING FROM THE USE OF THIS SOFTWARE REMAINS
//    WITH YOU.  OSR's entire liability and your exclusive remedy shall not
//    exceed the price paid for this material.  In no event shall OSR or its
//    suppliers be liable for any damages whatsoever (including, without
//    limitation, damages for loss of business profit, business interruption,
//    loss of business information, or any other pecuniary loss) arising out
//    of the use or inability to use this software, even if OSR has been
//    advised of the possibility of such damages.  Because some states/
//    jurisdictions do not allow the exclusion or limitation of liability for
//    consequential or incidental damages, the above limitation may not apply
//    to you.
//
//    OSR Open Systems Resources, Inc.
//    105 Route 101A Suite 19
//    Amherst, NH 03031  (603) 595-6500 FAX: (603) 595-6503
//    email bugs to: bugs@osr.com
//
//
//    MODULE:
//
//      USBFXTEST.cpp
//
//    ABSTRACT:
//
//      Test application for OSR's USBFX2 sample driver
//
//
//    AUTHOR(S):
//
//      OSR Open Systems Resources, Inc.
// 
///////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <windows.h>
#include <winioctl.h>
#include <initguid.h>
#include <usbfx2lk_ioctl.h>
#include <setupapi.h>
#include <stdlib.h>


//////////////////////////
// Forward Declarations //
//////////////////////////
BOOLEAN 
FindUSBFX2LKDevice(
    PHANDLE Handle
    );

__cdecl main(ULONG argc, LPSTR *argv)
{
    HANDLE          deviceHandle;
    DWORD           code;
    ULONG           bytesRet;
    DWORD           function;

    BAR_GRAPH_STATE barGraphState;
    SWITCH_STATE    switchState;
    UCHAR           sevenSegment;


    //
    // Let's see if we can find an OSR USB FX2 device
    //  in the system...
    //
    if (!FindUSBFX2LKDevice(&deviceHandle)) {

        //
        // Nope. Not much we can do, let's just get
        //  outta here...
        //
        printf("Unable to find any OSR FX2 devices!\n");

        return 1;

    }

    //
    // Infinitely print out the list of choices, ask for input, process
    // the request
    //
    while(TRUE)  {

        printf ("\nUSBFX TEST -- Functions:\n\n");
        printf ("\t1.  Light Bars\n");
        printf ("\t2.  Light entire Bar graph\n");
        printf ("\t3.  Clear entire Bar graph\n");
        printf ("\t4.  Get bar graph state\n");
        printf ("\t5.  Get Switch state\n");
        printf ("\t6.  Get Switch Interrupt Message\n");
        printf ("\t7.  Get 7 segment state\n");
        printf ("\t8.  Set 7 segment states\n");
        printf ("\n\t0. Exit\n");
        printf ("\n\tSelection: ");

        if (scanf ("%d", &function) <= 0) {

            printf("Error reading input!\n");
            return 1;

        }

        switch(function)  {

        case 1:

            for (UCHAR i = 0; i < 8; i++) {

                barGraphState.BarsAsUChar = 1 << i;

                if (!DeviceIoControl(deviceHandle,
                                     IOCTL_OSRUSBFX2_SET_BAR_GRAPH_DISPLAY  ,
                                     &barGraphState,             // Ptr to InBuffer
                                     sizeof(BAR_GRAPH_STATE),            // Length of InBuffer
                                     NULL,                 // Ptr to OutBuffer
                                     0,         // Length of OutBuffer
                                     &bytesRet,                     // BytesReturned
                                     0)) {                       // Ptr to Overlapped structure

                    code = GetLastError();

                    printf("DeviceIoControl failed with error 0x%x\n", code);

                    return(code);
                }

                printf("This is %d\n", i+1);
                Sleep(500);


            }
            break;
        case 2:

            barGraphState.BarsAsUChar = 0xFF;

            if (!DeviceIoControl(deviceHandle,
                                 IOCTL_OSRUSBFX2_SET_BAR_GRAPH_DISPLAY,
                                 &barGraphState,                 // Ptr to InBuffer
                                 sizeof(BAR_GRAPH_STATE),         // Length of InBuffer
                                 NULL,             // Ptr to OutBuffer
                                 0,            // Length of OutBuffer
                                 &bytesRet,                     // BytesReturned
                                 0)) {                       // Ptr to Overlapped structure

                code = GetLastError();

                printf("DeviceIoControl failed with error 0x%x\n", code);

                return(code);
            }

            break;

        case 3:

            barGraphState.BarsAsUChar = 0;

            if (!DeviceIoControl(deviceHandle,
                                 IOCTL_OSRUSBFX2_SET_BAR_GRAPH_DISPLAY,
                                 &barGraphState,                 // Ptr to InBuffer
                                 sizeof(BAR_GRAPH_STATE),         // Length of InBuffer
                                 NULL,             // Ptr to OutBuffer
                                 0,            // Length of OutBuffer
                                 &bytesRet,                     // BytesReturned
                                 0)) {                       // Ptr to Overlapped structure

                code = GetLastError();

                printf("DeviceIoControl failed with error 0x%x\n", code);

                return(code);
            }

            break;


        case 4:

            barGraphState.BarsAsUChar = 0;

            if (!DeviceIoControl(deviceHandle,
                                 IOCTL_OSRUSBFX2_GET_BAR_GRAPH_DISPLAY,
                                 NULL,             // Ptr to InBuffer
                                 0,            // Length of InBuffer
                                 &barGraphState,                 // Ptr to OutBuffer
                                 sizeof(BAR_GRAPH_STATE),         // Length of OutBuffer
                                 &bytesRet,                     // BytesReturned
                                 0)) {                       // Ptr to Overlapped structure

                code = GetLastError();

                printf("DeviceIoControl failed with error 0x%x\n", code);

                return(code);
            }

            printf("Bar Graph: \n");
            printf("    Bar8 is %s\n", barGraphState.Bar8 ? "ON" : "OFF");
            printf("    Bar7 is %s\n", barGraphState.Bar7 ? "ON" : "OFF");
            printf("    Bar6 is %s\n", barGraphState.Bar6 ? "ON" : "OFF");
            printf("    Bar5 is %s\n", barGraphState.Bar5 ? "ON" : "OFF");
            printf("    Bar4 is %s\n", barGraphState.Bar4 ? "ON" : "OFF");
            printf("    Bar3 is %s\n", barGraphState.Bar3 ? "ON" : "OFF");
            printf("    Bar2 is %s\n", barGraphState.Bar2 ? "ON" : "OFF");
            printf("    Bar1 is %s\n", barGraphState.Bar1 ? "ON" : "OFF");

            break;

        case 5:

            switchState.SwitchesAsUChar = 0;

            if (!DeviceIoControl(deviceHandle,
                                 IOCTL_OSRUSBFX2_READ_SWITCHES,
                                 NULL,             // Ptr to InBuffer
                                 0,            // Length of InBuffer
                                 &switchState,                 // Ptr to OutBuffer
                                 sizeof(SWITCH_STATE),         // Length of OutBuffer
                                 &bytesRet,                     // BytesReturned
                                 0)) {                       // Ptr to Overlapped structure

                code = GetLastError();

                printf("DeviceIoControl failed with error 0x%x\n", code);

                return(code);
            }

            printf("Switches: \n");
            printf("    Switch8 is %s\n", switchState.Switch8 ? "ON" : "OFF");
            printf("    Switch7 is %s\n", switchState.Switch7 ? "ON" : "OFF");
            printf("    Switch6 is %s\n", switchState.Switch6 ? "ON" : "OFF");
            printf("    Switch5 is %s\n", switchState.Switch5 ? "ON" : "OFF");
            printf("    Switch4 is %s\n", switchState.Switch4 ? "ON" : "OFF");
            printf("    Switch3 is %s\n", switchState.Switch3 ? "ON" : "OFF");
            printf("    Switch2 is %s\n", switchState.Switch2 ? "ON" : "OFF");
            printf("    Switch1 is %s\n", switchState.Switch1 ? "ON" : "OFF");
           
            break;

        case 6:   {
            switchState.SwitchesAsUChar = 0;

            if (!DeviceIoControl(deviceHandle,
                                 IOCTL_OSRUSBFX2_GET_INTERRUPT_MESSAGE,
                                 NULL,             // Ptr to InBuffer
                                 0,            // Length of InBuffer
                                 &switchState,                 // Ptr to OutBuffer
                                 sizeof(switchState),         // Length of OutBuffer
                                 &bytesRet,                     // BytesReturned
                                 0)) {                       // Ptr to Overlapped structure

                code = GetLastError();

                printf("DeviceIoControl failed with error 0x%x\n", code);

                return(code);
            }

            printf("Switches:\n");
            printf("    Switch8 is %s\n", switchState.Switch8 ? "ON" : "OFF");
            printf("    Switch7 is %s\n", switchState.Switch7 ? "ON" : "OFF");
            printf("    Switch6 is %s\n", switchState.Switch6 ? "ON" : "OFF");
            printf("    Switch5 is %s\n", switchState.Switch5 ? "ON" : "OFF");
            printf("    Switch4 is %s\n", switchState.Switch4 ? "ON" : "OFF");
            printf("    Switch3 is %s\n", switchState.Switch3 ? "ON" : "OFF");
            printf("    Switch2 is %s\n", switchState.Switch2 ? "ON" : "OFF");
            printf("    Switch1 is %s\n", switchState.Switch1 ? "ON" : "OFF");
            }
            break;

        case 7:

            sevenSegment = 0;

            if (!DeviceIoControl(deviceHandle,
                                 IOCTL_OSRUSBFX2_GET_7_SEGMENT_DISPLAY,
                                 NULL,             // Ptr to InBuffer
                                 0,            // Length of InBuffer
                                 &sevenSegment,                 // Ptr to OutBuffer
                                 sizeof(UCHAR),         // Length of OutBuffer
                                 &bytesRet,                     // BytesReturned
                                 0)) {                       // Ptr to Overlapped structure

                code = GetLastError();

                printf("DeviceIoControl failed with error 0x%x\n", code);

                return(code);
            }

            printf("7 Segment mask:  0x%x\n", sevenSegment);
            break;

        case 8:

⌨️ 快捷键说明

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