/// <summary> /// Get a Dictionary of attributes from the scanner given a List of attribute IDs. /// </summary> /// <param name="ids">Attribute ID list</param> /// <returns> /// Dictionary of ScannerAttribute objects holding identification info and the value of their corrisponding /// attribute. Keyed by id. /// </returns> protected IDictionary <ushort, ScannerAttribute> GetAttributes(IEnumerable <ushort> ids) { var xml = string.Format(_getAttributesXml, string.Join(",", ids.Select(n => n.ToString()).ToArray())); string outXml = null; int status; _scannerDriver.ExecCommand((int)ScannerCommand.AttrGet, ref xml, out outXml, out status); var s = (StatusCode)status; if (s != StatusCode.Success) { throw new ScannerException(s); } var retval = new Dictionary <ushort, ScannerAttribute>(); var doc = XDocument.Parse(outXml); var attributes = doc.Descendants("attribute"); foreach (var xmlAttribute in attributes) { var id = ushort.Parse(xmlAttribute.Descendants("id").Single().Value); var name = xmlAttribute.Descendants("name").Single().Value; var dataType = (DataType)xmlAttribute.Descendants("datatype").Single().Value[0]; var permission = xmlAttribute.Descendants("permission").Single().Value[0]; var stringValue = xmlAttribute.Descendants("value").Single().Value; var value = ValueConverters.StringToActualType(dataType, stringValue); retval.Add(id, new ScannerAttribute { Id = id, Name = name, DataType = dataType, Permission = permission, Value = value }); } return(retval); }
/// <summary> /// Get an attribute from the scanner given it's ID. /// </summary> /// <param name="id">Attribute ID</param> /// <returns>ScannerAttribute object holding identification info and the value of the attribute.</returns> protected ScannerAttribute GetAttribute(ushort id) { var xml = string.Format(_getAttributesXml, id); string outXml; int status; _scannerDriver.ExecCommand((int)ScannerCommand.AttrGet, ref xml, out outXml, out status); var s = (StatusCode)status; if (s != StatusCode.Success) { throw new ScannerException(s); } if (outXml == null) { return(null); } var doc = XDocument.Parse(outXml); var xmlAttribute = doc.Descendants("attribute").Single(); var name = xmlAttribute.Descendants("name").Single().Value; var dataType = (DataType)xmlAttribute.Descendants("datatype").Single().Value[0]; var permission = xmlAttribute.Descendants("permission").Single().Value[0]; var stringValue = xmlAttribute.Descendants("value").Single().Value; var value = ValueConverters.StringToActualType(dataType, stringValue); var retval = new ScannerAttribute { Id = id, Name = name, DataType = dataType, Permission = permission, Value = value }; return(retval); }