Example #1
0
        private bool IsDeviceShouldBeStopped(NandakaDevice device, DeviceError newError)
        {
            int errorCount = device.ErrorCounter[newError];

            device.ErrorCounter[newError] = errorCount + 1;

            return(errorCount > _maxErrorInRowCount);
        }
Example #2
0
        public static void PowerOff()
        {
            DeviceError res = (DeviceError)Interop.Device.DevicePowerPowerOff();

            if (res != DeviceError.None)
            {
                throw DeviceExceptionFactory.CreateException(res, "unable to power off the device.");
            }
        }
Example #3
0
        protected void RaiseShirtErrorEvent(DeviceError shirtError)
        {
            var handler = ShirtReceivedError;

            if (handler != null)
            {
                handler(shirtError);
            }
        }
Example #4
0
        protected void RaisePantsErrorEvent(DeviceError pantsError)
        {
            var handler = PantsReceivedError;

            if (handler != null)
            {
                handler(pantsError);
            }
        }
Example #5
0
        public static void Reboot(string reason)
        {
            DeviceError res = (DeviceError)Interop.Device.DevicePowerReboot(reason);

            if (res != DeviceError.None)
            {
                throw DeviceExceptionFactory.CreateException(res, "unable to reboot the device.");
            }
        }
Example #6
0
        /// <summary>
        /// Stops the LED that is located at the front of the device.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <exception cref="UnauthorizedAccessException">If the privilege is not set.</exception>
        /// <exception cref="InvalidOperationException">In case of any system error.</exception>
        /// <exception cref="NotSupportedException">In case the device does not support this behavior.</exception>
        /// <example>
        /// <code>
        ///     try
        ///     {
        ///         Led.Play(500, 200, Color.FromRgba(255, 255, 255, 1));
        ///         //wait for a while and stop...
        ///         Led.Stop();
        ///     }
        ///     Catch(Exception e)
        ///     {
        ///     }
        /// </code>
        /// </example>

        public static void Stop()
        {
            DeviceError res = (DeviceError)Interop.Device.DeviceLedStopCustom();

            if (res != DeviceError.None)
            {
                throw DeviceExceptionFactory.CreateException(res, "failed to stop Led.");
            }
        }
Example #7
0
        public static void ReleaseCpuLock()
        {
            DeviceError res = (DeviceError)Interop.Device.DevicePowerReleaseLock(Interop.Device.PowerLock.Cpu);

            if (res != DeviceError.None)
            {
                throw DeviceExceptionFactory.CreateException(res, "unable to release power lock.");
            }
        }
Example #8
0
        public static void RequestCpuLock(int timeout)
        {
            DeviceError res = (DeviceError)Interop.Device.DevicePowerRequestLock(Interop.Device.PowerLock.Cpu, timeout);

            if (res != DeviceError.None)
            {
                throw DeviceExceptionFactory.CreateException(res, "unable to acquire power lock.");
            }
        }
Example #9
0
        public void OnError(DeviceError error)
        {
            EventHandler <DeviceError> eventHandler = this.OnFailed;

            if (eventHandler != null)
            {
                eventHandler(this, error);
            }
        }
Example #10
0
        /* Public */

        public Controller(SerialPortStream port)
        {
            Buffer                    = new StringBuilder(16);
            TerminalQueue             = new BlockingCollectionQueue();
            DataQueue                 = new BlockingCollectionQueue();
            Port                      = port;
            Port.DataReceived        += Port_DataReceived;
            DataErrorEventThreadStart = (object x) => { DataError?.Invoke(this, (DataErrorEventArgs)x); };
            DeviceErrorThreadStart    = (object x) => { DeviceError?.Invoke(this, (TerminalEventArgs)x); };
        }
Example #11
0
        /// <summary>
        /// Transmits the IR command.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <param name="carrierFreequency">
        /// The carrier frequency to transmit the IR command (Hertz).
        /// </param>
        /// <param name="pattern">
        /// The IR command list of type integer.
        /// </param>
        /// <exception cref="ArgumentException"> When an invalid parameter value is set.</exception>
        /// <exception cref="UnauthorizedAccessException">If the privilege is not set.</exception>
        /// <exception cref="InvalidOperationException">In case of any system error.</exception>
        /// <exception cref="NotSupportedException">In case the device does not support this behavior.</exception>
        /// <example>
        /// <code>
        ///    try
        ///    {
        ///       List&lt;int&gt; pattern = new List&lt;int&gt;();
        ///       pattern.Add(10);
        ///       pattern.Add(50);
        ///       IR.Transmit(60657, pattern);
        ///    }
        ///    catch(Exception e)
        ///    {
        ///    }
        /// </code>
        /// </example>
        public static void Transmit(int carrierFreequency, IList <int> pattern)
        {
            int[]       patternArray = pattern.ToArray();
            DeviceError res          = (DeviceError)Interop.Device.DeviceIRTransmit(carrierFreequency, patternArray, pattern.Count());

            if (res != DeviceError.None)
            {
                throw DeviceExceptionFactory.CreateException(res, "unable to trasmit IR command.");
            }
        }
Example #12
0
        /// <summary>
        /// Plays the LED that is located at the front of the device.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <param name="on">Turn on time in milliseconds.</param>
        /// <param name="off">Turn off time in milliseconds.</param>
        /// <param name="color">
        /// The Color value
        /// The first byte means opaque and the other 3 bytes are the RGB values.
        /// </param>
        /// <exception cref="ArgumentException">When an invalid parameter value is set.</exception>
        /// <exception cref="UnauthorizedAccessException">If the privilege is not set.</exception>
        /// <exception cref="InvalidOperationException">In case of any system error.</exception>
        /// <exception cref="NotSupportedException">In case the device does not support this behavior.</exception>
        /// <example>
        /// <code>
        ///     try
        ///     {
        ///         Led.Play(500, 200, Color.FromRgba(255, 255, 255, 1));
        ///     }
        ///     Catch(Exception e)
        ///     {
        ///     }
        /// </code>
        /// </example>
        public static void Play(int on, int off, Color color)
        {
            //looks like only blink option is supported. So hard coded to default blink option.
            DeviceError res = (DeviceError)Interop.Device.DeviceLedPlayCustom(on, off, Convert.ToUInt32(color.GetArgb()), 1);

            if (res != DeviceError.None)
            {
                throw DeviceExceptionFactory.CreateException(res, "failed to play Led.");
            }
        }
Example #13
0
 /// <summary>
 /// Stops all the vibration effects which are being played.
 /// This function can be used to stop all the effects started by Vibrate().
 /// </summary>
 /// <since_tizen> 3 </since_tizen>
 /// <feature>
 /// http://tizen.org/feature/feedback.vibration
 /// </feature>
 /// <exception cref="ArgumentException"> In case an invalid vibrator instance is used.</exception>
 /// <exception cref="UnauthorizedAccessException">If the privilege is not set.</exception>
 /// <exception cref="InvalidOperationException">In case of any system error.</exception>
 /// <exception cref="NotSupportedException">In case the device does not support this behavior.</exception>
 /// <example>
 /// <code>
 ///     Vibrator vibrator = Vibrator.Vibrators[0];
 ///     try
 ///     {
 ///         vibrator.Stop();
 ///     }
 ///     catch(Exception e)
 ///     {
 ///     }
 /// </code>
 /// </example>
 public void Stop()
 {
     if (_hapticHandle != IntPtr.Zero)
     {
         DeviceError res = (DeviceError)Interop.Device.DeviceHapticStop(_hapticHandle, IntPtr.Zero);
         if (res != DeviceError.None)
         {
             throw DeviceExceptionFactory.CreateException(res, "unable to stop the current vibrator.");
         }
     }
 }
        private string GetNicifiedString(DeviceError deviceError)
        {
            switch (deviceError)
            {
            case DeviceError.CalibrationFailed:
                return("Please Recalibrate");

            case DeviceError.NoCalibration:
                return("Please Calibrate");

            case DeviceError.UnknownDevice:
                return("Unknown Device");
            }
            return("");
        }
Example #15
0
        private Vibrator(int id)
        {
            _vibratorId = id;
            DeviceError res = (DeviceError)Interop.Device.DeviceHapticOpen(_vibratorId, out _hapticHandle);

            if (res != DeviceError.None)
            {
                throw DeviceExceptionFactory.CreateException(res, "unable to create Vibrator for given Id");
            }
            res = (DeviceError)Interop.Device.DeviceHapticGetCount(out _maxcount);
            if (res != DeviceError.None)
            {
                Log.Warn(DeviceExceptionFactory.LogTag, "unable to get Vibrators count.");
            }
        }
