I'm trying to contact an usb barcode scanner as a serial port, using his virtual COM port name and the Serial Port class.
The reason I'm trying to do it this way is to avoid using the scanner as a keyboard wedge since I need the possibility to scan even when the form is hidden.
Problem is that when I connect the barcode scanner to the usb port, and I run the "GetPortNames" function, I get an empty list. Any suggestions why? Thanks
Typically many USB barcode scanners will just appear as virtual keyboard devices - not virtual COM ports. That would explain why it doesn't appear.
Does your scanner support some kind of serial emulation mode? You may need to configure it or install different drivers to enable this. Does it appear as a serial port in Device Manager? (Look under the Ports tree)
As an aside:
Take a look at this question if you find that the 'keyboard mode' is the only one supported:
Reading a barcode using a USB barcode scanner along with ignoring keyboard data input while scanner product id and vendor id are not known
This question refers to this article with a large amount of good information relating to keyboard hooks and filtering out the scanned barcodes:
http://nicholas.piasecki.name/blog/2009/02/distinguishing-barcode-scanners-from-the-keyboard-in-winforms/
I cannot guarantee that it will work with your specific device, but I've seen code that solved a similar problem once. The solution was looking for the port name in the registry.
The code for it can be found in the open source project ez430chronosnet; a .NET library that can access TI's EZ430 Chronos watch via its USB dongle.
You'll want to look at the PortName.cs file that looks for the name in the registry (it will at least point you to the right keys) and the Chronos.cs file that does the actual port opening with SerialPort.
Related
I'm working on an access control windows application, I'm using .Net and a simple Barcode readers.
In my app, I'd like to use 2 barcode readers installed on the same computer in differents USB ports
First to log entrance.
Second to log exit.
How can I retrieve which Barcode reader was been used to log ? (the one plugged on USB port 1 or 2)
>> here is an explanatory diagram
#Abd13t,
If you are using the scanner in keyboard wedge mode and both scanners are going to be reading the same barcode, one way to do this would be to add different prefixes that your scanner appends to the data event.
If you using an OPOS or POS for .NET implementation your data events should be associated with a specific device.
In order to help you further, we would need more details.
Terry Warwick, Microsoft
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 am trying to programmatically access internal device counters of a document scanning device that is connected via USB to my computer. I am NOT interested in the data that a scanner normally outputs (content of scanned pages, etc)! Instead, I would like to know how many pages were scanned so far. Does anyone have a clue on how to access such data? SNMP is usually the way to go for such device counters, but not with USB devices (at least I am not aware of how to do it).
OS is Windows 7, programming language is C#, and the scanning device is a Canon DR-M160 (hopefully this shouldn't matter, as I try to create a vendor-independend solution).
How can I get details on NON-HID USB Devices? Like the serial number, etc in c#?
I have created successfully a sample application to retrieve those information on HID only devices but not on NON-HID USB Devices.
Have you looked into LibUSB .Net?
http://sourceforge.net/projects/libusbdotnet/
I remmber seeing that this was possible, I'll try and dig the article out.
You want to retrieve the device descriptors. Assuming a driver has been bound to the device, some of these are already available as they can be seen from Device Manager.
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)