Exemplo n.º 1
0
 static void ReadGroupObject(AccessPort accessPort, int address)
 {
     try
     {
         byte[] telegram = accessPort.ReadGroupObject(address, 1000);
         byte[] data     = AccessPort.GetGroupData(telegram);
         Logger.Dump(Logger.Level.Information, "GroupValueRead response data", data);
     }
     catch (KdriveException e)
     {
         Logger.Log(Logger.Level.Error, "Error in ReadGroupObject: " + e.Message);
     }
 }
Exemplo n.º 2
0
        static void OnGroupData(byte[] buffer)
        {
            int address = AccessPort.GetDestAddress(buffer);

            byte[] data         = AccessPort.GetGroupData(buffer);
            GA     groupAddress = (GA)address;
            String value        = "";

            switch (groupAddress)
            {
            case GA.DPT1:
                value = String.Format("[1 Bit] {0}", Datapoint.Decode_DPT1(data));
                break;

            case GA.DPT2:
                bool dpt2_c = false;
                bool dpt2_v = false;
                Datapoint.Decode_DPT2(data, ref dpt2_c, ref dpt2_v);
                value = String.Format("[1 Bit Controlled] Control: {0} Value: {1}", dpt2_c, dpt2_v);
                break;

            case GA.DPT3:
                bool dpt3_c = false;
                byte dpt3_v = 0;
                Datapoint.Decode_DPT3(data, ref dpt3_c, ref dpt3_v);
                value = String.Format("[3 Bit Controlled] Control: {0} Value: {1}", dpt3_c, dpt3_v);
                break;

            case GA.DPT4:
                value = String.Format("[character] {0}", Datapoint.Decode_DPT4(data));
                break;

            case GA.DPT5:
                value = String.Format("[8 bit unsigned] {0}", Datapoint.Decode_DPT5(data));
                break;

            case GA.DPT6:
                value = String.Format("[8 bit signed] {0}", Datapoint.Decode_DPT6(data));
                break;

            case GA.DPT7:
                value = String.Format("[2 byte unsigned] {0}", Datapoint.Decode_DPT7(data));
                break;

            case GA.DPT8:
                value = String.Format("[2 byte signed] {0}", Datapoint.Decode_DPT8(data));
                break;

            case GA.DPT9:
                value = String.Format("[float] {0}", Datapoint.Decode_DPT9(data));
                break;

            case GA.DPT10_LOCAL:
            case GA.DPT10_UTC:
            case GA.DPT10:
                int day    = 0;
                int hour   = 0;
                int minute = 0;
                int second = 0;
                Datapoint.Decode_DPT10(data, ref day, ref hour, ref minute, ref second);
                value = String.Format("[time] {0} {1} {2} {3}", day, hour, minute, second);
                break;

            case GA.DPT11:
                int year  = 0;
                int month = 0;
                int d     = 0;
                Datapoint.Decode_DPT11(data, ref year, ref month, ref d);
                value = String.Format("[date] {0} {1} {2}", year, month, d);
                break;

            case GA.DPT12:
                value = String.Format("[4 byte unsigned] {0}", Datapoint.Decode_DPT12(data));
                break;

            case GA.DPT13:
                value = String.Format("[4 byte signed] {0}", Datapoint.Decode_DPT13(data));
                break;

            case GA.DPT14:
                value = String.Format("[4 byte float] {0}", Datapoint.Decode_DPT14(data));
                break;

            case GA.DPT15:
                int  accessCode = 0;
                bool error      = false;
                bool permission = false;
                bool direction  = false;
                bool encrypted  = false;
                int  index      = 0;
                Datapoint.Decode_DPT15(data, ref accessCode, ref error, ref permission,
                                       ref direction, ref encrypted, ref index);
                value = String.Format("[entrance access] {0} {1} {2} {3} {4} {5}",
                                      accessCode, error, permission,
                                      direction, encrypted, index);
                break;

            case GA.DPT16:
                value = String.Format("[character string] {0}", Datapoint.Decode_DPT16(data));
                break;

            default:
                Logger.Log(Logger.Level.Information, String.Format("Group Value for address: {0:x4}", address));
                Logger.Dump(Logger.Level.Information, "Value of GroupObject", data);
                break;
            }

            if (value != "")
            {
                String message = String.Format("{0} {1}", groupAddress, value);
                Logger.Log(Logger.Level.Information, message);
            }
        }