示例#1
0
        public async Task <Result> ConnectDeviceAsync(IDevice device, IDeviceConnection deviceConnection)
        {
            var res = await deviceConnection.TryOpenConnectionAsync(device.DeviceLogger);

            if (device.DeviceLogger == null)
            {
                device.DeviceLogger = _loggerGetFunc();
            }
            if (res.IsSuccess)
            {
                if (device.DeviceConnection != deviceConnection)
                {
                    device?.DeviceConnection?.Dispose();
                }
            }
            //инициализация подключения (добавление логгеров, датапровайдеров)
            device.InitializeConnection(deviceConnection);
            ConnectableItemChanged?.Invoke(new ConnectableItemChangingContext(device, ItemModifyingTypeEnum.Connected));
            if (res.IsSuccess)
            {
                if (device.DeviceConnection != deviceConnection)
                {
                    device.DeviceConnection.Dispose();
                }
                return(Result.Create(true));
            }

            return(res);
        }
 public Device(ILogger loggerIn, IDeviceConnection deviceConnectionIn, IDeviceCommunication deviceCommunicationIn)
 {
     logger              = loggerIn;
     deviceConnection    = deviceConnectionIn;
     deviceCommunication = deviceCommunicationIn;
     deviceConnection.SetCallback(GetHost, SetDeviceState, OnReceiveMessage);
     deviceState      = DeviceState.NotConnected;
     discoveredDevice = new DiscoveredDevice();
 }
示例#3
0
 public SmsService(IDeviceConnection connection)
 {
     _log        = LogManager.GetLogger(this.GetType());
     ChinaMobile = true;
     if (connection == null)
     {
         throw new ArgumentNullException("connection");
     }
     _log.Debug("connect is ok.");
     _deviceConnectin = connection;
     _deviceConnectin.ReceivedEvent += DeviceConnectinReceivedEvent;
 }
示例#4
0
        public void InitializeConnection(IDeviceConnection deviceConnection)
        {
            DeviceConnection = deviceConnection;
            StaticContainer.Container.Resolve <ILogService>().AddLogger(DeviceLogger, Name);

            if (deviceConnection is IDataProvider dataProvider)
            {
                DataProvider = Result <IDataProvider> .Create(dataProvider, true);
            }
            else
            {
                DataProvider = Result <IDataProvider> .Create(false);
            }
        }
 public Device(IDeviceConnection deviceConnectionIn, IDeviceCommunication deviceCommunicationIn)
 {
     deviceConnection = deviceConnectionIn;
     deviceConnection.SetCallback(GetHost, SetDeviceState, OnReceiveMessage);
     deviceCommunication = deviceCommunicationIn;
     deviceCommunication.SetCallback(SetDeviceState, OnVolumeUpdate, deviceConnection.SendMessage, GetDeviceState, IsConnected, deviceConnection.IsConnected, GetHost);
     deviceState   = DeviceState.NotConnected;
     volumeSetting = new Volume
     {
         controlType  = "attenuation",
         level        = 0.0f,
         muted        = false,
         stepInterval = 0.05f
     };
 }
 public Device(ILogger loggerIn, IDeviceConnection deviceConnectionIn, IDeviceCommunication deviceCommunicationIn)
 {
     logger              = loggerIn;
     deviceConnection    = deviceConnectionIn;
     deviceCommunication = deviceCommunicationIn;
     deviceConnection.SetCallback(GetHost, GetPort, SetDeviceState, OnReceiveMessage);
     deviceState      = DeviceState.NotConnected;
     discoveredDevice = new DiscoveredDevice();
     volumeSetting    = new Volume
     {
         controlType  = "attenuation",
         level        = 0.0f,
         muted        = false,
         stepInterval = 0.05f
     };
 }
示例#7
0
 /// <summary>
 /// Construct a new VoltageSensor.
 /// </summary>
 /// <param name="read">Characteristic, which provides read-access to the current battery state</param>
 public VoltageSensor(IDeviceConnection conn)
 {
     _conn = conn;
 }
示例#8
0
 /// <summary>
 /// Construct a new EarableName.
 /// </summary>
 /// <param name="read">Characteristic which allows read-access to the name</param>
 /// <param name="write">Characteristic which allows write-access to the name</param>
 public EarableName(IDeviceConnection conn)
 {
     _conn = conn;
 }
示例#9
0
 public SmsService(IDeviceConnection connection, string mobile)
     : this(connection)
 {
     _serviceCenterNumber = mobile;
     _log = LogManager.GetLogger(this.GetType());
 }
示例#10
0
 /// <summary>
 /// Construct a new MotionSensor.
 /// </summary>
 /// <param name="connection">BLE connection handle</param>
 public MotionSensor(IDeviceConnection connection)
 {
     _connection  = connection;
     _imuEnabled  = false;
     SamplingRate = 50;
 }