Пример #1
0
        private int _ledState         = 0;       // LED state

        #region DeviceBase Members

        /// <summary>
        /// Represents main device thread.
        /// </summary>
        /// <param name="token">Thread cancellation token.</param>
        public override void Main(CancellationToken token)
        {
            // send the notification about initial LED state
            ServiceChannel.SendEquipmentNotification(LED_CODE, new LedNotification(_ledState));

            // do nothing in the main thread
        }
Пример #2
0
        public DeviceCommandResult UpdateLedState(UpdateLedStateCommand command, CancellationToken token)
        {
            // validate input parameters
            if (command.Equipment != LED_CODE)
            {
                return(new DeviceCommandResult("Failed", "Invalid equipment parameter: " + command.Equipment));
            }
            if (command.State == null || !new[] { 0, 1 }.Contains(command.State.Value))
            {
                return(new DeviceCommandResult("Failed", "Invalid state parameter: " + command.State));
            }

            // switch the LED state
            Console.WriteLine("Received UpdateLedState command, setting LED state to " + command.State);
            _ledState = command.State.Value;

            // send the notification about LED state update
            ServiceChannel.SendEquipmentNotification(command.Equipment, new LedNotification(command.State.Value));

            // return the Completed status
            return(new DeviceCommandResult("Completed"));
        }