/// <summary> /// Determines if the message was fully received /// </summary> /// <returns></returns> public bool MessageReceived() { BufferFrameList.ForEach(Console.WriteLine); return(IncomingMessage.ToString().IndexOf(MessageTerminatorStop) > -1); }
/// <summary> /// Converts the buffer to a string ans stores it /// </summary> public void BuildIncomingMessage() { if (BufferList.Count > (MsgTerminatorStart.Count + BarcodeLengthSize + MsgTerminatorStop.Count)) { while (BufferList.Count > (MsgTerminatorStart.Count + MsgTerminatorStop.Count + BarcodeLengthSize)) { bool IsMsgTerminatorStart = true; bool IsMsgTerminatorStop = true; for (int i = 0; i < MsgTerminatorStart.Count; i++) { if (BufferList[i] != MsgTerminatorStart[i]) { IsMsgTerminatorStart = false; ClearBufferList(0, 1); break; } } if (IsMsgTerminatorStart) { int BarcodeLength = 0; BarcodeLength = Int32.Parse(Encoding.ASCII.GetString(BufferList.ToArray(), MsgTerminatorStart.Count, BarcodeLengthSize - 1)); // Console.WriteLine($" gia tri cuar con ver la {ConvertByteArrayToInt32(BufferList.GetRange(MsgTerminatorStart.Count, BarcodeLengthSize).ToArray())} "); int LengthToMsgStop = MsgTerminatorStart.Count + BarcodeLengthSize + BarcodeLength; for (int i = LengthToMsgStop; i < (LengthToMsgStop + MsgTerminatorStop.Count); i++) { if (BufferList[i] != MsgTerminatorStop[i - LengthToMsgStop]) { IsMsgTerminatorStop = false; ClearBufferList(0, i); break; } } if (IsMsgTerminatorStart && IsMsgTerminatorStop) { BufferFrameList.Add(Encoding.ASCII.GetString(BufferList.ToArray(), MsgTerminatorStart.Count + BarcodeLengthSize, (int)BarcodeLength)); ClearBufferList(0, (LengthToMsgStop + MsgTerminatorStop.Count)); } } } } }