Beispiel #1
0
        internal WinusbAppiDev(USBDeviceInfo di)
        {
            // TODO: Отлавливать исключения WinUsbNet
            try
            {
                Device     = new USBDevice(di);
                DevicePath = di.DevicePath;

                ReadPipe = Device.Pipes.First(p => p.IsIn);
                ReadPipe.Policy.PipeTransferTimeout = 100;
                ReadPipe.Policy.AutoClearStall      = true;
                ReadPipe.Flush();

                WritePipe = Device.Pipes.First(p => p.IsOut);
                WritePipe.Policy.PipeTransferTimeout = 100;

                lock (OpenedDevicesLocker)
                {
                    OpenedDevices.Add(this);
                }
            }
            catch (USBException e)
            {
                throw new AppiConnectoinException(e);
            }
        }
        //public PipeReader(AnonymousPipeClientStream ToRead, string Label)
        public PipeReader(ReadPipe ToRead, string Label)
        {
            this.Underlying = ToRead;

            Worker      = new Thread(ReaderThread);
            Worker.Name = "StreamReaderThread_" + Label;
            Worker.Start();
        }
Beispiel #3
0
 /// <summary>
 /// Чтение буфера
 /// </summary>
 protected override byte[] ReadBufferImplement()
 {
     try
     {
         Byte[] buff = new Byte[BufferSize];
         ReadPipe.Read(buff);
         //return buff.SkipWhile(b => b == 0).ToArray();
         return(buff);
     }
     catch (Exception usbExc)
     {
         OnDisconnected();
         throw new AppiConnectoinException("Ошибка при чтении буфера АППИ из USB", usbExc);
     }
 }
Beispiel #4
0
 void IDisposable.Dispose()
 {
     ReadPipe?.Dispose();
     WritePipe?.Dispose();
 }