101 lines
3.5 KiB
C#
101 lines
3.5 KiB
C#
using CoreScanner;
|
|
using SafeBagDE70.Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Shapes;
|
|
using System.Windows.Threading;
|
|
using System.Xml;
|
|
|
|
namespace SafeBagDE70
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for QRCodeWindow.xaml
|
|
/// </summary>
|
|
public partial class QRCodeZebraWindow : HandyControl.Controls.Window
|
|
{
|
|
|
|
public string QRCodeContent = null;
|
|
public CCoreScannerClass cCoreScannerClass;
|
|
public QRCodeZebraWindow()
|
|
{
|
|
InitializeComponent();
|
|
Init();
|
|
}
|
|
public void Init()
|
|
{
|
|
try
|
|
{
|
|
// Instantiate CoreScanner Class
|
|
cCoreScannerClass = new CCoreScannerClass();
|
|
|
|
// Call Open API
|
|
short[] scannerTypes = new short[1]; // Scanner Types you are interested in
|
|
scannerTypes[0] = 1; // 1 for all scanner types
|
|
short numberOfScannerTypes = 1; // Size of the scannerTypes array
|
|
int status; // Extended API return code
|
|
|
|
cCoreScannerClass.Open(0, scannerTypes, numberOfScannerTypes, out status);
|
|
|
|
// Subscribe for barcode events in cCoreScannerClass
|
|
cCoreScannerClass.BarcodeEvent += new _ICoreScannerEvents_BarcodeEventEventHandler(OnBarcodeEvent);
|
|
|
|
// Let's subscribe for events
|
|
int opcode = 1001; // Method for Subscribe events
|
|
string outXML; // XML Output
|
|
string inXML = "<inArgs>" +
|
|
"<cmdArgs>" +
|
|
"<arg-int>1</arg-int>" + // Number of events you want to subscribe
|
|
"<arg-int>1</arg-int>" + // Comma separated event IDs
|
|
"</cmdArgs>" +
|
|
"</inArgs>";
|
|
|
|
cCoreScannerClass.ExecCommand(opcode, ref inXML, out outXML, out status);
|
|
}
|
|
catch (Exception exp)
|
|
{
|
|
Console.WriteLine("Something wrong please check... " + exp.Message);
|
|
}
|
|
}
|
|
private void OnBarcodeEvent(short eventType, ref string pscanData)
|
|
{
|
|
string xmlString = pscanData;
|
|
XmlDocument xmlDoc = new XmlDocument();
|
|
xmlDoc.LoadXml(xmlString);
|
|
|
|
XmlNode rawDataNode = xmlDoc.SelectSingleNode("//datalabel");
|
|
string rawDataHex = rawDataNode.InnerText.Trim();
|
|
|
|
QRCodeContent = HexStringToString(rawDataHex);
|
|
this.Dispatcher.Invoke(() =>
|
|
{
|
|
cCoreScannerClass.BarcodeEvent -= new _ICoreScannerEvents_BarcodeEventEventHandler(OnBarcodeEvent);
|
|
DialogResult = true;
|
|
this.Close();
|
|
});
|
|
}
|
|
|
|
static string HexStringToString(string hexString)
|
|
{
|
|
string[] hexValues = hexString.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
|
|
byte[] bytes = new byte[hexValues.Length];
|
|
|
|
for (int i = 0; i < hexValues.Length; i++)
|
|
{
|
|
bytes[i] = Convert.ToByte(hexValues[i], 16);
|
|
}
|
|
return Encoding.ASCII.GetString(bytes);
|
|
}
|
|
|
|
}
|
|
}
|