Beispiel #1
0
            public SerialEchoTracker(string portPartID, string portTargetSpec, double[] binBoundariesArray, SerialEchoPerformancePartConfig config, INotifyable notifyOnDone, Logging.IBasicLogger logger)
            {
                PortTargetSpec = portTargetSpec;
                Config         = config;
                NotifyOnDone   = notifyOnDone;
                Logger         = logger;

                h = new Histogram(binBoundariesArray);

                timeoutCountGPI = new MDRF.Writer.GroupPointInfo()
                {
                    Name = "timeoutCount", ValueCST = ContainerStorageType.UInt64, VC = new ValueContainer(0L)
                };
                failureCountGPI = new MDRF.Writer.GroupPointInfo()
                {
                    Name = "failureCount", ValueCST = ContainerStorageType.UInt64, VC = new ValueContainer(0L)
                };

                hGrp = new MDRFHistogramGroupSource("{0}".CheckedFormat(portPartID),
                                                    h,
                                                    (ulong)config.AggregateGroupsFileIndexUserRowFlagBits,
                                                    extraClientNVS: new NamedValueSet()
                {
                    { "SerialEcho" }, { "PortTargetSpec", PortTargetSpec }
                },
                                                    extraGPISet: new[] { timeoutCountGPI, failureCountGPI });

                try
                {
                    portConfig = new PortConfig(portPartID, portTargetSpec)
                    {
                        TxLineTerm          = LineTerm.None,
                        RxLineTerm          = LineTerm.CR,
                        ConnectTimeout      = (2.0).FromSeconds(),
                        WriteTimeout        = (1.0).FromSeconds(),
                        ReadTimeout         = (1.0).FromSeconds(),
                        IdleTime            = (1.0).FromSeconds(),
                        EnableAutoReconnect = true,
                    };

                    port = MosaicLib.SerialIO.Factory.CreatePort(portConfig);

                    portGetNextPacketAction = port.CreateGetNextPacketAction();
                    portFlushAction         = port.CreateFlushAction();
                    portWriteAction         = port.CreateWriteAction(portWriteActionParam = new WriteActionParam());
                }
                catch (System.Exception ex)
                {
                    Logger.Error.Emit("Port setup for '{0}' failed: {1}", portTargetSpec, ex.ToString(ExceptionFormat.TypeAndMessage));
                }
            }
Beispiel #2
0
        /// <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));
        }
Beispiel #3
0
        /// <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));
        }