/// <summary> /// /// </summary> /// <param name="coreScannerService"></param> /// <param name="scannerId"></param> /// <param name="mode"></param> public static void SetCaptureMode( this ICoreScannerService scannerService, Int32 scannerId, CaptureMode mode) { Contract.Requires(scannerService != null); Contract.Requires(scannerId > 0); XDocument inXml = new XDocument( new XElement("inArgs", new XElement("scannerId", scannerId))); switch (mode) { case CaptureMode.Barcode: scannerService .ExecuteCommand(OperationCode.DeviceCaptureBarcode, inXml.ToString()); break; case CaptureMode.Image: scannerService .ExecuteCommand(OperationCode.DeviceCaptureImage, inXml.ToString()); break; case CaptureMode.Video: scannerService .ExecuteCommand(OperationCode.DeviceCaptureVideo, inXml.ToString()); break; default: throw new ArgumentOutOfRangeException("mode"); } }
/// <summary> /// Reboots the specified scanner. /// </summary> /// <param name="coreScannerService"></param> /// <param name="scannerId"></param> /// <remarks> /// Direct execution of this command on a Bluetooth scanner does not result in a reboot. /// This command needs to be sent to the scanner's associated cradle to reboot the /// Bluetooth scanner. /// </remarks> public static void RebootScanner( this ICoreScannerService scannerService, Int32 scannerId) { XDocument inXml = new XDocument( new XElement("inArgs", new XElement("scannerID", scannerId))); scannerService .ExecuteCommand(OperationCode.RebootScanner, inXml.ToString()); }
/// <summary> /// Flush MacroPDF on the specified scanner. /// </summary> /// <param name="scannerService"></param> /// <param name="scannerId"></param> public static void FlushMacroPdf( this ICoreScannerService scannerService, Int32 scannerId) { XDocument inXml = new XDocument( new XElement("inArgs", new XElement("scannerId", scannerId))); scannerService .ExecuteCommand(OperationCode.FlushMacroPdf, inXml.ToString()); }
/// <summary> /// Sets all parameters to default values on the specified scanner. /// </summary> /// <param name="scannerService"></param> /// <param name="scannerId"></param> public static void SetParametersToDefault( this ICoreScannerService scannerService, Int32 scannerId) { XDocument inXml = new XDocument( new XElement("inArgs", new XElement("scannerId", scannerId))); scannerService .ExecuteCommand(OperationCode.SetParameterDefaults, inXml.ToString()); }
/// <summary> /// Releases the specified device. /// </summary> /// <param name="service"></param> /// <param name="scannerId"></param> public static void ReleaseDevice( this ICoreScannerService scannerService, Int32 scannerId) { Contract.Requires(scannerService != null); Contract.Requires(scannerId > 0); XDocument inXml = new XDocument( new XElement("inArgs", new XElement("scannerId", scannerId))); scannerService .ExecuteCommand(OperationCode.ReleaseDevice, inXml.ToString()); }
/// <summary> /// Get the topology of devices that are connected to the calling system. /// </summary> /// <param name="scannerService"></param> /// <returns></returns> public static IEnumerable <ScannerInfo> GetDeviceTopology( this ICoreScannerService scannerService) { Contract.Requires(scannerService != null); XDocument inXml = new XDocument( new XElement("inArgs", String.Empty)); return(scannerService .ExecuteCommand(OperationCode.GetDeviceTopology, inXml.ToString()) .ParseXmlDocument() .Elements("outArgs") .Elements("arg-xml") .Elements("scanners") .Elements("scanner") .Select(scanner => ScannerInfo.Parse(scanner.ToString()))); }
/// <summary> /// Unregisters the specified CoreScanner events. /// </summary> /// <param name="scannerService"></param> /// <param name="events"></param> /// <returns></returns> public static void UnregisterForEvents( this ICoreScannerService scannerService, EventType events) { Contract.Requires(scannerService != null); List <EventType> eventCodes = events .GetFlags <EventType>() .ToList(); XDocument inXml = new XDocument( new XElement("inArgs", new XElement("cmdArgs", new XElement("arg-int", eventCodes.Count), new XElement("arg-int", eventCodes.Cast <Int32>().StringJoin(","))))); scannerService .ExecuteCommand(OperationCode.UnregisterForEvents, inXml.ToString()); }
/// <summary> /// Pulls or releases the trigger on the specified scanner. /// </summary> /// <param name="service"></param> /// <param name="scannerId"></param> /// <param name="pull"></param> public static void ToggleTrigger( this ICoreScannerService scannerService, Int32 scannerId, Boolean pull) { XDocument inXml = new XDocument( new XElement("inArgs", new XElement("scannerId", scannerId))); if (pull == true) { scannerService.ExecuteCommand(OperationCode.DevicePullTrigger, inXml.ToString()); } else { scannerService.ExecuteCommand(OperationCode.DeviceReleaseTrigger, inXml.ToString()); } }
/// <summary> /// Turns the aim on or off on the specified scanner. /// </summary> /// <param name="service"></param> /// <param name="scannerId"></param> /// <param name="on"></param> public static void ToggleAim( this ICoreScannerService scannerService, Int32 scannerId, Boolean on) { XDocument inXml = new XDocument( new XElement("inArgs", new XElement("scannerId", scannerId))); if (on == true) { scannerService.ExecuteCommand(OperationCode.AimOn, inXml.ToString()); } else { scannerService.ExecuteCommand(OperationCode.AimOff, inXml.ToString()); } }
/// <summary> /// Enables or disables scanning on the specified scanner. /// </summary> /// <param name="service"></param> /// <param name="scannerId"></param> /// <param name="pull"></param> public static void ToggleScan( this ICoreScannerService scannerService, Int32 scannerId, Boolean enable) { XDocument inXml = new XDocument( new XElement("inArgs", new XElement("scannerId", scannerId))); if (enable == true) { scannerService.ExecuteCommand(OperationCode.ScanEnable, inXml.ToString()); } else { scannerService.ExecuteCommand(OperationCode.ScanDisable, inXml.ToString()); } }
/// <summary> /// Gets the specified attribute values for the specified scanner. /// </summary> /// <param name="scannerService"></param> /// <param name="scannerId"></param> /// <param name="attributes"></param> /// <returns></returns> public static IObservable <IReadOnlyCollection <AttributeInfo> > GetAttributeValuesAsync( this ICoreScannerService scannerService, Int32 scannerId, params AttributeId[] attributes) { Contract.Requires(scannerService != null); Contract.Requires(scannerId > 0); Contract.Requires(attributes.Length > 0); XDocument inXml = new XDocument( new XElement("inArgs", new XElement("scannerID", scannerId), new XElement("cmdArgs", new XElement("arg-xml", new XElement("attrib_list", attributes.Cast <Int32>().ToArray()))))); IObservable <IReadOnlyCollection <AttributeInfo> > resultAsync = scannerService .WhenCommandResponded() .Do(e => e.Status.ThrowIfError()) .SelectMany(e => e.OutXml .ParseXmlDocument() .Elements("outArgs")) .Where(outXml => outXml .Elements("scannerID") .All(e => e.Value.ToInt32().Equals(scannerId))) .SelectMany(outXml => outXml .Elements("arg-xml") .Elements("response")) .Where(response => response .Elements("opcode") .Select(e => (OperationCode)e.Value.ToInt32()) .All(opCode => opCode.Equals(OperationCode.GetAttribute))) .FirstAsync() .RunAsync(CancellationToken.None) .Select(outXml => outXml .Elements("attrib_list") .Elements("attribute") .Select(e => AttributeInfo.Parse(e.ToString())) .ToList() .AsReadOnly()); scannerService .ExecuteCommandAsync(OperationCode.GetAttribute, inXml.ToString()); return(resultAsync); }
/// <summary> /// Gets the version of CoreScanner Driver. /// </summary> /// <param name="coreScannerService"></param> /// <returns></returns> /// <remarks> /// Major.Minor.Revision /// </remarks> public static String GetVersion( this ICoreScannerService coreScannerService) { Contract.Requires(coreScannerService != null); XDocument inXml = new XDocument( new XElement("inArgs", String.Empty)); return(coreScannerService .ExecuteCommand(OperationCode.GetVersion, inXml.ToString()) .ParseXmlDocument() .Elements("outArgs") .SelectMany(outArgs => outArgs .Elements("arg-xml")) .SelectMany(argXml => argXml .Elements("arg-string")) .Select(e => e.Value) .FirstOrDefault()); }
/// <summary> /// Gets the next attribute value of the specified attribute for the specified scanner. /// </summary> /// <param name="scannerService"></param> /// <param name="scannerId"></param> /// <param name="attribute"></param> /// <returns></returns> /// <remarks> /// Can be used to create an asynchronous scanner attribute iterator. /// </remarks> public static IObservable <AttributeInfo> GetNextAttributeValueAsync( this ICoreScannerService scannerService, Int32 scannerId, AttributeId attributeId) { Contract.Requires(scannerService != null); Contract.Requires(scannerId > 0); XDocument inXml = new XDocument( new XElement("inArgs", new XElement("scannerID", scannerId), new XElement("cmdArgs", new XElement("arg-xml", new XElement("attrib_list", (Int32)attributeId))))); IObservable <AttributeInfo> resultAsync = scannerService .WhenCommandResponded() .Do(e => e.Status.ThrowIfError()) .SelectMany(e => e.OutXml .ParseXmlDocument() .Elements("outArgs")) .Where(outArgs => outArgs .Elements("scannerID") .All(e => e.Value.ToInt32().Equals(scannerId))) .SelectMany(outArgs => outArgs .Elements("arg-xml") .Elements("response")) .Where(response => response .Elements("opcode") .Select(opCode => (OperationCode)opCode.Value.ToInt32()) .All(opCode => opCode.Equals(OperationCode.GetNextAttribute))) .FirstAsync() .RunAsync(CancellationToken.None) .SelectMany(response => response .Elements("attrib_list") .Elements("attribute") .Select(attribute => AttributeInfo.Parse(attribute.ToString()))); scannerService .ExecuteCommandAsync(OperationCode.GetNextAttribute, inXml.ToString()); return(resultAsync); }
/// <summary> /// Sets the specified parameters on the specified scanner persistently. /// </summary> /// <param name="scannerService"></param> /// <param name="scannerId"></param> /// <param name="attributes"></param> /// <remarks> /// Parameters sets using this command are persistent over power cycles. /// </remarks> public static void StoreParameters( this ICoreScannerService scannerService, Int32 scannerId, params AttributeInfo[] attributes) { XDocument inXml = new XDocument( new XElement("inArgs", new XElement("scannerID", scannerId), new XElement("cmdArgs", new XElement("arg-xml", new XElement("attrib_list", attributes .Select(attribute => new XElement("attribute", new XElement("id", (Int32)attribute.Id), new XElement("datatype", attribute.Type.ToStringCode()), new XElement("value", attribute.Value))) .ToArray()))))); scannerService .ExecuteCommand(OperationCode.SetParameterPersistence, inXml.ToString()); }
/// <summary> /// /// </summary> /// <param name="coreScannerService"></param> /// <param name="mode"></param> /// <param name="scannerId"></param> /// <param name="isSilent"></param> /// <param name="isPermanent"></param> public static void SetHostMode( this ICoreScannerService scannerService, HostMode mode, Int32 scannerId, Boolean isSilent, Boolean isPermanent) { Contract.Requires(scannerService != null); Contract.Requires(scannerId > 0); XDocument inXml = new XDocument( new XElement("inArgs", new XElement("scannerID", scannerId), new XElement("cmdArgs", new XElement("arg-string", mode.GetStringCode()), new XElement("arg-bool", isSilent), new XElement("arg-bool", isPermanent)))); scannerService .ExecuteCommand(OperationCode.DeviceSwitchHostMode, inXml.ToString()); }
/// <summary> /// Stores the values of attributes for the specified scanner. Attributes set using this /// command are persistent over power down and power up cycles. /// </summary> /// <typeparam name="TValue"></typeparam> /// <param name="scannerService"></param> /// <param name="scannerId"></param> /// <param name="attribute"></param> /// <param name="value"></param> public static void StoreAttributeValue( this ICoreScannerService scannerService, Int32 scannerId, AttributeInfo attribute) { Contract.Requires(scannerService != null); Contract.Requires(scannerId > 0); XDocument inXml = new XDocument( new XElement("inArgs", new XElement("scannerID", scannerId), new XElement("cmdArgs", new XElement("arg-xml", new XElement("attrib_list", new XElement("attribute", new XElement("id", (Int32)attribute.Id), new XElement("datatype", attribute.Type.ToStringCode()), new XElement("value", attribute.Value))))))); scannerService .ExecuteCommand(OperationCode.StoreAttribute, inXml.ToString()); }