/// <summary> /// Queries for the device with the given serial number. /// </summary> /// <returns>The for using serial number async.</returns> /// <param name="serialNumber">Serial number.</param> public static Task <DeviceRow> QueryForUsingSerialNumberAsync(this IONDatabase db, ISerialNumber serialNumber) { //Log.D("DeviceDatabaseExtensions", "QueryFor: " + serialNumber); try { var serial = serialNumber.ToString(); if (db.Table <DeviceRow>().Count() > 0) { return(Task.FromResult(db.Table <DeviceRow>().Where(x => x.serialNumber == serial).First())); } else { return(Task.FromResult(default(DeviceRow))); } } catch (Exception e) { Log.E(typeof(DeviceDatabaseExtensions).Name, "Failed to query for using serial number.", e); return(Task.FromResult(default(DeviceRow))); } }
/// <summary> /// </summary> /// <param name="ion">Ion.</param> public static DeviceSensorGaugeReportData QueryFromSessionOrThrow(IION ion, long sessionId, ISerialNumber serialNumber, int index) { var def = ion.deviceManager.deviceFactory.GetDeviceDefinition(serialNumber); if (def == null) { throw new Exception("Cannot query sensor data for " + serialNumber + ": failed to find device definition"); } var gaugeDef = def as GaugeDeviceDefinition; if (gaugeDef == null) { throw new Exception("Cannot query sensor data for " + serialNumber + ": serial number returned an invalid device definition"); } var sensorDef = gaugeDef[index]; if (sensorDef == null) { throw new Exception("Cannot query sensor data for " + serialNumber + ": serial number returned a device definition with invalid sensor definition"); } var table = ion.database.Table <SensorMeasurementRow>(); var rawSerialNumber = serialNumber.ToString(); var rows = table.Where(smr => smr.frn_SID == sessionId && smr.serialNumber.Equals(rawSerialNumber) && smr.sensorIndex == index) .OrderBy(smr => smr.recordedDate); var measurements = new List <MeasurementData>(); foreach (var row in rows) { measurements.Add(new MeasurementData() { measurement = sensorDef.minimumMeasurement.unit.standardUnit.OfScalar(row.measurement), recordedDate = row.recordedDate, }); } return(null); }
// Implemented from IDeviceManager public IDevice CreateDevice(ISerialNumber serialNumber, string connectionAddress, EProtocolVersion protocol) { var p = Protocol.FindProtocolFromVersion(protocol); return(deviceFactory.GetDeviceDefinition(serialNumber).CreateDevice(ion, serialNumber, new RemoteConnection(serialNumber.ToString()), p)); }