When using the UWP MIDI API with a physical MIDI device, the app hangs on exit and cannot be forcefully terminated neither from command line nor from the Task Manager.
This happens for all UWP apps that use MIDI, including the official example from MSDN, without modifications.
I have raised an issue on GitHub about this, but it does not seem to be a new problem. MIDI is supposedly broken since 2014.
Is there a way to circumvent this problem in UWP through other means? I'm writing in C#, but I am fluent in C++ and could use lower-level APIs, if they existed. I only need to get MIDI input from a selected MIDI device (keyboard).
I also tried using the winmm.dll as suggested in the related post (Getting signals from a MIDI port in C#), but this does not work for me. The midiInGetNumDevs() method returns 0 when used from a UWP app.
I am using M-Audio Fast Track USB sound card (connected via USB) and an M-Audio 88es Keystation MIDI Keyboard (connected via USB). I haven't had problems in desktop applications.
I have discovered a partial workaround where I move the deallocation code to the App Suspending event handler instead of having it in a destructor. However, the problem still arises when a device is unplugged during app's lifetime. If the MIDI device is plugged in while the app is running, the app closes without problems (with the workaround). If the MIDI device is plugged in before the app is run and remains plugged in while the app is running, the app closes without problems (with the workaround). Only if the device is plugged out while the app is running will the app hang on close, regardless of whether the deallocation code is done in the destructor or in the App Suspending handler.
I’m unable to reproduce this issue. I believe it could be related to the audio card’s driver.
Using the sample you mentioned, https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/MIDI
• App did not hang when I closed it.
• I was able to remove the cable during app lifecycle, without issue. I was still able to send and receive messages after reconnecting.
• I was able to plug in the device mid-lifecycle, without issue. I was still able to send and receive messages.
Although it's currently working from desktop, it’s required to be “universal” for it to work well in UWP. Is the audio card driver universal?
In our developing drivers doc, we see a note to Use the InfVerif tool to verify that your driver package's INF file is universal. https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/infverif.
In the app developer documentation, I see a note to test the device metadata. https://learn.microsoft.com/en-us/windows-hardware/drivers/devapps/step-4--test-device-metadata
Additional documentation related to your question:
Building UWP device apps
https://learn.microsoft.com/en-us/windows-hardware/drivers/devapps/the-workflow
Test the device metadata for your UWP device app
https://learn.microsoft.com/en-us/windows-hardware/drivers/devapps/step-4--test-device-metadata
Getting Started with Universal Windows drivers
https://learn.microsoft.com/en-us/windows-hardware/drivers/develop/getting-started-with-universal-drivers
MIDI sample
https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/MIDI
Releasing resources in app suspend
https://learn.microsoft.com/en-us/windows/uwp/launch-resume/suspend-an-app#release-resources
Use Dispose to suppress finalization
NOTE: depending on a finalizer will keep resources in memory longer than necessary. They won’t be released until a full GC is performed or when the process exits.
https://learn.microsoft.com/en-us/dotnet/standard/garbage-collection/implementing-dispose
Related
I'm working on troubleshooting a device that only works once it has been unplugged and plugged back into its USB port on the PC.
The application that talks to the device is written in C#. So I need a programmatic way in C# or perhaps batch files, etc. to reset a USB device.
Thus far I've tried using the devcon.exe tool, but that doesn't seem to do the same job that physically removing and adding it back does.
Is it possible to use Win32_USBController to control a USB device's power through the port somehow? MSDN Link
Perhaps in a similar fashion, I found the CIM_Controller class, which has Reset() function. MSDN Link
The tools for resetting a USB port in the Windows Driver Framework/Kit don't appear to be readily accessible via a library or otherwise without first creating an actual driver unless I'm mistaken.
Thanks
I would recommend that you navigate to the directory and find the device. Right click on it and in the short cut menu click on eject. The application and the OS should handle the device. It is a bad idea to "unplug" a USB device, especially flash drives without ejecting them. You could end up with open file errors.
If the problem is not ejecting the device then the issue is probably with the application. If the application is opening a file on the device and the device has to be unplugged in order to function properly then the application may not be closing the open file properly...
Just saying
You might look at the SO link: How to programmatically unplug & replug an arbitrary USB device?
and read through that...
it sounds to me like your scanner is completing a task then shutting it's post down. it remains plugged into the PC but the PC does not 'see' it. go to the directory and see if it is still in the directory...
unplugging once the device shuts down the port does nothing. replugging reconnects the electronics and the PC becomes aware of the device which completes one more task. then shuts down its port again.
Dr t
I'm working on a Windows Universal App that communicates with BluetoothLE heart rate monitors. As of yesterday (related to a windows update, I'm thinking), things appear to be suddenly broken.
Specifically:
When I first pair a HRM device to my computer (in windows settings, not through their API), my app sees the device just fine, and can subscribe to notifications from the GATT Heart Rate Service (through a method close to the code here, in the C# sample.)
In all subsequent connection attempts, the app will detect the device normally, and indicate that it is paired to windows, but the HRM in question has a Device.ConnectionStatus of BluetoothConnectionStatus.Disconnected, and never reports hear rate updates.
If you run the MSDN sample above, you'll see the same thing, even though it's a Windows 8/8.1 sample.
This leaves me in a really sticky spot - I need to be able to communicate with these devices, but as of right now, it appears that I can only do so consistently unpairing the device from windows, and repairing it. That is obviously not acceptable.
I've found a few articles that seem to be tangentially related, but none seem to have found a solution. Help!
Note : I'm using VS2008 and I'm working on windows 7.
I'm developping a Windows CE application which will run on a Motorola MC3000 device with a WinCE 5.0 like OS .
I tried to use ActiveSync in order to make the test with the selected device possible but it doesn't work on win7, so I tried to find another tool and I found Windows Mobile Device Center based on this discussion .
So Now I can browse with the device but unfortunately I can not test with it : The device have a "santech" application installed and can not kill the app. (even when I reboot the machine, the autorun lunch the app. automatically). Also when I try to deploy my application on the device it return error reports ; sometimes "no disc space" sometimes "the .exe can not be found".
I'm really stucked.
Can some one help me with this, I will be really gratefull.
Sounds like the debugger is attaching just fine, it's just unable to either fully copy the app and dependencies, or there's not enough memory to execute it.
If you can browse the device, you can stop the "santech" app from running. You just have to determine what is launching it. It might be a shortcut in the \Windows\Startup folder. It might be through a registry entry at \[HKLM\Init\]. IIRC, Symbol devices also support a *.run file in the \Application\Startup folder, so check that as well.
One of those is launching the app, so you can eliminate that if you desire.
Next, check the available memory on the device by looking in the Control Panel under System->Memory and adjusting the slider to provide more storage space. If there's not enough Storage Memory to store your app, you might try changing the deployment directory (under Project Properties->Device) to push the app binaries to non-volatile storage of some sort (on-board Flash, SD card, etc), if the device has it.
If you don't have enough Program Memory to run your app, you might be out of luck. Try killing processes to free up some space and playing with the memory allocation slider.
You can debug from inside VS2008 as well. You'll need to tell it to connect to a device as it automatically sends it to a emulator. To do that you need to select Windows CE Device from the dropdown list found in the "Devices" toolbar (To enable go to View, Toolbars and select Devices). Then hit F5 and it should start up on your device. You might get a couple of pop-up boxes that contain a list of devices; make sure these are set to Windows CE Device as well.
This handy page on MSDN should provide the information you need also.
I am looking into making a c# program that will read in the logcat output from an android device and read it in to the c# program.
Initially it should do this while the phone is connected and it shouldn't require a specific app on the phone to be installed for the c# program to be able to retrieve the logcat output. Also the phone shouldn't require root access.
Is this something that is possible, I can't find anything on Google that says its possible but thought I'd ask on here in case someone has some useful information.
Thanks for any help you can provide
The most practical answer is to execute the shell command 'adb logcat' from your C# program and capture its output.
The only requirement for the device is that USB debugging be enabled in the settings menu.
The host PC will require that the android developer tools and appropriate USB driver for the device be installed. This can, unfortunately involve a substantial amount of hassle, especially finding the right drivers for windows hosts.
More complicated approaches would be to duplicate the functionality of the adb program (it is open source) and/or USB driver in your program, or to install an app on the device with the read logs permission which sends them to you - or even run an ssh server under the app userid so you can connect in and obtain them.
I have a device and the drivers for this device. What I would like to do is build an application that mocks a USB device to communicate with a third party application.
More specifically, I am attempting to build an application that can mock a USB device that mimics a Microsoft Zune. I want to make it so my application can register as a zune device and then communicate with the client. I have added several DLL's to my application in order to attempt to determine the calls that tell the software a connected device is a legitimate zune, but so far I haven't had much luck.
I'm new to this type of development - that is mimicking hardware devices, and I'm not very experienced in importing dll's that were written in C/C++. I am using Visual Studio 2010 (.net 4.0) to develop my app, and I would appreciate any help anyone can offer me towards mimicking the hardware. I do have the device drivers, which Visual studio refuses to reference directly. I also have an actual physical device, so I can see what the drivers are that it uses in Device Manager.
The goal is as follows
Application registers itself as a usb device, mimicking a Microsoft Zune in a similar fashion to how Virtual Clone Drive mimics a DVD player.
Application is recognized by zune client as a valid microsoft zune.
Zune Software works with application as it does the hardware device (syncing, etc)
I just found something called the Device Simulation Framework, which might be exactly what you need. It will still require significant research into how USB works to finish your solution, though. And probably still typically done using C or C++.
The Zune uses a modified version of the MTP protocol called MTPZ, but I found this sample using the Device Simulation Framework to simulate a regular MTP device. It's called The MTP Device Simulator. I can't tell if source code is available.
Are you able to replace the DLLs used by the zune client software with your own DLLs? In that case, you could wrap the original DLLs with your DLLs and intercept the operations.
Update: To find out the signatures of the functions in the DLL, take a look at the Dependency Walker tool, which will list the exported functions (and lots of other information). I'm guessing you will want to write your replacement DLL in C.
Otherwise, you'll have to write drivers that register a USB device with the proper endpoints. I'm not sure how to do this on Windows - I've only done USB coding on the firmware side, not the driver side. You should be able to use any tutorial for creating a Windows USB driver, like Getting Started with USB Driver Development
Zune specifics information might also be useful. Perhaps this blog post and its sequels could help: Inside the Zune/USB Protocol: Part 1