123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- using Edge.Core.Processor;using Edge.Core.IndustryStandardInterface.Pump;
- using Edge.Core.Parser.BinaryParser.Util;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Edge.Core.Processor.Communicator;
- namespace ShellChina_EPS_Project_CarPlatePay_EpsClient_App
- {
-
-
-
- public class MessageCutter : IMessageCutter<byte[]>
- {
- public byte[] Message { get; private set; }
- public event EventHandler OnMessageCut;
- public event EventHandler<MessageCutterInvalidMessageReadEventArg> OnInvalidMessageRead;
-
- static NLog.Logger innerLogger = NLog.LogManager.LoadConfiguration("nlog.config").GetLogger("Communicator");
- private readonly List<byte> buffer = new List<byte>();
- private int fullMsgLength = 0;
-
-
-
-
- public MessageCutter()
- {
- }
- public void Feed(byte[] next)
- {
- for (int i = 0; i < next.Length; i++)
- {
- this.buffer.Add(next[i]);
- if (this.buffer.Count == 2)
- {
- this.fullMsgLength = (this.buffer[0] << 8) + this.buffer[1] + 2;
- }
- if (this.buffer.Count == this.fullMsgLength)
- {
- var e = this.OnMessageCut;
- this.Message = this.buffer.ToArray();
- e?.Invoke(this, null);
- this.fullMsgLength = 0;
- this.buffer.Clear();
- }
- }
- }
- }
- }
|