Example #16
0
        /// <summary>
        /// Increase the cpu clock within timeout.
        /// </summary>
        /// <param name="type">Performance Control Type</param>
        /// <param name="timeout">Cpu clock increasing duration in milliseconds.</param>
        /// <exception cref="ArgumentException">When an invalid parameter value is set.</exception>
        /// <exception cref="InvalidOperationException">In case of any system error.</exception>
        /// <exception cref="NotSupportedException">In case the device does not support this behavior.</exception>
        /// <example>
        /// <code>
        ///     try
        ///     {
        ///         PerformanceController.Request(PerformanceControlType.AppLaunchHome, 100);
        ///     }
        ///     Catch(Exception e)
        ///     {
        ///     }
        /// </code>
        /// </example>
        public static void Request(PerformanceControlType type, int timeout)
        {
            PerformanceControlFunc func = null;

            if (!PerformanceControlFunctions.TryGetValue(type, out func))
            {
                throw new ArgumentException("Invalid Arguments");
            }

            DeviceError res = (DeviceError)func(timeout);

            if (res != DeviceError.None)
            {
                throw DeviceExceptionFactory.CreateException(res, "unable to transmit PmQos command.");
            }
        }
Example #17
0
        private static IReadOnlyList <Vibrator> GetAllVibrators()
        {
            int             count     = 0;
            List <Vibrator> vibrators = new List <Vibrator>();
            DeviceError     res       = (DeviceError)Interop.Device.DeviceHapticGetCount(out count);

            if (res != DeviceError.None)
            {
                throw DeviceExceptionFactory.CreateException(res, "unable to get Vibrators count.");
            }
            for (int i = 0; i < NumberOfVibrators; i++)
            {
                vibrators.Add(new Vibrator(i));
            }
            return(vibrators);
        }
Example #18
0
        private dynamic MakeResult(int code, DeviceError errorcode, string description)
        {
            dynamic res = new ExpandoObject();

            switch (errorcode)
            {
            case DeviceError.NO_ANSWER:
                res.code = 310;
                break;

            default:
                res.code = code;
                break;
            }

            res.description = description;
            return(res);
        }
Example #19
0
 public AnvizDevice(TcpClient socket)
 {
     DeviceStream = new AnvizStream(socket);
     DeviceStream.ReceivedPacket += (s, e) =>
     {
         if (e.ResponseCode == 0x7F)
         {
             DevicePing?.Invoke(this, null);
         }
         else
         {
             ReceivedPacket?.Invoke(this, e);
         }
     };
     DeviceStream.DeviceError += (s, e) =>
     {
         DeviceError?.Invoke(this, e);
     };
 }
Example #20
0
        public dynamic MakeResult(int code, DeviceError errorcode, string description)
        {
            dynamic result = new ExpandoObject();

            switch (errorcode)
            {
            case DeviceError.NO_ANSWER:
                result.code = 310;
                break;

            default:
                result.code = code;
                break;
            }

            result.success     = code == 0 ? true : false;
            result.description = description;

            return(result);
        }
Example #21
0
        /// <summary>
        /// Vibrates during the specified time with a constant intensity.
        /// This function can be used to start monotonous vibration for the specified time.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <param name="duration">The play duration in milliseconds.</param>
        /// <param name="feedback">The amount of the intensity variation (0 ~ 100).</param>
        /// <feature>
        /// http://tizen.org/feature/feedback.vibration
        /// </feature>
        /// <exception cref="ArgumentException"> When an invalid parameter value is set.</exception>
        /// <exception cref="UnauthorizedAccessException">If the privilege is not set.</exception>
        /// <exception cref="InvalidOperationException">In case of any system error.</exception>
        /// <exception cref="NotSupportedException">In case the device does not support this behavior.</exception>
        /// <example>
        /// <code>
        ///     Vibrator vibrator = Vibrator.Vibrators[0];
        ///     try
        ///     {
        ///         vibrator.Vibrate(2000, 70);
        ///     }
        ///     catch(Exception e)
        ///     {
        ///     }
        /// </code>
        /// </example>

        public void Vibrate(int duration, int feedback)
        {
            IntPtr      effect;
            DeviceError res = DeviceError.None;

            if (_hapticHandle == IntPtr.Zero)
            {
                res = (DeviceError)Interop.Device.DeviceHapticOpen(_vibratorId, out _hapticHandle);
                if (res != DeviceError.None)
                {
                    throw DeviceExceptionFactory.CreateException(res, "unable to get vibrator.");
                }
            }

            res = (DeviceError)Interop.Device.DeviceHapticVibrate(_hapticHandle, duration, feedback, out effect);
            if (res != DeviceError.None)
            {
                throw DeviceExceptionFactory.CreateException(res, "unable to vibrate the current vibrator.");
            }
        }
