public PacketEventArgs(Packet p) { Packet = p; }
public SendCommand(Action<Packet> action, Packet packet) { _action = action; _packet = packet; }
protected Packet Read() { int length; int pos = 0; ErrorCode c = ErrorCode.None; do { c = _irIN.Read(_rxBuffer, pos, _rxBuffer.Length - pos, 2000, out length); if (c == ErrorCode.None) { pos += length; if(length < 64) { byte[] retVal = new byte[pos]; Array.Copy(_rxBuffer, retVal, pos); Encoder enc = new Encoder(retVal); Packet p = new Packet(_logger); p.Parse(enc); return p; } } else if (c == ErrorCode.IoTimedOut) { } else { _logger.Log("Error {0}", c.ToString()); _logger.Log(UsbDevice.LastErrorString); } } while (c == ErrorCode.None); return null; }
public void Send(Packet p) { Enqueue(new SendCommand(OnSend, p)); }
protected void OnSend(Packet p) { int length; byte[] data = p.ToArray(); ErrorCode c = _bulkOUT.Write(data, 2000, out length); if (c == ErrorCode.None) p.Print(); else _logger.Log("Error {0} {1}", c.ToString(), UsbDevice.LastErrorString); _bulkOUT.Flush(); }