示例#1
0
        public void WriteReport(HidReport report, WriteCallback callback, int timeout)
        {
            var writeReportDelegate = new WriteReportDelegate(WriteReport);
            var asyncState          = new HidAsyncState(writeReportDelegate, callback);

            writeReportDelegate.BeginInvoke(report, timeout, EndWriteReport, asyncState);
        }
示例#2
0
        private void Parsecode(HidReport report, bool flag)
        {
            var data = String.Join(" ", report.Data.Select(d => d.ToString("X2")));
            if (data.StartsWith(heartbitpackage))
            {
                //"heartBit";
            }
            else
            {
                var buffer = report.Data;
                if (buffer.All(s => s == 0))
                {
                    //"Disconnected";
                    return;
                }
                else
                {
                    if (buffer.Last() == 0x01)
                    {
                        //多包二维码(第一包)
                        packages.Add(report.Data);
                    }
                    else
                    {
                        if (packages.Count == 0)
                        {
                            //单包二维码
                            var end = Array.IndexOf<byte>(buffer, ETX);
                            if (end > -1)
                            {
                                var dataLen = end - DataPos;
                                byte[] total = new byte[128];
                                Array.Copy(buffer, DataPos, total, 0, dataLen);
                                QRCode = ToAscii(total);
                            }
                        }
                        else
                        {
                            var package1 = packages.First().ToArray();
                            var package2 = buffer;

                            byte[] total = new byte[128];
                            //第一包结尾 73 00 01
                            var len = package1.Length - DataPos - 3;
                            //第一包从8个字节开始
                            Array.Copy(package1, DataPos, total, 0, len);
                            var end = Array.IndexOf<byte>(package2, ETX);
                            if (end > -1)
                            {
                                var pos = len;
                                //第二包从第4字节开始
                                len = end - 4;
                                Array.Copy(package2, 4, total, pos, len);
                            }
                            packages.Clear();
                            QRCode = ToAscii(total);
                        }
                    }
                }
            }
        }
示例#3
0
 private void ReadOutProcess(HidReport report)
 {
     this.Dispatcher.BeginInvoke(new ReadHandlerDelegate(ReadOutHandler), new object[] { report });
 }
示例#4
0
 private void ReadOutHandler(HidReport report)
 {
     Parsecode(report, false);
     _deviceOut.ReadReport(ReadOutProcess);
 }
示例#5
0
        private void Parsecode(HidReport report, bool flag)
        {
            var data = String.Join(" ", report.Data.Select(d => d.ToString("X2")));
            DataBuffer = string.Concat(data, "->", report.Data.Length);
            if (data.StartsWith(heartbitpackage))
            {
                Debug.WriteLine(data);
                Debug.WriteLine("heartBit");
            }
            else
            {
                var buffer = report.Data;
                if (buffer.All(s => s == 0))
                {
                    Debug.WriteLine("Disconnected");
                    _deviceIn.CloseDevice();
                    return;
                }
                else
                {
                    if (buffer.Last() == 0x01)
                    {
                        //多包二维码(第一包)
                        packages.Add(report.Data);
                    }
                    else
                    {
                        if (packages.Count == 0)
                        {
                            //单包二维码
                            Debug.WriteLine(buffer.First());
                            var end = Array.IndexOf<byte>(buffer, ETX);
                            if (end > -1)
                            {
                                var dataLen = end - DataPos;
                                byte[] total = new byte[128];
                                Array.Copy(buffer, DataPos, total, 0, dataLen);
                                Debug.WriteLine(data);
                                var code = ToAscii(total);
                                var prefix = flag ? "开门-" : "关门-";
                                QRCode = prefix + code + "->" + code.Length;
                                Debug.WriteLine(code);
                            }
                            else
                            {
                                Debug.WriteLine(data);
                            }
                        }
                        else
                        {
                            var package1 = packages.First().ToArray();
                            var package2 = buffer;

                            Debug.WriteLine(string.Join(" ", package1));
                            Debug.WriteLine(string.Join(" ", package2));

                            byte[] total = new byte[128];
                            //第一包结尾 73 00 01
                            var len = package1.Length - DataPos - 3;
                            //第一包从8个字节开始
                            Array.Copy(package1, DataPos, total, 0, len);
                            var end = Array.IndexOf<byte>(package2, ETX);
                            if (end > -1)
                            {
                                var pos = len;
                                //第二包从第4字节开始
                                len = end - 4;
                                Array.Copy(package2, 4, total, pos, len);
                            }
                            packages.Clear();
                            var code = ToAscii(total);
                            var prefix = flag ? "开门-" : "关门-";
                            QRCode = prefix + code + "->" + code.Length;
                            Debug.WriteLine(code);
                        }
                    }
                }
            }
        }
