Beispiel #1
0
        private void KNXUart_OnKNXMessage(KNXNetworkLayerTemplate caller, KNXBaseTypes.KNXmessage Message, KNXNetworkLayerTemplate.KnxPacketEvents uartEvent)
        {
            if (Message.ControlField.RepeatFrame)
            {
                return;
            }

            if (Message.TargetAddress == knxGroupToMonitor)
            {
                FahPayloadInterpeter.TryToInterpret(ref Message);

                switch (Message.Payload.Apdu.apduType)
                {
                case KNXAdpu.ApduType.GroupValueWrite:
                    FAHGroupValueWrite fAHGroupValueWrite = new FAHGroupValueWrite(Message.Payload);
                    Console.Write("GroupMonitor: {0}; {1} ", Message.Timestamp.ToString(KNXHelpers.DateTimeFormat), Message.HeaderAsString);
                    data = fAHGroupValueWrite.MessageData;
                    OnGroupValueChange?.Invoke(this, data);
                    Message.Payload.ReadablePayloadPacket.PrintUnaccountedBytes(false);
                    break;

                case KNXAdpu.ApduType.GroupValueRead:
                    FAHGroupValueRead fAHGroupValueRead = new FAHGroupValueRead(Message.Payload);
                    Console.Write("GroupMonitor: {0}; {1} ", Message.Timestamp.ToString(KNXHelpers.DateTimeFormat), Message.HeaderAsString);
                    Message.Payload.ReadablePayloadPacket.PrintUnaccountedBytes(false);
                    break;

                case KNXAdpu.ApduType.GroupValueResponse:
                    FAHGroupValueResponse fAHGroupValueReponse = new FAHGroupValueResponse(Message.Payload);
                    Console.Write("GroupMonitor: {0}; {1} ", Message.Timestamp.ToString(KNXHelpers.DateTimeFormat), Message.HeaderAsString);
                    data = fAHGroupValueReponse.MessageData;
                    OnGroupValueChange?.Invoke(this, data);
                    Message.Payload.ReadablePayloadPacket.PrintUnaccountedBytes(false);
                    break;

                default:
                    Console.WriteLine("???" + Message.Payload.Apdu.apduType);
                    break;
                }
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            //Can be used to replay log messages to an existing device
            //fahDevToReturn = FaHDevice.DeserializeFromFile(@"ABB700C730A9-learn-metvloeren.json", true);
            //fahDevToLearn = FaHDevice.DeserializeFromFile(@"ABB700C730A9-learn-metvloeren.json", true);

            Console.SetWindowSize(Console.WindowWidth * 2, Console.WindowHeight);
            stdOut = new ReadWriteKNXDataLog("Output_" + DateTime.Now.Ticks + ".txt", true);
            //stdIn = new ReadWriteKNXDataLog(@"replay_log.txt", false);

            FaHTCPClient.TCPknxClient kNXUart = new FaHTCPClient.TCPknxClient("172.16.16.20", 9998);

            /*KNXUartModule.KNXUartConnection kNXUart = new KNXUartConnection(AppSettings.Default.ComPort)
             * {
             *  AllowWrite = AppSettings.Default.KNXWriteEnabled
             * };*/

            kNXUart.OnKNXMessage += KNXUart_OnKNXMessage;
            kNXUart.OnKNXEvent   += KNXUart_OnKNXEvent;
            //kNXUart.ResetAndInit();

            /*
             * int i = 0;
             * while (true)
             * {
             *  KNXmessage k = stdIn.ReadNextMessage();
             *  if (k == null) break;
             *  if (i > 0)
             *      KNXUart_OnKNXMessage(null, k, KNXUartConnection.UartEvents.GotKNXPacket);
             *
             *  i++;
             * }*/

            while (true)
            {
                string ret = Console.ReadLine();
                if (ret.ToLower() == "exit")
                {
                    Console.WriteLine("Exit Accepted");
                    return;
                }

                if (ret.ToLower() == "x")
                {
                    //[0x00 - 0x01]     [0x14 - 0xC8]      0x00 0x80 0x66
                    //[0xEB - 0x01]     [0xB5 - 0x50]      0x00[0x80 | 0x09]

                    //[0x00 - 0x01]     [0x14 - 0xC8]      0x00 0x80 0x59
                    //[0x00 - 0x01]     [0x3D - 0x26]      0x00 0x80 0x45 0x1E 0xD1 0x58

                    FaHDevice nulldev = new FaHDevice();
                    nulldev.KnxAddress.u16valueHigh = 1;
                    KNXAddress TargetGroupValue = new KNXAddress(0x14, 0xC8);
                    byte[]     data             = new byte[] { 0x66 };

                    KNXmessage GroupWriteMessage = FAHGroupValueWrite.CreateFAHGroupValueWrite(nulldev, TargetGroupValue, data, false);
                    KNXUart_OnKNXMessage(null, GroupWriteMessage, KNXNetworkLayerTemplate.KnxPacketEvents.GotKNXPacket);

                    kNXUart.SendKNXMessage(GroupWriteMessage);

                    //*************************************************************
                    KNXAddress TargetGroupValue1 = new KNXAddress(0x3D, 0x26);
                    byte[]     data1             = new byte[] { 0x45, 0x1E, 0xD1, 0x66 };

                    KNXmessage GroupWriteMessage1 = FAHGroupValueWrite.CreateFAHGroupValueWrite(nulldev, TargetGroupValue1, data1, true);
                    KNXUart_OnKNXMessage(null, GroupWriteMessage1, KNXNetworkLayerTemplate.KnxPacketEvents.GotKNXPacket);

                    kNXUart.SendKNXMessage(GroupWriteMessage1);

                    //**********************************************************************//
                }


                if (ret.ToLower() == "+")
                {
                    FaHDevice  nulldev          = new FaHDevice();
                    KNXAddress TargetGroupValue = new KNXAddress(0xC6, 0x4D);
                    byte[]     data             = new byte[] { 0x01 };

                    KNXmessage GroupWriteMessage = FAHGroupValueWrite.CreateFAHGroupValueWrite(nulldev, TargetGroupValue, data, true);
                    KNXUart_OnKNXMessage(null, GroupWriteMessage, KNXNetworkLayerTemplate.KnxPacketEvents.GotKNXPacket);

                    kNXUart.SendKNXMessage(GroupWriteMessage);


                    //2021 - 10 - 03 11:08:33.826; GroupValueWrite KNX_PRIORITY_HIGH[NoExtdFrame]   [0x00 - 0x01]     [0x3D - 0x26]      0x00 0x80 0x06 0xB0 0xFF 0x57
                }
                if (ret.ToLower() == "-")
                {
                    FaHDevice  nulldev          = new FaHDevice();
                    KNXAddress TargetGroupValue = new KNXAddress(0xC6, 0x4D);
                    byte[]     data             = new byte[] { 0x00 };

                    KNXmessage GroupWriteMessage = FAHGroupValueWrite.CreateFAHGroupValueWrite(nulldev, TargetGroupValue, data, true);
                    KNXUart_OnKNXMessage(null, GroupWriteMessage, KNXNetworkLayerTemplate.KnxPacketEvents.GotKNXPacket);


                    //[0xC6 - 0x4D]      0x00[0x80 | 0x01]

                    kNXUart.SendKNXMessage(GroupWriteMessage);


                    //2021 - 10 - 03 11:08:33.826; GroupValueWrite KNX_PRIORITY_HIGH[NoExtdFrame]   [0x00 - 0x01]     [0x3D - 0x26]      0x00 0x80 0x06 0xB0 0xFF 0x57
                }


                Console.WriteLine("# " + ret);
                stdOut.WriteComment(ret);
            }
        }