Author Topic: I am having difficulty getting any of my programs to access the USB ports  (Read 24405 times)

randdp

  • Member
  • ***
  • Posts: 5
When I run WinUsb I get no connected USB devices.  Even though I have a USB:
1) Mouse
2) Printer
3) USB to MIDI adapter
4) Hard  disc
connected to USB Ports.
I am using Windows 7 and I have tried it on a Windows Vista operating system.
I compiled code with Visual Studio 2008 Professional
Program is WinUsb dated 6/3/08 to 11/9/08

I have been trying to connect to the USB port in order to write a simple MIDI program that outputs through the USB interface.  I have been reading your "USB Complete" 4th edition and have been unable to get any positive results in writing my own simple program to identify what is connected to USB ports.  I am using VB9 to do the programming and don't fully understand everything that is needed to get a working program and was hoping that your WinUsb example would show me what is needed to accomplish my project.

All I really want to do is to identify my USB to MIDI interface and be able to send data to the interface.  I would love to do this using VB 6 but am also able to do it using VB 9 which is in the Visual Studio 2008 Package.

I would appreciate any information that would help in getting this program working.  Either the WinUsb program or my own stripped down version.

Do you have any suggestions as to how to accomplish the task of sending MIDI commands through the USB interface.  The USB-MIDI adapter is a:  E-MU XMidi1X1 Tab

I need to be able to send simple MIDI commands from a VB or C program to play 1 note at a time on a MIDI instrument.  A linkable routine would be great if one exists.  If I need to write the code, as I understand it I need to be able to identify this interface when it is plugged in and to get a handle to it and then send commands to the interface.

This is a non commercial home project.  I am a retired Electrical Engineer with some experience with writing VB and C code.
Regards, randdp

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Every USB device has an assigned driver on the host. How applications communicate with the device varies with the driver. For example, to access USB drives, you use the file system. Only some devices use the WinUSB driver.

To find out what driver your device is using, locate the device in Windows Device Manager. Select Driver > Driver Details. Tell us what you find.

Jan

randdp

  • Member
  • ***
  • Posts: 5
Here is most of the information about the driver - unfortunately typed by hand:

E-MU XMidi1X1 Tab
Driver File Details:
C:\windows\system32\drivers\dmk.sys
C:\windows\system32\drivers\ksthunk.sys
C:\windows\system32\drivers\portcls.sys
C:\windows\system32\drivers\USBAUDIO.sys
C:\windows\system32\SysFxUl.dll
C:\windows\system32\WMALFXGFXDSP.dll
Provider:  Microsoft Corporation
File version: 6.1.7600.16385(win7_rtm.090713-1255)
Copyright: MS Corp All rights Reserved
Digital Signer: Microsoft Windows

Properties:
Driver Date:   11/19/2010
Driver Version:  6.1.7601.17514

Properties (most of them.  have to ask for them 1 by 1):
Parent: USB\VID_041E&PID_3F0E\E-MU-E6-3F0E-07D90A1E-1014A-TAB
Container ID: {36c9d7cb-55ae-59a4-8215-ef5caaa46bae}
Driver Node Strong Name: wdma_usb.inf:Microsoft.ntamd64:USBAudio:6.1.7601.17514:usb\class_01
Driver assembly description: USB Audio Device
DevNode status:
0180200A
DN_DRIVER_LOADED
DN_STARTED
DN_DISABLEABLE
DN_NT_ENUMERATOR
DN_NT_DRIVER
Device Instance Path: USB\VID_041E&PID_3F0E&MI_00\7&12D82DF7&0&0000
Display name: E-MU XMidi1X1 Tab
Bus reported device description: E-MU XMidi1X1 Tab
Inf name:  wdma_usb.inf
Inf section: USBAudio
Matching device Id: usb\class_01
Rank of Installed Driver: 00FF2002
Included Infs: ks.inf   wdmaudio.inf
{b3f8fa53-0004-438e-9003-51a46e139bfc}[7]:  00000000
{d1885396-39d8-4777-bcff-5e3241483416}[0]:  00000002
Class upper filter: ksthunk
Class long name: Sound, video and game controllers
Class short name: MEDIA
Class Installer: mmci.dll,MediaClassInstaller
Class icon path: %systemroot%\system32\mmsys.cpl,-3004
Lower logo version: 5.1
Display name: Sound, video and game controllers
Class co-installers: mmcico.dll,MediaClassCoInstaller

