1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- using Edge.Core.Processor;using Edge.Core.IndustryStandardInterface.Pump;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Edge.Core.Processor.Communicator;
- namespace OPW_VaporRecoveryOnlineWatch_PressureGage
- {
- public class StateMachineMessageCutter : 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("PumpHandler");
- private string loggerAppendix = "OPW_VaporRecoveryOnlineWatch_PressureGage msgCutter ";
- private readonly List<byte> buffer = new List<byte>();
- /// <summary>
- /// </summary>
- public StateMachineMessageCutter()
- {
- }
- public void Feed(byte[] next)
- {
- for (int i = 0; i < next.Length; i++)
- {
- if ((next[i] == 0xFE && this.buffer.Count == 0)
- || (next[i] != 0xFE && this.buffer.Count != 0))
- {
- this.buffer.Add(next[i]);
- }
- if (this.buffer.Count == 7)
- {
- this.Message = this.buffer.ToArray();
- var safe = this.OnMessageCut;
- safe?.Invoke(this, null);
- this.buffer.Clear();
- }
- }
- }
- }
- }
|