Beispiel #1
0
        public void SetWithBooleanFalse()
        {
            var builder = new TunnelRequestBuilder();

            var bytes = builder.Build(0x1C, 0, new MultiCastAddress(0, 4, 0), KnxData.FromBoolean(false));

            var expected = new byte[]
            {
                0x06, 0x10, 0x04, 0x20, 0x00, 0x15, 0x04, 0x1C, 0x00, 0x00, 0x11, 0x00, 0xAC, 0xF0, 0x00, 0x00, 0x04, 0x00,
                0x01, 0x00, 0x80
            };

            bytes.Length.Should().Be(expected.Length);
            bytes.Should().BeEquivalentTo(expected);
        }
Beispiel #2
0
        public void ShouldThrowExceptionIfNotConnected()
        {
            var connection = GetConnection();

            new Func <Task>(async() => await connection.SendAsync(MultiCastAddress.FromString("0/4/0"), KnxData.FromBoolean(false))).Should().Throw <NotConnectedException>();
        }
Beispiel #3
0
        public static async Task Main(string[] args)
        {
            Console.WriteLine("Send IP:");
            var sendIp = Console.ReadLine();

            Console.WriteLine("Send port:");
            var sendPort   = Convert.ToInt32(Console.ReadLine());
            var connection = new Connection(new IPEndPoint(IPAddress.Any, 45678), new IPEndPoint(IPAddress.Parse(sendIp), sendPort));

            connection.Connected += (sender, response) =>
                                    Console.WriteLine(
                $"Connected! CommunicationChannel: {response.CommunicationChannel} Status: {response.Status}");
            connection.Disconnected += (sender, response) =>
                                       Console.WriteLine(
                $"Disconnected! CommunicationChannel: {response.CommunicationChannel} Status: {response.Status}");

            Console.WriteLine("c:\tConnect");
            Console.WriteLine("d:\tDisconnect");
            Console.WriteLine("s:\tSend");
            Console.WriteLine("x:\tExit");

            while (true)
            {
                var key = Console.ReadKey();
                Console.SetCursorPosition(0, Console.CursorTop);
                switch (key.Key)
                {
                case ConsoleKey.C:
                    Console.WriteLine("Connect");
                    connection.Connect();
                    break;

                case ConsoleKey.X:
                    Console.WriteLine("Exit");
                    if (connection.IsConnected)
                    {
                        Console.WriteLine("Disconnect");
                        connection.Disconnect();
                    }
                    return;

                case ConsoleKey.S:
                    Console.WriteLine("Send");
                    await connection.SendAsync(MultiCastAddress.FromString(ReadLine("Address:")), KnxData.FromBoolean(Convert.ToBoolean(ReadLine("Value"))));

                    break;

                case ConsoleKey.D:
                    Console.WriteLine("Disconnect");
                    connection.Disconnect();
                    break;
                }
            }
        }