So it looks like it uses the USBAudio driver.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Here is one example:

http://253.ccarh.org/lab/midiprog/

A search on

Windows midi programming

should bring up more.

Jan

randdp

  • Member
  • ***
  • Posts: 5
Jan,  This looks like the perfect solution!  It does compile and has no error messages. It is a very simple, easy to understand program.  I won't be able to try it out fully until Monday, however, since I am away from the instrument.  I'll post when finished with the testing.  Thank you very much for the reference.  I am very appreciative of this forum and your work.
When this is finished it will allow 1 person to tune a pipe organ from the organ loft by simply touching a few keys on a laptop.  An assistant will not be needed to sit at the console and play 1 note at a time, a rather boring job.  Considering that there are more than 600 pipes in a small organ that need to be tuned 1 by 1 it is impractical to run back and forth from the console to the pipe loft for each pipe.
 Many Regards, Richard

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Happy to help.

Jan

randdp

  • Member
  • ***
  • Posts: 5
Accessing the USB port works OK. However when there are more than 1 - the usual case since the included Microsoft Synthesizer also responds to MIDI commands, I would like the program to determine the correct one to use.  I have tried using the routines below to access the device names and actually got the names once but the program crashed.  I don't understand how to use these functions to get the device name (probably in szPname).  I have been unable to repeat the one success in a test program

for (midiport=0; midiport<3; midiport++;)
{
This works OK and the flag1 shows that the midiport number used is good or not.  The device handle is useful:
//  midiOutOpen(LPHMIDIOUT phmo, UINT uDeviceID, DWORD dwCallback, DWORD dwInstance, DWORD fdwOpen);
     flag1 = midiOutOpen(&device, midiport, 0, 0, CALLBACK_NULL);
     printf("flag1=%d  device=%8x   ", flag1, device);

Seems like this one should work since it says GetId in the name but it doesn't return anything useful so far:
//   midiOutGetID(HMIDIOUT hmo, LPUINT puDeviceID);
     flag2 =  midiOutGetID(&hmo, midiport);
     printf("flag2=%d  hmo=%8x  ", flag2, hmo);

This routine does pass a structure that contains szPname and I was able to get the name once but not reliably
I chose this routing only because the structure contained szPname:
//   waveOutGetDevCaps(UINT uDeviceID, LPWAVEOUTCAPS pwoc, UINT cbwoc);
     flag3 = waveOutGetDevCaps(midiport, &pwoc, cbwoc);
     printf("flag3=%d  pwoc=%8x  pwoc->szPname=%s \n", flag3, pwoc, pwoc->szPname);
}
I have no documentation on these routines.  I have just looked through the mmsystem.h file to find possibilities.

Can you help me understand how to extract the product name or other unique ID?
Regards, Richardd

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research

randdp

  • Member
  • ***
  • Posts: 5
Success!  I did find the routine that returns a useful ID for the plugged in USB MIDI adapter:
"midiOutGetDevCaps" does return useful information.  Searching on that name gives the definition of the prameters
Looking through the include file: "mmsystem.h" and the structure of the returned parameter can be found.
Several of the returned values can be used to ID the particular device.

Thank you very much for your help!

MMRESULT WINAPI midiOutGetDevCaps(UINT uDeviceID, LPMIDIOUTCAPS pmoc, UINT cbmoc);

typedef struct midioutcaps_tag {
    WORD    wMid;                  /* manufacturer ID */
    WORD    wPid;                  /* product ID */
    VERSION vDriverVersion;        /* version of the driver */
    char    szPname[MAXPNAMELEN];  /* product name (NULL terminated string) */
    WORD    wTechnology;           /* type of device */
    WORD    wVoices;               /* # of voices (internal synth only) */
    WORD    wNotes;                /* max # of notes (internal synth only) */
    WORD    wChannelMask;          /* channels used (internal synth only) */
    DWORD   dwSupport;             /* functionality supported by driver */
} MIDIOUTCAPS, *PMIDIOUTCAPS, NEAR *NPMIDIOUTCAPS, FAR *LPMIDIOUTCAPS;

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
You're welcome! Glad to hear it's working.

Jan