/// <summary> /// /// </summary> /// <param name="queue"></param> /// <param name="msgInPacket"></param> /// <param name="buffer"></param> /// <param name="size"></param> internal static void QueueToMsgPacket(SafeQueue <CanMessage> queue, int msgInPacket, out byte[] buffer, out int size) { int items = queue.Count; CanMessage[] frames; if (items != 0) { if (items > msgInPacket) { frames = new CanMessage[msgInPacket]; for (int i = 0; i < msgInPacket; i++) { frames[i] = queue.Dequeue(); } } else { frames = new CanMessage[items]; for (int i = 0; i < items; i++) { frames[i] = queue.Dequeue(); } } buffer = new byte[64]; CanMessage.CanFramesToMsgPacket(frames, buffer, out size); } else { buffer = new byte[0]; size = 0; } }
/// <summary> /// Reading a specified number of messages in the frame buffer. /// </summary> /// <param name="frames">Frame buffer that will receive the data read from the queue.</param> /// <param name="offset">Frame offset within the buffer at which to begin writing the data received.</param> /// <param name="length">Length of the data to transfer.</param> /// <returns>The number of frames read from the pipe.</returns> public int Read(CanMessage[] frames, int offset, int length) { 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 } for (int i = 0; i < length; i++) { frames[i + offset] = IncomingMsgQueue.Dequeue(); } return(length); }