/// <summary> /// /// </summary> /// <param name="iftAr"></param> void MsgPipeReadComplate(IAsyncResult iftAr) { int bytes = 0; CanMessage[] frames; //lock (LockObj) Ezt nem lehet lock-ni, mivel adatvesztés következik be.! { if (!this.isAbort) { try { bytes = Usb.Pipes[USB_MSG_IN_ADDR].EndRead(iftAr); } catch (Exception ex) { /*Itt valahogy jelezni kell, hogy ha hibábval ért véget a pipe olvasása*/ /*Ha itt hiba történt akkor vége.*/ LasException = ex; this.isAbort = true; } } if (bytes != 0) { CanMessage.MsgPacketToCanFrames(rxMsgPacketBuffer, bytes, out frames); for (int i = 0; i < frames.Length; i++) { RxCanMsgAbsTime = (frames[i].TimestampTick * 10000) + RxCanMsgAbsTime; frames[i].TimestampTick = RxCanMsgAbsTime; if (IncomingMsgQueue != null) { IncomingMsgQueue.Enqueue(frames[i]); } } if (_asyncReadBeginResult != null && !_asyncReadBeginResult.IsCompleted) { if (IncomingMsgQueue.Count >= _readBeginLength) { Read(_readBeginFrameArray, _readBeginOffset, _readBeginLength); _asyncReadBeginResult.OnCompletion(false, null, _readBeginLength, true); } } } if (!this.isAbort) { Usb.Pipes[USB_MSG_IN_ADDR].BeginRead(rxMsgPacketBuffer, 0, UsbMsgInEpSize, _asynReadCpltCallback, null); } } }
public IAsyncResult BeginRead(CanMessage[] frames, int offset, int length, AsyncCallback userCallback, object stateObject) { if (!IsConnected) { throw new CanAdapterException("Adapter is Disconnected. Code:-8604."); //Doc } if (!_isOpen) { throw new CanAdapterException("Bus is Closed. Code:-8605"); //Doc } if (frames == null) { throw new ArgumentNullException("Frame Buffer cannot be null. Code:-8606."); //Doc } _readBeginFrameArray = frames; _readBeginLength = length; _readBeginOffset = offset; _asyncReadBeginResult = new CanAsyncResult(userCallback, stateObject); try { //Van annyi elem, hogy most azonnal vége legyen. if (IncomingMsgQueue.Count >= length) { Read(_readBeginFrameArray, offset, length); _asyncReadBeginResult.OnCompletion(true, null, length, true); } } catch (Exception) { _asyncReadBeginResult.Dispose(); throw; } return(_asyncReadBeginResult); }