public BusMaster(string name, string targetSpecStr, bool autoConnect) : base(name, "HART.BusMaster") { portConfig = new SerialIO.PortConfig(name + ".sp", targetSpecStr, MosaicLib.SerialIO.LineTerm.None) { EnableAutoReconnect = autoConnect, // SpinWaitTimeLimit = TimeSpan.FromSeconds(0.001), TraceDataLoggerGroupID = Logging.LookupDistributionGroupName, // support mapping of this logger into a non-default group. TraceDataMesgType = Logging.MesgType.Trace, TraceMesgType = Logging.MesgType.Trace, DebugMesgType = Logging.MesgType.Trace, }; try { sp = SerialIO.Factory.CreatePort(portConfig); } catch (System.Exception ex) { Log.Error.Emit("CreatePort failed: {0}", ex.Message); sp = SerialIO.Factory.CreatePort(new MosaicLib.SerialIO.PortConfig(name + ".sp", "<NullPort/>", MosaicLib.SerialIO.LineTerm.None)); } spFlushAction = sp.CreateFlushAction(TimeSpan.FromSeconds(0.100)); }
/// <summary>Contructor</summary> public ModbusServerFunctionPortAdapter(string partID, SerialIO.PortConfig portConfig, IModbusFCServer fcServer, ADUType aduType, byte unitID, bool responseToAllUnits) : base(partID, initialSettings: SimpleActivePartBaseSettings.DefaultVersion2.Build(waitTimeLimit: (0.2).FromSeconds())) { this.fcServer = fcServer; Timeout = portConfig.ReadTimeout; portConfig.ReadTimeout = TimeSpan.FromSeconds(Math.Max(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); portReinitializeAction = port.CreateGoOnlineAction(true); portReadAction.NotifyOnComplete.AddItem(threadWakeupNotifier); portWriteAction.NotifyOnComplete.AddItem(threadWakeupNotifier); portFlushAction.NotifyOnComplete.AddItem(threadWakeupNotifier); portReinitializeAction.NotifyOnComplete.AddItem(threadWakeupNotifier); port.BaseStateNotifier.NotificationList.AddItem(threadWakeupNotifier); AddMainThreadStartingAction(() => port.StartPart()); AddMainThreadStoppingAction(() => port.StopPart()); AddExplicitDisposeAction(() => Fcns.DisposeOfObject(ref port)); }