Example #22
0
        public static Result MakeResult(int code, DeviceError devicecode = DeviceError.NO_ERROR, string description = "")
        {
            Result result = new Result();

            switch (devicecode)
            {
            case DeviceError.NO_ANSWER:
                result.code = 310;
                break;

            default:
                result.code = code;
                break;
            }

            result.devicecode  = devicecode;
            result.description = description;
            //result.success = code == 0 ? true : false;
            return(result);
        }
Example #23
0
        internal static Exception CreateException(DeviceError err, string msg)
        {
            Exception exp;

            switch (err)
            {
            case DeviceError.InvalidParameter:
            case DeviceError.NotInitialized:
                //fall through
                exp = new ArgumentException(msg);
                break;

            case DeviceError.NotSupported:
                exp = new NotSupportedException(msg + " : Device does not support the Operation.");
                break;

            case DeviceError.AlreadyInProgress:
            //fall through
            case DeviceError.ResourceBusy:
            //fall through
            case DeviceError.OperationFailed:
            //fall through
            case DeviceError.InvalidOperation:
                exp = new InvalidOperationException(msg);
                break;

            case DeviceError.PermissionDenied:
                exp = new UnauthorizedAccessException(msg);
                break;

            default:
                exp = new InvalidOperationException("Unknown error occured.");
                break;
            }
            return(exp);
        }
Example #24
0
 protected void InvokeDeviceError(IDeviceEventArgs e)
 {
     CheckDisposed();
     DeviceError?.Invoke(this, e);
 }
Example #25
0
 protected void FireDeviceError(string msg)
 {
     DeviceError?.Invoke(this, msg);
 }
Example #26
0
        private void Listen(CancellationToken token)
        {
            CheckDisposed();
            DeviceStateEventArgs state = new DeviceStateEventArgs {
                IsEnabled = true
            };

            resetWait.Reset();
            NetworkStream stream = client.Connected ? client.GetStream() : null;

            while (!token.IsCancellationRequested)
            {
                if (state.IsEnabled)
                {
                    try
                    {
                        if (!client.Connected)
                        {
                            lock (lockerClient)
                            {
                                client.Dispose();
                                client = null;
                                OpenClient();
                                stream = client.Connected ? client.GetStream() : null;
                            }
                        }

                        PollingRequests();

                        if (stream?.DataAvailable ?? false)
                        {
                            byte[] buffer = new byte[client.ReceiveBufferSize];

                            int length = 0;
                            lock (lockerClient)
                            {
                                length = stream.Read(buffer, 0, buffer.Length);
                            }
                            try
                            {
                                IDeviceEventArgs message = RecivedData(buffer, length);
                                if (message != null)
                                {
                                    DeviceRecivedMessage?.Invoke(this, message);
                                }
                            }
                            catch (Exception ex)
                            {
                                DeviceError?.Invoke(this, new DeviceErrorEventArgs {
                                    Ex = ex
                                });
                            }
                        }

                        DeviceCheckState?.Invoke(this, state);
                        if (!state.IsEnabled)
                        {
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        DeviceError?.Invoke(this, new DeviceErrorEventArgs {
                            Ex = ex
                        });
                    }
                }
                else
                {
                    Disconnection(false);
                }
                Thread.Sleep(pollingTimeout);
            }
            resetWait.Set();
        }
Example #27
0
 public void OnErrorOccured(NandakaDevice device, DeviceError error, ILog log)
 {
     log.AppendMessage(LogMessageType.Error, $"Error occured with {device}. Reason: {error}");
 }
 public override void OnDeviceError(CloverDeviceErrorEvent deviceErrorEvent) => DeviceError?.Invoke(deviceErrorEvent);
Example #29
0
 public DeviceError_dst_adapter(DeviceError dst)
 {
     this.dst = dst;
 }
Example #30
0
 public void OnErrorOccured(NandakaDevice device, DeviceError error)
 {
     _updatePolicy.OnErrorOccured(device, error, _log);
 }