I need to connect and disconnect USB devices, such as flash drives, in a programmatical manner, without unplugging and re-plugging the device.
Is there any way to do it in a C# Windows application?
You might want to look at some related questions:
Safe remove USB-Drive using Win32 API?
Windows - Power off an usb device in software
Both of the approaches mentioned in the answers are readily translatable to C#.
Related
apologies if the question is quite basic, I am inexperienced in USB programming and I might be missing some conceptual detail here.
For our industrial solution we are supposed to provide communication between our PC wpf application and windows embedded HH 8.1 application. Ideally we would like this to be over USB.
I see a lot of sample code to connect directly to USB devices from host role.
However in our case the Windows Embedded HH device (Panasonic FZ-E1) will have the device role listening. I could not find any way to register to raw data sent from our PC application via USB events. I examined UMDF (user mode driver framework) which has examples about writing drivers for usb devices, yet it seems like it is for device manufacturers and us not being the manufacturer for Panasonic HH we should not/cannot use our own driver and we have to use the WinUSB driver it already has in place.
Windows Embedded 8.1 HH has some USB apis unlike windows phone, yet all the functionality provided in the API seems like connecting to external USB devices with the host role. When we use USBlyzer I see that there is some USB traffic towards the device from the PC so it looks it should be possible for the HH to have the listening device role. What am I missing here, any ideas?
Any help/direction is greatly appreciated.
P.S: I also tried windows connectivity api examining the source code of windows phone power tools yet it seems like the the dlls for addon packages here to handle transfer via agents is not there for newer versions of windows phone anymore.
This is quite a general question I think but searching online I can't really find that much information. I have an embedded system with a Bluetooth chip that I often use to connect to another embedded device. This connection is very robust and never fails.
However the embedded system can also connect to windows via a virtual serial port. I've written a piece of software to handle the connection using the 32Foot inthehand bluetooth library. It works very consistently on some computers (including my own) but entirely fails or is very flakey on others. One of which is actually an identical system ( same hardware/ same version of windows)
Is there anything I should specifically be looking at in my software to improve reliability accross different computers/ versions of windows when it comes to bluetooth pairing, creation of virtual com ports etc.
Thanks
I write software that runs on Windows and connects to an embedded device via a virtual serial port using the 32Foot library. I've experienced similar issues to you, and from experience the main problems are:
Conflicts between Bluetooth radio on Windows:
Is more than one Bluetooth radio installed/attached? I find that if on a Windows machine there is both an external Bluetooth dongle plugged in, and the internal Bluetooth is switched on, it won't work.
Widcomm/Broadcom and BlueSoleil stacks:
These don't support authentication, and Widcomm/Broadcom don't support setting of a pin. You can check if BluetoothRadio.PrimaryRadio is not null, and if so find out the SoftwareManufacturer of the Bluetooth Radio. If the Manufacturer enum is Bluesoleil, Widcomm or Broadcom then just don't use authentication or SetPin when initializing the BluetoothClient.
Toshiba stack:
This isn't supported at all
Is a supported Bluetooth radio and stack even currently available?:
You can handle a PlatformNotSupportedException which will tell you if there is no currently available supported Bluetooth stack on the machine. This won't let you know if there is more than one radio attached however.
Finally, from experience, internal Bluetooth chips don't always have a good range and interference can really affect the connection. I have had better luck with an external Bluetooth dongle.
Does anyone know if it's possible to use Bluetooth to connect to multiple phones using C# Monotouch/Xamarin iOS?
Update
I'd preferably like to connect multiple phones to one main phone
host, all via Bluetooth (1 host and 3 or 4 clients).
I don't know a
great deal about bluetooth and the various profiles, so I'd be
looking for guidance on this aspect also.
Yes, you can.
iOS 7.0 introduced the Multipeer Connectivity framework. It can work with both bluetooth and/or wifi (and can even bridge between them, pretty neat).
You can find sample code (e.g. chat, mixed with iBeacons) by googling around for Multipeer Connectivity, iOS and monotouch.
I am trying to find a sample that connect a Win RT app with other Bluetooth devices for example a PC. It is a basic thing but seems like it is not supported in WinRT.
In one thread a Microsoft employee says
.... Other than the call control sample, there is no Bluetooth stack
available for Store apps...
After reading other similar threads it seems to me that this is not possible at the moment. Am I right or is there any way to connect a Win RT app with some other device like a desktop app on PC via Bluetooth?
After reading many questions and articles (some links are below) on different forums I have reached to conclusion that communication between a Metro Style App and a PC is not possible via Bluetooth. One option is to go with is WiFi.
Some useful links which supports this conclusion are below
http://social.msdn.microsoft.com/Forums/en-US/tailoringappsfordevices/thread/6634240b-c042-4e76-a3b0-1f1103ea0ddf
http://social.msdn.microsoft.com/Forums/en-US/tailoringappsfordevices/thread/0cb2a6c1-d1f1-4872-aa32-709acd90b94d
http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/9db327e1-afe4-443b-8856-343492645083/
http://social.msdn.microsoft.com/Forums/en-US/tailoringappsfordevices/thread/172061f4-56ff-4fd2-987d-687d4703506d
The WinRT 8.1 Bluetooth stack provides the requisite services for ad hoc Bluetooth communications with similarly capable devices. More specifically, peer discovery and peer to peer communications is supported.
I want to write a simple program that detect USB Wifi plugged computer and unplug it. I am finding code or library help me to do that (C# or Delphi). Tell me if you know :)
Or
Code or lib that list all USB devices on computer ?
Thanks !
I can only answer part of the question. You can "eject" USB devices using this API:
CM_Request_Device_Eject (MSDN link)
I'm using it to eject USB thumb drives after I copy stuff onto them in a backup application. I'm pretty sure there are ways of enumerating available USB devices using one of the many CM_XXX routines, but I was only interested in storage devices connected via USB, so I can't comment on WiFi devices.
An other sugestion: Maybe you can solve your problem at an other layer, maybe you can detect the addition of a new network adapter and disable that. Not all USB devices can be ejected, it's probably a driver-related issue. But I guess, if you can eject it from the notification area icon, you can eject it from code.
may have a look at http://sourceforge.net/projects/libusbdotnet/ (never used it by myself)