Beispiel #1
0
    // ANCHOR_END: master_channel_config

    // ANCHOR: association_config
    private static AssociationConfig GetAssociationConfig()
    {
        var config = new AssociationConfig(
            // disable unsolicited first (Class 1/2/3)
            EventClasses.All(),
            // after the integrity poll, enable unsolicited (Class 1/2/3)
            EventClasses.All(),
            // perform startup integrity poll with Class 1/2/3/0
            Classes.All(),
            // don't automatically scan Class 1/2/3 when the corresponding IIN bit is asserted
            EventClasses.None()
            );

        config.AutoTimeSync     = AutoTimeSync.Lan;
        config.KeepAliveTimeout = TimeSpan.FromSeconds(60);
        return(config);
    }
Beispiel #2
0
    private static async Task MainAsync(Runtime runtime)
    {
        var master = Master.CreateTcpSession(
            runtime,
            LinkErrorMode.Close,
            GetMasterConfig(),
            new EndpointList("127.0.0.1:20000"),
            new TestListener()
            );

        var readHandler = new TestReadHandler();
        var association = master.AddAssociation(
            1024,
            new AssociationConfig(EventClasses.All(), EventClasses.All(), Classes.All(), EventClasses.None())
        {
            AutoTimeSync           = AutoTimeSync.Lan,
            AutoTasksRetryStrategy = new RetryStrategy
            {
                MinDelay = TimeSpan.FromSeconds(1),
                MaxDelay = TimeSpan.FromSeconds(5),
            },
            KeepAliveTimeout = TimeSpan.FromSeconds(60),
        },
            new AssociationHandlers(readHandler, readHandler, readHandler),
            new TestTimeProvider()
            );

        var pollRequest = Request.ClassRequest(false, true, true, true);
        var poll        = association.AddPoll(pollRequest, TimeSpan.FromSeconds(5));

        // start communications
        master.Enable();

        while (true)
        {
            switch (await GetInputAsync())
            {
            case "x":
                return;

            case "enable":
            {
                master.Enable();
                break;
            }

            case "disable":
            {
                master.Disable();
                break;
            }

            case "dln":
            {
                master.SetDecodeLevel(new DecodeLevel());
                break;
            }

            case "dlv":
            {
                master.SetDecodeLevel(new DecodeLevel()
                    {
                        Application = AppDecodeLevel.ObjectValues
                    });
                break;
            }

            case "rao":
            {
                var request = new Request();
                request.AddAllObjectsHeader(Variation.Group40Var0);
                var result = await association.Read(request);

                Console.WriteLine($"Result: {result}");
                break;
            }

            case "rmo":
            {
                var request = new Request();
                request.AddAllObjectsHeader(Variation.Group10Var0);
                request.AddAllObjectsHeader(Variation.Group40Var0);
                var result = await association.Read(request);

                Console.WriteLine($"Result: {result}");
                break;
            }

            case "cmd":
            {
                var command = new Command();
                command.AddU16g12v1(3, new G12v1(new ControlCode(TripCloseCode.Nul, false, OpType.LatchOn), 1, 1000, 1000));
                var result = await association.Operate(CommandMode.SelectBeforeOperate, command);

                Console.WriteLine($"Result: {result}");
                break;
            }

            case "evt":
            {
                poll.Demand();
                break;
            }

            case "lts":
            {
                var result = await association.PerformTimeSync(TimeSyncMode.Lan);

                Console.WriteLine($"Result: {result}");
                break;
            }

            case "nts":
            {
                var result = await association.PerformTimeSync(TimeSyncMode.NonLan);

                Console.WriteLine($"Result: {result}");
                break;
            }

            case "crt":
            {
                var result = await association.ColdRestart();

                Console.WriteLine($"Result: {result}");
                break;
            }

            case "wrt":
            {
                var result = await association.WarmRestart();

                Console.WriteLine($"Result: {result}");
                break;
            }

            case "lsr":
            {
                var result = await association.CheckLinkStatus();

                Console.WriteLine($"Result: {result}");
                break;
            }

            default:
                Console.WriteLine("Unknown command");
                break;
            }
        }
    }