/// <summary> /// Constructor /// </summary> /// <param name="wrapperName">Gives the name that the wrapper is to use for the log messages that it creates</param> /// <param name="wrappedPort">Gives the IPort instance that the AEW is to implement auto echo for</param> public AutoEchoWrapper(string wrapperName, IPort wrappedPort) : base(wrapperName, "AutoEchoWrapper") { port = wrappedPort; portWrActionParam.Buffer = portRdActionParam.Buffer; portRdAction = port.CreateReadAction(portRdActionParam); portWrAction = port.CreateWriteAction(portWrActionParam); portRdAction.NotifyOnComplete.OnNotify += this.ReadActionComplete; portWrAction.NotifyOnComplete.OnNotify += this.WriteActionComplete; // I Want the BaseStateNotifier to act as both a IGuardedNotificationObject and an ISequencedRefObjectSource so that // can signal on its state change AND use an observer to look at it cheaply. portBaseStateObserver = new SequencedRefObjectSourceObserver<IBaseState, int>(port.BaseStateNotifier); portBaseStateObserver.Update(); SetBaseState(UseState.Initial, ConnState.Initial, "CTOR", true); AddExplicitDisposeAction(() => MosaicLib.Utils.Fcns.DisposeOfObject(ref port)); }
/// <summary>Contructor</summary> public ModbusServerFunctionPortAdapter(string partID, SerialIO.PortConfig portConfig, IModbusFCServer fcServer, ADUType aduType, byte unitID, bool responseToAllUnits) : base(partID, TimeSpan.FromSeconds(0.2)) { this.fcServer = fcServer; Timeout = portConfig.ReadTimeout; portConfig.ReadTimeout = TimeSpan.FromSeconds(Math.Min(0.1, Timeout.TotalSeconds)); port = SerialIO.Factory.CreatePort(portConfig); portBaseStateObserver = new SequencedRefObjectSourceObserver<IBaseState, Int32>(port.BaseStateNotifier); IPortBehavior portBehavior = port.PortBehavior; IDictionary<string, Logging.IMesgEmitter> emitters = new Dictionary<string,Logging.IMesgEmitter>() { { "Issue", Log.Error }, {"Debug", Log.Debug}, {"Trace", Log.Trace} }; serverFunctionContainer = new ServerFunctionContainer() { ADUType = aduType, Emitters = emitters, UnitID = unitID, RTUAddr = unitID, MBAPUnitID = unitID, RespondToAllTargets = responseToAllUnits }; FlushPeriod = (portBehavior.IsDatagramPort ? TimeSpan.FromSeconds(0.0) : TimeSpan.FromSeconds(0.1)); portReadAction = port.CreateReadAction(portReadActionParam = new ReadActionParam() { WaitForAllBytes = false }); portWriteAction = port.CreateWriteAction(portWriteActionParam = new WriteActionParam()); portFlushAction = port.CreateFlushAction(FlushPeriod); portReadAction.NotifyOnComplete.AddItem(threadWakeupNotifier); portWriteAction.NotifyOnComplete.AddItem(threadWakeupNotifier); portFlushAction.NotifyOnComplete.AddItem(threadWakeupNotifier); port.BaseStateNotifier.NotificationList.AddItem(threadWakeupNotifier); AddExplicitDisposeAction(() => Fcns.DisposeOfObject(ref port)); }