Set USB keyboard status in C# - c#

I need to send output reports to a USB "keyboard", but Windows returns an invalid handle when using CreateFile on the USB device. This is because Windows has the device open in exclusive mode. How do I still send output reports to the keyboard?
I have already looked into the HidP_Xxxx functions, but they all require the CreateFile to succeed with a valid handle. Also the Direct Input's SendDeviceData's documentation says that no device will work with it and to use HID instead. The link to HID documentation is broken on that page.

maybe this is an issue of the driver (the .inf file) of the barcode scanner and some specific keys it sets in registry, see the following links
http://www.cypress.com/knowledge-base-article/exclusive-access-usb-device
https://msdn.microsoft.com/en-us/library/windows/hardware/ff563827(v=vs.85).aspx (specifying exclusive access to device objects)
https://msdn.microsoft.com/en-us/library/windows/hardware/ff548407(v=vs.85).aspx (IoCreateDeviceSecure routine)
https://msdn.microsoft.com/windows/hardware/drivers/install/inf-addreg-directive
https://msdn.microsoft.com/en-us/library/dn790026(v=vs.85).aspx (register and initialize the barcode scanner driver)
https://msdn.microsoft.com/de-de/library/windows/desktop/ee416848(v=vs.85).aspx (Cooperative levels)
maybe use a program like USBDeview to clean the registry and reinstall the scanner again (check the inf file for the AddReg entry) or try to remove the exclusive access registry key for the barcode scanner manually
in addition the windows 10 hidscanner.dll seems to be buggy https://answers.microsoft.com/en-us/windows/forum/windows_10-hardware/pos-hid-barcode-scanner-drivers-being-deleted/206b5354-06e0-47cb-98b8-805f525e130e , https://answers.microsoft.com/en-us/windows/forum/windows_10-hardware/windows-10-with-pos-hid-barcode-scanner/2adc8ea9-556c-4b85-98fe-3b625c37ab76

Related

im have trouble with adding pos printer to posdm (configuration.xml or command line adddevice)

I am having trouble with adding my Pos Printer to PosDM in Configurattion XML and with command line add device.
i had searched a lot about this but got nothing Useful
i had tried the command line add device like:
"posdm adddevice SWD\PRINTENUM{9475957E-9973-435B-AF15-4591F5938233} /type:PosPrinter /soname:"EPSON TM-T82 ReceiptSA4"
by using this i got "no SO found that matches!"
i also added the logical name of device in configuration.xml:
but when i use the command "Posdm listdevices" i doesnt show me my printer
"SWD\PRINTENUM{9475957E-9973-435B-AF15-4591F5938233}" is the DevicePath as a standard Windows desktop printer.
EPSON OPOS/OPOS for.NET should not support that mode.
If it is visible on the device manager, it is a usage mistake.
Disconnect the printer, uninstall the printer driver, use the OPOS ADK for.NET, see Appendix-C in the appropriate printer manual, change the hardware settings, and reinstall the device driver (USB serial?) .
Configurattion XML of PosDM settings should be set in the GUI by running the SetupPOS tool of EPSON OPOS for.NET as an administrator instead of the command line.
For details, refer to the SetupPOS User's Reference Manual.
To set the default printer in code behind try:
app.ActivePrinter = "EPSON TM-T82 ReceiptSA4";

OPOS Configuration.xml DevicePath Property

We use a windows iot version to do a cash drawer Service Object of OPOS.
We open the cash drawer using GPIO pin,so we communication with system
using Physical Memory address to do a open
We don't know how to set a Hardware Device Path of Configuration file of POS.NET
environment.
Someone could help us to deal with the Hardware Device Path problem?
<Device HardwarePath="0xFED0C1D8" Enabled="yes" PnP="no">
<LogicalName Name="WASPCD" />
</Device>
The HardwarePath="0xFED0C1D8" is our GPIO address ,is that right?
If the cash drawer service object you are using is made by OPOS instead of POS for.NET, you do not need to write the configuration.xml of POS for.NET.
Please make sure that Common Control Objects are installed.
Follow the procedure below to open the cash drawer device in the application.
2-1.Acquire the device collection by calling the GetDevices method with CashDrawer as the type parameter and Opos or OposAndCompatibilityLevel1 as the compatibility parameter.
2-2. Search the device information with the device name key or logical device name of the device being used defined in the OPOS registry from the acquired device collection, and perform CreateInstance based on it.
2-3. Call Open method using created object.

ClaimedBarcodeScanner.DataReceived() event as keyboard input for WebView control (UWP)

