using System; using System.Collections.Generic; using System.Linq; using System.IO.Ports; using System.Threading; using Edge.Core.Parser.BinaryParser.MessageEntity; using Edge.Core.Processor; using Edge.Core.IndustryStandardInterface.Pump; using Edge.Core.Parser; using System.Threading.Tasks; using Edge.Core.Processor.Communicator; namespace Mocks { public class ComPortCommunicatorMock : ICommunicator where T : MessageBase { private object syncObject = new object(); private int isStarted = 0; public string Identity { get; set; } public event EventHandler OnConnected; public event EventHandler OnDisconnected; public event EventHandler> OnRawDataWriting; public event EventHandler> OnDataReceived; public event EventHandler OnErrorMessageRead; public bool Write(T message) { var safe = this.OnRawDataWriting; var arg = new CommunicatorEventArg() { Message = message, Continue = true }; safe?.Invoke(this, arg); return true; } public void Dispose() { this.isStarted = 0; } public async Task Start() { if (0 == Interlocked.CompareExchange(ref this.isStarted, 1, 0)) { return true; } return false; } #region mock functions /// /// simulate a message was read and parsed from remote device, then push this message finally to Hanlder. /// /// public void FireOnDataReceived(T message) { var safe = this.OnDataReceived; safe?.Invoke(this, new CommunicatorEventArg() { Message = message }); } public bool Write(T message, object extraControlParameter) { throw new NotImplementedException(); } #endregion } }