LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do you use the MPUSBAPI.dll?

For some reason the attached DLL driver (Mpusbapi\Dll\Borland_C\Mpusbapi.dll) seems to crash whenever it is run within LabVIEW.  I have run this dll under visual c++ and it works just fine.  In particular the functions MPUSBRead and MPUSBWrite are generating errors within LabVIEW. The other functions of this DLL such as MPUSBGetDeviceCount and MPUSBGetDllVersion are working correctly.   I am using the "Call Library Function" to access this DLL.  Is there anything special that I have to do to use the functions MPUSBRead and MPUSBWrite?  Any suggestions?  Thanks.  Below is the header for this dll.

#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

extern "C" __declspec(dllexport)
DWORD MPUSBGetDLLVersion(void);

extern "C" __declspec(dllexport)
DWORD MPUSBGetDeviceCount(PCHAR pVID_PID);

extern "C" __declspec(dllexport)
HANDLE MPUSBOpen(DWORD instance,    // Input
                 PCHAR pVID_PID,    // Input
                 PCHAR pEP,         // Input
                 DWORD dwDir,       // Input
                 DWORD dwReserved); // Input <Future Use>

extern "C" __declspec(dllexport)
DWORD MPUSBRead(HANDLE handle,              // Input
                PVOID pData,                // Output
                DWORD dwLen,                // Input
                PDWORD pLength,             // Output
                DWORD dwMilliseconds);      // Input

extern "C" __declspec(dllexport)
DWORD MPUSBWrite(HANDLE handle,             // Input
                 PVOID pData,               // Input
                 DWORD dwLen,               // Input
                 PDWORD pLength,            // Output
                 DWORD dwMilliseconds);     // Input

extern "C" __declspec(dllexport)
DWORD MPUSBReadInt(HANDLE handle,           // Input
                   PVOID pData,             // Output
                   DWORD dwLen,             // Input
                   PDWORD pLength,          // Output
                   DWORD dwMilliseconds);   // Input

extern "C" __declspec(dllexport)
BOOL MPUSBClose(HANDLE handle);

#endif

0 Kudos
Message 1 of 25
(11,662 Views)
This DLL uses some non standard types.  Any suggestions as to how I can work around this?   Could this be the cause of the errors that I am seeing?
0 Kudos
Message 2 of 25
(11,653 Views)
What does you LabVIEW code look like? I'm guessing you're not properly allocating the memory for those pointers.
0 Kudos
Message 3 of 25
(11,649 Views)
I've attached the project
0 Kudos
Message 4 of 25
(11,644 Views)
When you use the read function are you pre-allocating the buffer in your calling function, or are you trying to use the read function directly? The latter will probably cause a crash. You need to pre-allocate the buffer using Initialize Array.
0 Kudos
Message 5 of 25
(11,637 Views)
I'll try that, but I think it may be a different problem since my write function also is returning a '0' indicating that the write function generated an error during execution.  Thank you.
0 Kudos
Message 6 of 25
(11,633 Views)
For the write are you properly setting the value for dwLen, which is the length of the input array in your calling VI? I have no idea what pLength is for since I don't have the documentation for that DLL.
Message 7 of 25
(11,628 Views)
I've attached the functional C code that implements this DLL.  I am making the changes that you suggested. 
0 Kudos
Message 8 of 25
(11,622 Views)
Attached is the DLL's .cpp code.  From the .cpp code:  "//  dwLen   - Specifies the number of bytes to write to the pipe."


0 Kudos
Message 9 of 25
(11,604 Views)
As I suspected, it's the length of the data array that you're trying to write. You just need to make sure you set the value to be the length of the array. This doesn't really need to be a control for the wrapper VI since you can use the Array Size function to just get it from the input array.
0 Kudos
Message 10 of 25
(11,599 Views)