Пример #1
0
        /* write record */
        public bool Write(byte[] data)
        {
            try
            {
                Trace.WriteLine("Send HID:\n" + Converts.ByteArrayToString(data));
                /* write some bytes */
                _fileStream?.Write(data, 0, data.Length);
                /* flush! */
                _fileStream?.Flush();

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Пример #2
0
        public bool Write(byte[] data)
        {
            try
            {
                GattCommunicationStatus result = GattCommunicationStatus.Success;
                lock (_lock)
                {
                    _WriteChar.WriteValueAsync(data.Skip(5).Take(20).ToArray().AsBuffer())
                    .AsTask()
                    .ContinueWith(r =>
                    {
                        if (r.Status == TaskStatus.Faulted)
                        {
                            var name = _Device.Name;
                            var id   = _Device.DeviceId;
                            result   = GattCommunicationStatus.Unreachable;
                            if (r.Exception is AggregateException aex && aex.InnerExceptions.Any(e => e is ObjectDisposedException))
                            {
                                Reopen();
                            }
                        }
                        else
                        {
                            result = r.Result;
                        }
                    })
                    .Wait();
                }
                Trace.WriteLine("Send:\n" + Converts.ByteArrayToString(data.Skip(5).Take(20).ToArray()));

                return(result == GattCommunicationStatus.Success);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }