I'm building web application for fitness center, they have a barcode scanner to which you are scanning your gym card into. What i'm trying to accomplish is to somehow get the data that the scanner is providing to them (name,surname and time of monthly subscription). My web application is built in ASP.NET C#, this is my first time dealing with this kind of problem.
I would appreciate your help or any other word of advice, feel free to ask more detailed questions.
If gym has barcode scanner like this
, it is seen in the system as a keyboard.
Such a scanner should also be able to set the ending character Tab or Enter. You do not need to confirm the scanned code then.
A card with a barcode as above returns the card number associated with a given person in the database.
You probably don't have access to the barcode scanner from MVC (Core or Framework). To do that you would probably have to run some software on the computer or phone that is scanning the member cards. There might be a solution though since the barcode scanner might be able to copy the id. This way you could input it to an input field in your MVC application and post it to the backend from there.
If i understand your Question correctly you probably need a SerialPort.
its actually pretty easy..
SerialPort serPort = new SerialPort("COM7"); // thats the USB port on which the scanner is connected
serial.DataReceived += new SerialDataReceivedEventHandler(serial_DataReceived);
serPort.Open();
and now you will receive everythig the Scanner has on:
private void serial_DataReceived(object sender, SerialDataReceivedEventArgs e){
string response = serPort.ReadExisting();
//do work
}
also if u dont know which port it is connected on use :
foreach (string sp in SerialPort.GetPortNames())
{
port = new SerialPort(sp)
{
Encoding = Encoding.GetEncoding("Windows-1252")
};
port.DataReceived += new
SerialDataReceivedEventHandler(Port_DataReceived);
port.Open();
}
this will watch over every Port you have see if something is connected and opens a connection to it, obviously if u have something like a mobile phone connected it will open a port with it too. but you can just make a check that if u scan u will only take that port and so on..
IF i did understand your question correctly that u want to know how to communicate with the Scanner thats how you do it.
if that was not your question, please comment and Clarify im working all day with Mobile Scanners Reading Barcodes so i think i will be able to help you.
Almost all handheld barcode scanners have a barcode in it's manual to change the scanner to function as a keyboard wedge. This way the scanner functions exactly like a keyboard device. You'd scan a barcode and keycodes are sent to the cursor location.
So just look up the make/model of your scanner and download its manual and look for a barcode that you can scan to change its emulation mode.
Related
I am currently working on a C#-UWP app that needs to be able to discovery bluetooth devices (Not BLE) on the network and ones that have been previously connected to/paired.
Im sure anyone who is new to this task will have quickly found the documentation and example are of little help. I have learned more from Stackoverflow questions about peoples experimentations than from the docs and examples, but anyways.
My main question/problem is this: After setting up the device watcher to find bluetooth devices I found that I consistently get multiple additions of the same device but having a different bluetooth address (this is a device that was previously paired but not live on the network). After much investigate and brainstorming, we discovered that each device id is actually a pairing of the devices MAC address and the BT receivers MAC address.
The reason I was getting 3 device additions per 1 physical device is because I have connected to that same device with 3 different BT receiver dongles in the past. So my question is, is there anyway to make the device watcher return the device that corresponds to the currently active BT receiver dongle?
Otherwise I will need to find the currently active BT receivers MAC address and filter out the devices that do not have this, because otherwise the user will see 3 identical devices to select and only 1 of them will pass while the other 2 will fail.
While on this subject I would also like to mention that the device properties dont seem to be working. Before creating the watcher, I have a list of properties like this for example:
requestedProperties.Add("System.Devices.Aep.DeviceAddress");
requestedProperties.Add("System.Devices.Aep.IsConnected");
requestedProperties.Add("System.Devices.Aep.Bluetooth.Le.IsConnectable");
requestedProperties.Add("System.Devices.Aep.IsPresent");
requestedProperties.Add("System.Devices.Aep.ContainerId");
requestedProperties.Add("System.Devices.Aep.ModelId");
requestedProperties.Add("System.Devices.Aep.Manufacturer");
requestedProperties.Add("System.Devices.Aep.ProtocolId");
requestedProperties.Add("System.Devices.Aep.SignalStrength");
But when I debug the device that is added, it doesnt have any properties:
debug info showing no properties for added device
I would be useful to have this information.
Thank you for any input or suggestions.
Update
I found a quick solution that overcomes this problem (although i did find a lot more problems with the device watcher but that is probably a topic for another question).
For now I simply get the current BT adaptors MAC address and then check each incoming device if it has this MAC address in its pair. If it does not that means the device is paired with an old/unused BT adaptor.
/* NOTE:
Windows allows only 1 BT adapter to be active on 1 machine at a time
Therefore this function will either return the active dongle or a null if
there is no BT adapter on the machine or its disabled.
*/
BluetoothAdapter BTAdaptor = await BluetoothAdapter.GetDefaultAsync();
if (BTAdaptor == null)
{
// Log error
// return
}
//
// Code block to check if the BT adaptor can support the BT tech stack you are interested in.
//
// Format into hex with 12 characters (12 being the number of characters for MAC address)
string tempMac = BTAdaptor.BluetoothAddress.ToString("X12").ToLower();
// Pattern for MAC address.
string pattern = "(.{2})(.{2})(.{2})(.{2})(.{2})(.{2})";
string replace = "$1:$2:$3:$4:$5:$6";
m_strBTAdapterMAC = Regex.Replace(tempMac, pattern, replace);
Then when the device is added/updated/removed by the watcher event, check it:
// If device is not paired with the currently used BT adapter.
if (deviceInfo.Id.Contains(m_strBTAdapterMAC) == false)
{
// Device paired with old dongle, dont want to show the user.
return;
}
If anyone ever figures out how to make the device watcher just not give old devices, please let me know, its probably a better solution.
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!
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
So I am trying to connect a bluetooth speakers from a script. I am using 32feet.net and I have successfully found the device but it doesn't work when I try to pair and connect to it.
This is the code im using to pair to device, this always fails not sure why:
private static void connected(BluetoothDeviceInfo[] dev)
{
// dev[foundIndex];
bool paired=false;
paired = BluetoothSecurity.PairRequest(dev[foundIndex].DeviceAddress, "1166");
if (paired)
Console.WriteLine("Passed, Device is connected.");
else
Console.WriteLine("Failed....");
}
Here is the code called after connected to actually connect to the device: bc is my bluetooth client var.
bc.BeginConnect(devInfo[foundIndex].DeviceAddress, BluetoothService.SerialPort, new AsyncCallback(Connect), devInfo[foundIndex]);
private static void Connect(IAsyncResult result)
{
if (result.IsCompleted)
{
Console.Write("Connected... ");
}
}
Any help would be appreciated. I am new to 32feet.net so i dont know much about this, i tried following code online to get where im at.
Try BluetoothDeviceInfo.SetServiceState. That will ask Windows to connect to the audio service on the device -- hopefully that'll do the job.
See https://32feet.codeplex.com/wikipage?title=Connecting%20to%20Bluetooth%20Services
Sometimes we don’t want our application to itself send data to/from a remote service but we want instead the local operating system to do so. This is the case for keyboard/mouse/etc with HID, networking with DUN/NAP/PAN/etc, Headset/Handsfree etc.
and then
The short answer in this case is to use BluetoothDeviceInfo.SetServiceState. This is the API equivalent to manually checking the respective checkbox on the “Services” tab of the Device dialog in Bluetooth Control panel.
Also, in these days of Secure Simple Pairing, using PairRequest is fine only if all peer devices will use old style PIN code authentication, otherwise instantiate a BluetoothWin32Authentication and then do the connect (here indirectly via SetServiceState) and handle the authentication in the authentication callback.
I can't seem to find this anywhere.
I want to build an Audio Endpoint device that plugs into the Windows Phone Headphone Jack.
I know I need to start with what the phone is capable of receiving and detecting.
Ultimately I would like to use already in existence libraries however I have no heartache about writing my own.
My problem is I can't find any examples of how people access the Audio input on the phone outside of the built in microphone.
Is there a library for this?
You can detect when a headset is plugged in using the VOIP capabilities in Windows Phone 8.
First in the WMAppManifest.xml file, you need to enable ID_CAP_VOIP and ID_CAP_AUDIOROUTING
Then in the App, you need to capture the event
AudioRoutingManager.GetDefault().AudioEndpointChanged += AudioEndpointChanged;
public void AudioEndpointChanged(AudioRoutingManager sender, object args)
{
var AudioEndPoint = sender.GetAudioEndpoint();
switch (AudioEndPoint)
{
case AudioRoutingEndpoint.WiredHeadset:
MessageBox.Show("Headset connected");
break;
}
}
This will enumerate from this list (no custom endpoints allowed)
http://msdn.microsoft.com/en-us/library/windowsphone/develop/windows.phone.media.devices.audioroutingendpoint(v=vs.105).aspx
Sorry, but I can only answer the first part of your question about detecting the device, I'm not familiar with how the hardware device interfaces with the headphone jack to answer the rest.