I have successfully written an app for Honeywell Dolphin 75e device with both embedded and external ring scanner running Windows 10 Mobile Enterprise.
There are plenty of resources on how to deal with barcode scanners in UWP on the Internet. However, all off them are scanning into some text based user controls like so:
private async void ScenarioStartScanButton_Click(object sender, RoutedEventArgs e)
{
// Add a data receive event handler.
claimedScanner.DataReceived += claimedScanner_DataReceived;
}
async void claimedScanner_DataReceived(ClaimedBarcodeScanner sender, BarcodeScannerDataReceivedEventArgs args)
{
// Update the UI with the data received from the scan.
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
// Read the data from the buffer and convert to string.
var scanDataLabelReader = DataReader.FromBuffer(args.Report.ScanDataLabel);
ScenarioOutputScanDataLabel.Text = scanDataLabelReader.ReadString(args.Report.ScanDataLabel.Length);
var scanDataReader = DataReader.FromBuffer(args.Report.ScanData);
ScenarioOutputScanData.Text = scanDataReader.ReadString(args.Report.ScanData.Length);
ScenarioOutputScanDataType.Text = BarcodeSymbologies.GetName(args.Report.ScanDataType);
});
}
But what I need is the scanner to act like a keyboard on my WebView control:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<WebView Source="http://google.co.uk"/>
</Grid>
When I don't use (don't claim) scanner explicitly in my app and leave the default working like it does globally for any app, the scanner does what I need in my WebView. But since I have to assign/claim different scanners within my app, I have to make it act like a keyboard, meaning, that when any user input field inside the WebView gets focus, I just scan input into it.
Here I found a similar question, although it was easy to solve, since only the parameter in URL (search term) had to be different for each scan.
UPDATE: I also thought about a workaround, so my app would claim the scanner and retain it even when I leave the app. In that case I could open a browser, navigate to my web app and use desired scanner. Unfortunately, all but embedded scanners seem to get disposed after I leave the app. Even though I don't explicitly dispose them.
None of Honeywell provided test apps seem to retain the claim either.
Ok, looks like I now understand how it all works. For what I need, I don't need to create any app that would claim and enable specific scanner, as it would put the scanner from default Wedge Mode to POS Mode.
The difference between those two modes is described in Dolphin 75e user guide.
Dolphin 75e models running Windows 10 IoT Mobile Enterprise has two scan modes, Wedge mode and POS mode. In Wedge mode bar code data is inserted into the keyboard interface, as if the bar code data was entered using the keyboard. POS mode implements Microsoft Point of Service interface. In POS mode, barcode data is sent to an application via the Microsoft defined APIs.
Scan wedge mode is enabled by default. The 75e remains in wedge mode until POS application starts and claims the scanner. The terminal only switches back to wedge mode when the POS application releases its claim on scanner.
So, all I need is to place scanner config file into /Documents/Profile folder, specifying which scanner I want to use in the Wedge mode. Unfortunately, my USB HID ring scanner cannot be put into the wedge mode...
Note that wedge mode is not supported for USB HID scanner in v66.4.0.638, or v66.4.0.569.
So after all this struggle I found out that if one wants to use 75e scanner for custom web app, or scan to, say, Excel spreadsheet - his only option is to use embedded scanner, which operates in Wedge mode by default.
And if you want to use USB HID scanner, then you can only use it for specifically developed app that implements Microsoft defined APIs. So basically, you will only be able to scan to specific user controls - text blocks, input fields - as shown in my first post.
UPDATE: Since version 66.4.0.718 USB HID scanner can also be used in wedge mode!

Sending a USB "keyboard" a set of output reports to switch USB modes

I have a camera that initial shows up as a USB keyboard and needs a sequence sent to it before it will reset the USB connection as a USB HID device. This sequence is a set of output reports (1 Byte per report) setting and clearing "LED Status" flags. Sometime the camera will attach as a USB HID device but still need the sequence.
My 2 Questions are:
How do I get Windows to send this "keyboard" the proper sequence?
How do I change the output report packet size (i.e. set it to 1 + reportID number instead of the 64 + reportID number that it is sending)?
install USBView or USB Device Tree Viewer and post a screenshot or something. normally this can be done either by USB control requests ( https://msdn.microsoft.com/en-us/library/windows/hardware/ff539261(v=vs.85).aspx ) or USB HID feature reports ( https://msdn.microsoft.com/en-us/windows/hardware/drivers/hid/introduction-to-hid-concepts , https://msdn.microsoft.com/en-us/library/windows/hardware/ff539684 ) with no more information about the internal structure of the USB tree in the device this is impossible to say...

Complete removal of the driver files in Windows XP

I'm developing an application which involves installation of some project specific hardware devices. On the installation of the application, I'm using difxAPI to push the driver inf files into the Driverstore. But after the unintallation using the difx, there are still some references left in the windows registry, under HKLM\SYSTEM\CurrentControlSet\Enum\USB. The presence of these references tend to be a problem as the devices gets enumerated and showing its entry in COM ports section of Device Manager. This is what I use for uninstalling the drivers:
DriverPackageUninstall(infName, DRIVER_PACKAGE_DELETE_FILES, ptrInstallerInfo, out fNeedReboot);
Again I thought of clearing those registry entries programatically for that I understand I should be setting the access permission for accessing the particular keys. This is what I did:
RegistryAccessRule regAccess = new RegistryAccessRule("Everyone", RegistryRights.FullControl, AccessControlType.Allow);
RegistrySecurity regSecurity = new RegistrySecurity();
regSecurity.AddAccessRule(regAccess);
Registry.LocalMachine.OpenSubKey(#"SYSTEM\CurrentControlSet\Enum\USB\", true).SetAccessControl(regSecurity);
But this piece of code is throwing an exception as it is not allowing me to set the access control programatically. In a Windows XP machine manually I'm able to set this permission from registry editor. Is there an efficient way in XP by which I can remove the driver files completely?
It's strange. DifxAPI should remove both a) the driver package from the driver store, b) the installed instances of this driver. Are you sure those old device instances (in HKLM\SYSTEM\CurrentControlSet\Enum\USB) are using the driver you're removing, or perhaps an older version of its .INF files or whatnot?
Basically, though, Microsoft doesn't want you playing with Enum and changing ACLs. They'd rather have you enumerate and remove devices through SetupAPI (as shown in the devcon sample in the Windows DDK).
I've lately wrote code to do just that: all my devices share the same custom device class so they were easy to enumerate, and then I blindly removed them following the code from devcon.

Categories

Resources