コード例 #1
0
        public void DPT9_ShouldParse(byte[] bytes, float expected)
        {
            var parser = new DataTypeParser();
            var result = parser.DTP9(bytes).FloatValue;

            Assert.Equal(expected, result);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: martinguess/KNXNet
        public static void Main(string[] args)
        {
            KnxTunnelingConnection connection         = new KnxTunnelingConnection("172.16.1.122", 3671);
            KnxGroupAddress        temperatureAddress = KnxGroupAddress.Parse("15/1/0");
            KnxGroupAddress        relayAddress       = KnxGroupAddress.Parse("15/3/0");
            DataTypeParser         parser             = new DataTypeParser();

            connection.Logger = new ConsoleLogger();

            connection.OnConnect    += (sender, eventArgs) => Console.WriteLine("Connected");
            connection.OnDisconnect += (sender, eventArgs) => Console.WriteLine("Disconnected");
            connection.OnData       += (sender, eventArgs) =>
            {
                Console.WriteLine(eventArgs.SourceAddress + " -> " + eventArgs.DestinationAddress + " : " + ByteArrayToString(eventArgs.Data));

                if (eventArgs.DestinationAddress == temperatureAddress && (eventArgs.RequestType == APCIType.AGroupValueWrite || eventArgs.RequestType == APCIType.AGroupValueResponse))
                {
                    Console.WriteLine("Temp: " + parser.DTP9(eventArgs.Data).FloatValue);
                }
            };

            connection.Connect();

            while (true)
            {
                ConsoleKey key = Console.ReadKey().Key;

                if (key == ConsoleKey.Q)
                {
                    break;
                }
                else if (key == ConsoleKey.A)
                {
                    connection.RequestValue(temperatureAddress);
                }
                else if (key == ConsoleKey.Z)
                {
                    connection.SendValue(relayAddress, new byte[] { 0 }, 1);
                }
                else if (key == ConsoleKey.X)
                {
                    connection.SendValue(relayAddress, new byte[] { 1 }, 1);
                }
            }

            connection.Disconnect();

            Task.Delay(1000).Wait();
        }