예제 #1
0
        /// <summary>
        /// Creates an IDevice from this device definition.
        /// </summary>
        /// <returns>The device.</returns>
        /// <exception cref="ArgumentException">If the IDevice could not be created with the given arguments.</exception>
        /// <param name="serialNumber">Serial number.</param>
        /// <param name="connection">Connection.</param>
        /// <param name="protocol">Protocol.</param>
        public IDevice CreateDevice(IION ion, ISerialNumber serialNumber, IConnection connection, IProtocol protocol)
        {
            if (!(serialNumber is GaugeSerialNumber))
            {
                /////should not throw exeptions
                //throw new ArgumentException("Cannot create device: expected GaugeSerialNumber, received: " + serialNumber.GetType().Name);
                return(null);
            }

            if (!(protocol is IGaugeProtocol))
            {
                /////should not throw exeptions
                //throw new ArgumentException("Cannot create device: expected an IGaugeProtocol, received: " + protocol.GetType().Name);
                return(null);
            }

            var ret = new GaugeDevice(serialNumber as GaugeSerialNumber, connection, protocol as IGaugeProtocol);
            var s   = new List <GaugeDeviceSensor>();

            int i = 0;

            foreach (var sensorDefinition in sensorDefinitions)
            {
                var sensor = new GaugeDeviceSensor(ion, ret, i++, sensorDefinition.sensorType, sensorDefinition.isRelative);
                sensor.removable      = sensorDefinition.isRemovable;
                sensor.minMeasurement = sensorDefinition.minimumMeasurement;
                sensor.maxMeasurement = sensorDefinition.maximumMeasurement;
                sensor.SetSupportedUnits(sensorDefinition.supportedUnits.ToArray());
                s.Add(sensor);
            }

            ret.sensors = s.ToArray();

            return(ret);
        }
 public GaugeDeviceSensor(IION ion, GaugeDevice device, int index, ESensorType sensorType, bool relative = true)
     : base(sensorType, ion.preferences.units.DefaultUnitFor(sensorType).OfScalar(0.0), relative)
 {
     this.device = device;
     this.index  = index;
     this.name   = device.name;
 }