I need to connect and disconnect USB programmatically. That is, I have inserted the USB device. I need to transfer the file using C#, .NET application. The application will watch the particular folder and transfer the file from that folder to a USB drive. I need to disconnect the USB device after the file is transfered and connect the USB when needed - without unplug and replug.
What would be some code to do it or is there any DLL file available?
Main thing: NOTE, NOTE: Without unplugging and replugging the USB device.
If your goal is to make a certain disk volume unavailable while you're not using it, a more sensible approach might be to use the volume management APIs, e.g. by using the IOCTL_VOLUME_OFFLINE control code. (I'm assuming that you know which drive letter belongs to your USB disk.)
Alternatively, you can disable and enable the volume device programmatically with the CfgMgr / SetupAPI -- the same as right-clicking the volume in Device Manager and choosing Disable would do. (For information about using SetupAPI, please review the DevCon sample code provided with the Windows WDK, and see MSDN for functions such as SetupDiChangeState.)
The latter option might require a privileged user account.
I'm not exactly sure, but it can be done. In Linux, I've experienced certain situations where power is disconnected to a device programmatically. The kernel usually does this if the connected USB device is exhibiting too many errors. So, it should be possible to do this even in Windows. You may need to write your own external DLL to do it though.
Related
Does anyone know how can I prevent a specific USB disk/flash from installing in a Windows Service? I don't want to disable all usb ports, I just prevent a specific usb disk from installing. I'm using windows 7.
Yes, is possible disable USB disk, using Kernel-Mode Filter Driver.
http://msdn.microsoft.com/en-us/library/windows/hardware/ff545890%28v=vs.85%29.aspx
Few years ago, I wrote project, that accept only USB disks with specified VID\PID.
Unfortunately, I can not find this project.
I took me several time and days to research and try some codes applicable to my problem but unfortunately I wasn't able to see codes that pair and receive files (text, images etc..NOT audio or video in particular) from a mobile device.
Most of the examples found are for SENDING only (From PC to Mobile).
I have bluetooth device (USB) physically attached to my PC.
Summary:
All I need is a sample code that automatically detect/pair when a device is trying to send the file (like in Kodak kiosk but not limited to images only).
I also wanted to understand and study the code.
Perhaps use my 32feet.NET library and its ObexListener class see e.g. http://32feet.codeplex.com/wikipage?title=Server-side&referringTitle=OBEX
For more advanced scenarios use Andy Hume's Brecham.Obex library and his server sample application. See http://inthehand.co.uk/files/folders/objectexchange/entry9942.aspx
Which Bluetooth stack does your PC have installed? Microsoft, Widcomm, BlueSoleil...? See e.g. http://32feet.codeplex.com/wikipage?title=Supported%20Hardware%20and%20Software On Widcomm for instance the build-in OBEX server would have to be disabled to allow your server to get all the incoming connections...
well guys, i am part of one team. (I dont have the project yet, i am new).
They did a application using gps, problem is it fail sometimes...
why? they think gps fails because users has the device in "energy saving" mode; then the device hibernates
after 5 minutes if they dont use it.
GPS brings sometimes bad coordinates (for example coordinate shows users is on "SEA" or in "Japan". I repeat, My partners thinks problem is because device is in "energy saving" mode. how can i change this configuration with C# while application is running (maybe back old configuration when application has been closed).
I am using this library.
using Microsoft.WindowsMobile.Samples.Location;
I can't check if it works because now i dont have a device, and i my computer doesn't have GPS, do you have any idea for i can check the application?.
i am using
`"Windows Mobile 6.0 SDK"`
You can install networking functionality while using the Microsoft Device Emulator. This blog explains how to setup network functionality on Windows 7. Follow the official documentation if you're not using Windows 7.
You can emulate GPS functionality using the FakeGPS program supplied by Microsoft. If you want anything close to real data you'll need a text file containing raw NMEA to feed into FakeGPS. You can simply record bytes passed through the GPS COM port to a file to generate a NMEA file. If fake GPS doesn't like your file then remove the non-standard NMEA lines and try again.
You should do some research on Windows Mobile Power Management first to understand the problem. The quickest hack is to simply call SystemIdleTimerReset() more frequently than the battery idle timeout (use SystemParametersInfo() and SPI_GETBATTERYIDLETIMEOUT) to prevent the device from sleeping. This will decrease the battery life of the device! There are other more elegant solutions available such as using the Power Management API.
I am using a Motorola DS4208 hand held barcode reader. In the past I was able to successfully setup and use this device, however recently it has stopped working. This may be the result of installing other devices that also use OPOS and POS for .Net interfaces.
This is a USB device so I created a Control Configuration file named *Moto_Scanner.xml* and placed it in the correct location.
<PointOfServiceConfig Version="1.0">
<ServiceObject Type="Scanner" Name="Example Scanner">
<HardwareId
From="HID\VID_05E0&PID_1300&REV_0100"
To="HID\VID_05E0&PID_1300&REV_0100" />
<HardwareId
From="HID\VID_05E0&PID_1300"
To="HID\VID_05E0&PID_1300" />
</ServiceObject>
</PointOfServiceConfig>
Using SOMgr.exe I can see the device in POSDevices with the proper path. I then created a LogicalName of MotoScan. It then appears in the Logical Names list as expected.
Using Microsoft Point Of Service\SDK\Samples\Sample Application\TestApp.exe I am able to open and claim the device. However, after attempting click the enable checkbox I get the following error message.
POSControlException ErrorCode(Failure) ExtendedErrorCode(0) occurred: Unable to enable the device. See inner exception for details.
System.ComponentModel.Win32Exception: The process cannot access the file because it is being used by another process
at Microsoft.PointOfService.ExampleServiceObjects.HidReader.HidThread.StartReading()
at Microsoft.PointOfService.ExampleServiceObjects.HidReader.OpenDevice()
at Microsoft.PointOfService.ExampleServiceObjects.ExampleScanner.set_DeviceEnabled(Boolean value)
Opened device: Example Scanner
Created instance of device: Example Scanner
Motorola provides an app called 123Scan to assist with configuration and testing. Using this app I can confirm the device works. This app was eventually uninstalled as part of troubleshooting.
Any suggestions will be appreciated.
Have you tried installing the OPOS driver?
EDIT:
Instead of re-linking this every time it expires, you should proactively search for "OPOS Driver" at http://support.symbol.com so that you can download the driver for the appropriate platform.
Through the learning process it became clear that opening and claiming a device does not mean it is actually connected. POS Explorer will allow you to open a connection and claim a device for exclusive use even if it not physically connected. This is partially because POS Explorer is using a Service Object to communicate with the hardware.
It is not until you enable a device, that you will have positive confirmation the device is available. In fact, if enable fails you have confirmation the device is not connected.
The Motorola DS4208 hand held scanner does not require a custom made configuration mapping file. After installing the Motorola ADK the correct Service Objects are installed and they have the Hardware Ids internally stored. In my previous code I attempted to use the "Example Scanner" Service Object available in the POS Explorer SDK to communicate with that hardware, that was my primary mistake.
After the OPOS Driver for Symbol Scanners v3.31 were installed I had not trouble testing the hardware.
I am using Visual Studio Team System 2008, C#, .NET 3.5, IIS 7.0, and ASP.NET. I am using Silverlight 3.0 as well. I want to read the content of a USB flash disk at the client side, using the information in the USB flash disk as a user profile identifier -- just like an online bank service is using a USB key to store a client certificate (but my security requirement is not that high).
How the content of a specific file in a USB flash disk in a web application (at the client side) be read? Could we do this in Silverlight (if can not, any alternative solution to read USB flash disk content)?
BTW: I want to read the content automatically, and I do not want the user to manually select the specific file on the USB flash disk to read.
You can not do this in Silverlight. You can read a file on the user's machine, but not without user intervention. The security model built into Silverlight will not allow it.
The best you can do is to read a user-specified file is to have them browse to it with a
file-open dialog box.
You can access the USB/flash drive if you are using a console/Windows Forms/WPF application locally. You can find the drives using the DriveInfo class, then iterate over them or use a LINQ query to find the drive you want to access. See the Stack Overflow question "How to find USB drive letter?" for details. Once you have a path, you can search it for the file you want. You do not need a special API or library, the Windows OS treats the USB drive as a normal drive, same as a "permanent" HDD connected to your system, and will do all the dirty work for you at that level. Just use the .NET I/O classes. However, if you wish to access the drive in an independent manner that does not depend on any OS, then you should use a 3rd party library.
I don't think what you're asking for is possible. If it IS possible, that's scary stuff... To allow a web site to grab stuff without user intervention? Uh-Uh. No way.\
Edit - Added after reading the comment
Using only the standard framework, no. USB support is not something that comes standard. You'd think there would be some classes in the System.IO namespace for USB ports like there are for COM ports, but no such luck. However, there are some libraries that will handle this. Here are some links to get you started.
http://weblogs.asp.net/israelio/archive/2005/08/15/422637.aspx
http://www.icsharpcode.net/OpenSource/SharpUSBLib/