示例#6
0
 private void ParseCode(HidReport report, bool flag)
 {
     var data = String.Join(" ", report.Data.Select(d => d.ToString("X2")));
     if (data.StartsWith(heartbitpackage))
     {
         LogHelper.Info("heartBit");
     }
     else
     {
         var buffer = report.Data;
         if (buffer.All(s => s == 0))
         {
             CloseDevice();
             LogHelper.Info("Disconnected");
             return;
         }
         else
         {
             if (buffer.Last() == 0x01)
             {
                 //多包二维码(第一包)
                 _hidPackages.Add(report.Data);
             }
             else
             {
                 if (_hidPackages.Count == 0)
                 {
                     //单包二维码
                     var end = Array.IndexOf<byte>(buffer, ETX);
                     if (end > -1)
                     {
                         var dataLen = end - DataStartPos;
                         byte[] total = new byte[128];
                         Array.Copy(buffer, DataStartPos, total, 0, dataLen);
                         var code = total.ToAscII();
                         _readerBarcodeCallback(code);
                     }
                     else
                     {
                         LogHelper.Info(data);
                     }
                 }
                 else
                 {
                     var package1 = _hidPackages.First().ToArray();
                     var package2 = buffer;
                     byte[] total = new byte[128];
                     //第一包结尾 73 00 01
                     var len = package1.Length - DataStartPos - 3;
                     //第一包从8个字节开始
                     Array.Copy(package1, DataStartPos, total, 0, len);
                     var end = Array.IndexOf<byte>(package2, ETX);
                     if (end > -1)
                     {
                         var pos = len;
                         //第二包从第4字节开始
                         len = end - 4;
                         Array.Copy(package2, 4, total, pos, len);
                     }
                     _hidPackages.Clear();
                     var code = total.ToAscII();
                     _readerBarcodeCallback(code);
                 }
             }
         }
     }
 }
示例#7
0
 public async Task<bool> WriteReportAsync(HidReport report, int timeout = 0)
 {
     var writeReportDelegate = new WriteReportDelegate(WriteReport);
     return await Task<bool>.Factory.FromAsync(writeReportDelegate.BeginInvoke, writeReportDelegate.EndInvoke, report, timeout, null);
 }
示例#8
0
 public bool WriteReport(HidReport report, int timeout)
 {
     return(Write(report.GetBytes(), timeout));
 }
示例#9
0
 public void WriteReport(HidReport report, WriteCallback callback)
 {
     WriteReport(report, callback, 0);
 }
示例#10
0
 public bool WriteReport(HidReport report, int timeout)
 {
     return Write(report.GetBytes(), timeout);
 }
示例#11
0
 public bool WriteReport(HidReport report)
 {
     return WriteReport(report, 0);
 }
示例#12
0
        public async Task <bool> WriteReportAsync(HidReport report, int timeout = 0)
        {
            var writeReportDelegate = new WriteReportDelegate(WriteReport);

            return(await Task <bool> .Factory.FromAsync(writeReportDelegate.BeginInvoke, writeReportDelegate.EndInvoke, report, timeout, null));
        }
示例#13
0
 public void WriteReport(HidReport report, WriteCallback callback)
 {
     WriteReport(report, callback, 0);
 }
示例#14
0
 private void ReadInHandler(HidReport report)
 {
     Parsecode(report, true);
     _deviceIn.ReadReport(ReadInProcess);
 }
示例#15
0
 public void WriteReport(HidReport report, WriteCallback callback, int timeout)
 {
     var writeReportDelegate = new WriteReportDelegate(WriteReport);
     var asyncState = new HidAsyncState(writeReportDelegate, callback);
     writeReportDelegate.BeginInvoke(report, timeout, EndWriteReport, asyncState);
 }
示例#16
0
 private void ReadInProcess(HidReport report)
 {
     Application.Current.Dispatcher.BeginInvoke(new ReadHandlerDelegate(ReadInHandler), new object[] { report });
 }
示例#17
0
 public bool WriteReport(HidReport report)
 {
     return(WriteReport(report, 0));
 }