Forum: PC-Programmierung mpusbapi.dll und dev cpp unter Windows 7


von FakerFacker (Gast)


Lesenswert?

Hi Leute, ich versuche seit Tagen einen App zu schreiben der das 
USB-Device von 
http://www.sprut.de/electronic/pic/8bit/18f/programm/usb2550/usb2550.htm

ansprechen soll. Es soll zunächst sehr primitiv sein(Schwarze C-Box) und 
später eventuell ein GUI bekeommen. Mir ist bewusst, dass ich irgendwie 
auf die mpusbapi.dll zugreifen muss, da diese wohl mit dem 
USB-Controller kommuniziert.Folgender Sourcecode, lässt sich 
Compilieren, die Anwendung lässt sich auch starten, jedoch stürzt die 
Anwendung beim Aufruf einer Funktion aus der DLL-datei ab und 
funktioniert plötzlich nicht mehr...

Der Teufel steckt beim Programmieren ja oft im Detail. Es wäre schön 
wenn du dir mal zeit nehmen könntest um die c-datei und die h-datei 
durch zu sehen. Wenn du helfen kannst machst du einen Menschen 
glücklicher:)


mpusbapi.c

/*********************************************************************
 *
 *                Example 01 - Load-time Linking
 *
 *********************************************************************
 * FileName:        mpusbapi.cpp
 * Dependencies:    None
 * Compiler:        DevC++ 4.9.9.2
 * Company:         Copyright (C) 2011 P_Engineering
 *
 * Software License Agreement
 *
 *
 *
 * THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES,
 * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
 * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
 * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
 * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
 *
 * Author               Date        Comment
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * Pete Glocke       10.08.11
 ********************************************************************/

//---------------------------------------------------------------------- 
-----


#include <stdio.h>
#include "windows.h"
#include <string.h>
#include <setupapi.h>
#include <initguid.h>
#include <winioctl.h>
#include "mpusbapi.h"                  // MPUSBAPI Header File

//---------------------------------------------------------------------- 
-----
//#pragma argsused

// Global Vars
char vid_pid[]= "vid_04d8&pid_000c";    // Default Demo Application 
Firmware
char out_pipe[]= "\\MCHP_EP1";
char in_pipe[]= "\\MCHP_EP1";


DWORD temp;

HANDLE myOutPipe;
HANDLE myInPipe;
HANDLE myRueckgabewert;
HANDLE a=0;

//---------------------------------------------------------------------- 
-----
// Prototypes
void GetSummary(void);

//---------------------------------------------------------------------- 
-----

int main(int argc, char* argv[])
{
    BOOLEAN bQuit;
    DWORD selection;
    bQuit = false;

a=LoadLibrary("mpusbapi.dll");

    // Always a good idea to initialize the handles
    myOutPipe = myInPipe = INVALID_HANDLE_VALUE;

    printf("Microchip Technology Inc., 2004\r\n");
    printf("===============================\r\n");
    while(!bQuit)
    {
        printf("Select an option\r\n");
        printf("[1] Get MPUSBAPI Version\r\n");
        printf("[2] Summarize Instances\r\n");
        printf("[3] -\r\n");
        printf("[4] Quit\r\n>>");
        scanf("%d",&selection);

        switch(selection)
        {
        case 1:
           temp = MPUSBGetDLLVersion();
           printf("MPUSBAPI Version: 
%d.%d\r\n",HIWORD(temp),LOWORD(temp));
           break;
        case 2:
           GetSummary();
           break;
        case 3:
           // Place Holder
           break;
        case 4:
           bQuit = true;
           break;
        default:
           break;
        }// end switch



        fflush(stdin);printf("\r\n");
    }//end while

    // Always check to close all handles before exiting!
    if (myOutPipe != INVALID_HANDLE_VALUE) MPUSBClose(myOutPipe);
    if (myInPipe != INVALID_HANDLE_VALUE) MPUSBClose(myInPipe);
    myOutPipe = myInPipe = INVALID_HANDLE_VALUE;

    return 0;
}//end main

//---------------------------------------------------------------------- 
-----

void GetSummary(void)
{
    HANDLE tempPipe = INVALID_HANDLE_VALUE;
    DWORD count = 0;
    DWORD max_count;

    max_count = MPUSBGetDeviceCount(vid_pid);

    printf("\r\n%d device(s) with %s currently 
attached\r\n",max_count,vid_pid);

    // Note:
    // The total number of devices using the generic driver could be
    // bigger than max_count. They could have different vid & pid 
numbers.
    // This means if max_count is 2, the valid instance index do not
    // necessary have to be '0' and '1'.
    //
    // Below is a sample code for searching for all valid instance 
indexes.
    // MAX_NUM_MPUSB_DEV is defined in _mpusbapi.h

    count = 0;
    for(int i = 0; i < MAX_NUM_MPUSB_DEV; i++)
    {
        tempPipe = MPUSBOpen(i,vid_pid,NULL,MP_READ,0);
        if(tempPipe != INVALID_HANDLE_VALUE)
        {
            printf("Instance Index # %d\r\n",i);
            MPUSBClose(tempPipe);
            count++;
        }
        if(count == max_count) break;
    }//end for
    printf("\r\n");
}//end GetSummary

//---------------------------------------------------------------------- 
-----






und mpusbapi.h

/*********************************************************************
 *
 *                  MPUSBAPI Library Version 1.00
 *
 *********************************************************************
 * FileName:        mpusbapi.h
 * Dependencies:    None
 * Compiler:        C++
 * Company:         Copyright (C) 2004 by Microchip Technology, Inc.
 *
 * Software License Agreement
 *
 * The software supplied herewith by Microchip Technology Incorporated
 * (the “Company”) for its PICmicro® Microcontroller is intended and
 * supplied to you, the Company’s customer, for use solely and
 * exclusively on Microchip PICmicro Microcontroller products. The
 * software is owned by the Company and/or its supplier, and is
 * protected under applicable copyright laws. All rights are reserved.
 * Any use in violation of the foregoing restrictions may subject the
 * user to criminal sanctions under applicable laws, as well as to
 * civil liability for the breach of the terms and conditions of this
 * license.
 *
 * THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES,
 * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
 * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
 * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
 * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
 *
 * Author               Date        Comment
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * Ross Fosler          9/2/04      Implemented MPUSBGetDeviceLink()
 * Rawin Rojvanit       11/19/04    Original version 1.00 completed
 ********************************************************************/

#ifndef MPUSBAPI_H
#define MPUSBAPI_H

#define  MPUSB_FAIL                  0
#define MPUSB_SUCCESS               1

#define MP_WRITE                    0
#define MP_READ                     1

// MAX_NUM_MPUSB_DEV is an abstract limitation.
// It is very unlikely that a computer system will have more
// then 127 USB devices attached to it. (single or multiple USB hosts)
#define MAX_NUM_MPUSB_DEV           127

DWORD (*MPUSBGetDLLVersion)(void);

DWORD (*MPUSBGetDeviceCount)(PCHAR pVID_PID);

HANDLE (*MPUSBOpen)(DWORD instance,         // Input
                 PCHAR pVID_PID,            // Input
                 PCHAR pEP,                 // Input
                 DWORD dwDir,               // Input
                 DWORD dwReserved);         // Input <Future Use>

DWORD (*MPUSBRead)(HANDLE handle,           // Input
                PVOID pData,                // Output
                DWORD dwLen,                // Input
                PDWORD pLength,             // Output
                DWORD dwMilliseconds);      // Input

DWORD (*MPUSBWrite)(HANDLE handle,          // Input
                 PVOID pData,               // Input
                 DWORD dwLen,               // Input
                 PDWORD pLength,            // Output
                 DWORD dwMilliseconds);     // Input

DWORD (*MPUSBReadInt)(HANDLE handle,        // Input
                   PVOID pData,             // Output
                   DWORD dwLen,             // Input
                   PDWORD pLength,          // Output
                   DWORD dwMilliseconds);   // Input

BOOL (*MPUSBClose)(HANDLE handle);

#endif


Danke

von Rufus Τ. F. (rufus) Benutzerseite


Lesenswert?

*Längeren Sourcecode nicht im Text einfügen, sondern als Dateianhang*

von FakerFacker (Gast)


Lesenswert?

Entschuldigung! Soll ich es berichtigen oder löschen und neu Posten?

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.