All,
Apologies in advance if this is an ill-informed question with lack of detailed examples of what I have tried to do so far - all the material I am finding on this topic seems to be out of scope of what I'm trying to do, or its just going right over my head (Learning resources on this are welcome!!).
What I am essentially trying to do is build a small program that will differentiate the input device used to create a user input on my Lenovo Win10 Machine that can run in the background and trigger scripts when certain conditions are met. In my case the input devices are a generic wireless/USB keyboard, and a USB Barcode scanner that acts as a HID Keyboard (The Barcode Scanners plugs directly into the machine, not via a keyboard).
The reason I need to differentiate the input is for example, if I have a script run every time an asterisk is printed from a scanned barcode I want the user to still be able to type an asterisk from the keyboard without triggering the script - Im restricted to using Code 128 barcodes so I also cant bypass this issue by adding characters to the barcodes to trigger the scripts that are not present on the keyboard.
In pseudo-code its essentially
start:
if inputdevice == keyboard 1
then
System.Diagnostics.Process.Start(myBatchFileName);
else
goto start;
Initially I tried to do this in VB, using some code I had previously used to listen to a COM Port to record output from an arduino -
Dim barcodescanner As SerialPort
barcodescanner = New SerialPort()
barcodescanner.PortName = "COMx"
barcodescanner.BaudRate = 9600
barcodescanner.Parity = Parity.None
barcodescanner.DataBits = 8
barcodescanner.StopBits = StopBits.One
Dim barcode As String
barcodescanner.Open()
barcode = barcodescanner.ReadLine()
barcodescanner.Close()
-however for reasons beyond me I cannot successfully use a virtual COM port for the scanner and record data this way, I also tried to create a virtual COM port using drivers from http://www.ftdichip.com/FTDrivers.htm but this was to no avail.
From some investigation I found some C# Classes, namely; InputEventArgs, InputDevice, RoutedEventArgs, that seem as if they could be used to resolve a device ID from an Input/Event that may allow be to harness some information I could use to flesh out and build the pseudo IF THEN ELSE loop above - but im struggling to use the classes and actually build any working code.
Does anyone have any suggestions as to how to do this?
In a perfect world if I could create a virtual COM port for the barcode scanner and listen to it using VB that would be ideal - but if not could anyone suggest a method of doing this in C# or point me to another method?
The problem is that a keyboard-emulating scanner and a keyboard work the same way and Windows does not allow you to find out which device actually sent the keystroke.
One way would be (if possible for your scanner):
Configure the scanner to work as COM port emulation (not possible with all scanners, only industrial ones support this normally)
Install the manufacturer's virtual COM port driver if necessary
Then you can actually open a COM port and communicate with the scanner as desired - you then, however, need to put the scanned strings into text fields yourself if required.
Second possible solution (if available for your device):
Configure the scanner to transmit a certain prefix or suffix along with the barcode content (most scanners can be configured to send a barcode identifier before the content, which is highly unlikely to be typed by the user)
Also configure the scanner to send CRLF or CR as last character
When you receive CRLF or CR, check whether the input starts with that prefix/ends with that suffix
If it does, remove the prefix/suffix from the text box and react to the "*" as desired.
I am trying to use multiple identical USB flatbed scanners for a C# project using a .Net TWAIN library. The problem with the TWAIN drivers is they are not set up to handle multiple instances of identical USB devices, in this case two Epson V37 scanners. The two scanners show up in device manager as separate but only the first scanner being plugged in shows up in TWAIN. This is not the case when two distinct scanner models are attached. My question is; is there a way i can change the drivers/registry entries enough to make it look like different scanners to TWAIN
I'm trying to capture or log all the print settings for any given print job that I make on Windows (in particular from Photoshop, but I don't think that matters much).
In particular, I want to log or capture the Printer Driver specific settings. I have an Epson 3880 which has many many print settings (colour/quality/media type). My understanding is that these settings are provided via the Specific Printer Drivers and not Windows?
Reason I want to do this is because I'm sampling many new paper types for fine art, and want to tweak and record all the settings I use for tracking. I found a few software monitors, but all they seem to track from the print jobs are No of copies, and paper orientation.
Any ideas?
While writing a native kiosk application one of the requirements that came up. While scanning the bar code with a 2D/QR code scanner, I've to identify if the bar code scanned was present on a mobile device(Passbook, etc) or was it on a printout. Is it possible to identify from where(mobile device or printout) the bar code has been scanned from, any tools which can do it?
Last option would be to have some sort of values in the bar/QR code during generation to differentiate them one for mobile devices and one for the physical mediums.
No that's not possible, 2 options:
Use 2 different barcodes, which will - in your system - lead to the same endpoint but can show the difference between a printout and a mobile scanned barcode.
Let the user that scans the barcode choose if it was scanned from a mobile device or a printout.
I have a "Symbol" brand barcode scanner (USB) and I am trying to capture the data it scans from a barcode into my application (which is running as a service -- with no textbox control, of course).
The catch is that : Whenever you scan something, it acts like a keyboard and outputs the digits to anything that has focus (i.e notepad, word, etc).
My question is: How do I perform this barcode scan in the background and put it in a variable that I can use in my in C#.
So far, the only api's that I've found are for the .NET CF and I need this to be a
windows service.
Basically, I want to be able to send certain keystrokes to an application if the barcode = "123456789-0111" without interfering with the current window that has focus. After my application reads the barcode in then it will look for a certain program (launch it and set focus) and send keystrokes. I am using Code 128.
The HID mode will be your best best.
Put the barcode reader in HID mode and make your service capture the reader. When data comes in take a look at it and if it is one of your special barcodes you can act on it.
If the data is not one of your special barcodes then inject them as keydown/keyup windows messages so that it will seem to work in the same fashion as in keyboard emulation mode.
Put the scanner into USB mode. This is generally done by scanning a series of barcodes in your manual or printed out from the software provided from symbol.
With the scanner plugged in/docked connect to windows update. You'll get an update specific to that scanner. It won't work if if the scanner is not plugged in.
The scanner should map to a com port. This has typically been com 2 on the machines I've set it up on.
Download JustinIO. For my scanner, useful COM settings: Baud Rate: 9600, ByteSize 8, StopBits: 1 Parity: 0
Create a new CommPort instance. Set up a thread that does something like:
StringBuilder sb;
byte[] b;
do
{
b = commPort.Read(1);
sb.Append(Encoding.ASCII.GetChars(b));
Thread.Sleep(20); //symbol is slow...
} while(b.Length > 0);
Note: that's much crunched down from the code that I'm actually using so you'll need to modify it for your application.
Send the string to your application via whatever method seems appropriate.
The scanner is configured as HID (human interface device) and emulating keyboard.
To access it through Symbol's API, you probably have to disactivate current communication mode and set it to native one - should be documented in the scanner manual. Then you can access it directly without input field.
PS. I have no Symbol's scanner, but this is common to many devices.
It really depends upon the barcode scanner's api, and that is specific to the vendor. You'll need to get the the api for the scanner from the vendor, if you can't find it on their site you should just email their support, though you might find you have to buy the api.
First..
Ignore the .NET CF info for now as it probably pertains to the actual handheld unit. The mode of operation, pretending to be a keyboard, is referred to classically as a 'keyboard wedge'.
Second..
What kind of barcode symbologies are you attempting to use? And for what purposes? Or, mor directly,...What do the barcodes look like when scanned? (Do they contain special leading and trailing characters?)
Third... keep it simple... avoid the API unless it is necessary...
In the past when I've had to interface with barcode scanners, I've used a very simple approach in that my data entry form has the property of KeyPreview true and contains a method to detect and direct input originating from the scanner (by examining starting and trailing characters) to the appropriate control. Most of the scanners I've dealt with were programmable (usually via barcodes) to pass a custom set of characters to signal beginning and end of scanned input.
I hope that helps....
Here is a CodeProject sample that demonstrates how to set up global mouse and keyboard hooks in C#:
http://www.codeproject.com/KB/cs/globalhook.aspx
You could add this code to your console application, and then just monitor all keyboard input, looking for the specific codes you need. No API fuss or muss.