Ejemplo n.º 1
0
        public static void Test()
        {
            Debug.Write("Eis52Value 0xOCFB = " + (KNXConversion.Eis52Value(3323).ToString()) + "\r\n"); // expected to give 25.5
            Debug.Write("Value2Eis5 25.5 = " + (KNXConversion.Value2Eis5(25.5).ToString()) + "\r\n");   // expected to give 3323 = 0xOCFB

            Debug.Write("Eis62Percent 0xCC = " + (KNXConversion.Eis62Percent(204).ToString()) + "\r\n");
            Debug.Write("Eis62Percent 0xFF = " + (KNXConversion.Eis62Percent(255).ToString()) + "\r\n");
            Debug.Write("Eis62Percent 0x00 = " + (KNXConversion.Eis62Percent(0).ToString()) + "\r\n");
            Debug.Write("Percent2Eis6 0.4% = " + (KNXConversion.Percent2Eis6(0.4).ToString()) + "\r\n");
            Debug.Write("Percent2Eis6 100% = " + (KNXConversion.Percent2Eis6(100).ToString()) + "\r\n");
            Debug.Write("Percent2Eis6 0% = " + (KNXConversion.Percent2Eis6(0).ToString()) + "\r\n");

            Debug.Write("Eis62Angle 0x01 = " + (KNXConversion.Eis62Angle(1).ToString()) + "\r\n");
            Debug.Write("Eis62Angle 0xFF = " + (KNXConversion.Eis62Angle(255).ToString()) + "\r\n");
            Debug.Write("Eis62Angle 0x00 = " + (KNXConversion.Eis62Angle(0).ToString()) + "\r\n");
            Debug.Write("Angle2Eis6 1.4 degree = " + (KNXConversion.Angle2Eis6(1.4).ToString()) + "\r\n");
            Debug.Write("Angle2Eis6 360 degree = " + (KNXConversion.Angle2Eis6(360).ToString()) + "\r\n");
            Debug.Write("Angle2Eis6 0 degree = " + (KNXConversion.Angle2Eis6(0).ToString()) + "\r\n");
        }
Ejemplo n.º 2
0
        private string ParseKNXTelegram(byte[] b)
        {
            ushort address = (ushort)(b[3] << 8);

            address += b[4];
            uint   usefulData  = 0;
            string sUsefulData = "";

            if (b[2] != 0x71 || b[2] != 0x75)
            {
                switch (b[5])
                {
                case 0:
                case 1:
                    usefulData  = b[6];
                    sUsefulData = b[6].ToString();
                    break;

                case 2:
                    usefulData  = (uint)(b[6] << 8);
                    usefulData += b[7];
                    sUsefulData = KNXConversion.Eis52Value(usefulData).ToString();
                    break;

                default:

                    break;
                }
            }

            string eventType = "";

            switch (b[2])
            {
            case 0x70:
                eventType = "Write Sent";
                break;

            case 0x71:
                eventType = "Read Sent";
                break;

            case 0x74:
                eventType = "Write Recieved";
                break;

            case 0x75:
                eventType = "Read Recieved";
                break;

            case 0x76:
                eventType = "Response Recieved";
                break;
            }

            string result = "";

            if (b[2] == 0x71 || b[2] == 0x75)
            {
                result = eventType + ". Address: " + KNXConversion.GroupAddr2Ets(address, 3);
            }
            else
            {
                result = eventType + ". Address: " + KNXConversion.GroupAddr2Ets(address, 3) + " Length: " + b[5].ToString() + " Data: " + sUsefulData;
            }

            return(result);
        }
Ejemplo n.º 3
0
        private byte[] buildKNXTelegram(byte commandType)
        {
            if (commandType == 0x71)
            {
                byte[] knxMessage = { 0x5A, 0x03, commandType, 0x00, 0x00, 0x00 };
                int    knxAddress = 0;

                try
                {
                    knxAddress = KNXConversion.GroupETS2Addr(tbKnxGroupAddress.Text);
                }
                catch
                {
                    MessageBox.Show("KNX Group Address Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return(null);
                }
                finally
                {
                    knxMessage[3] = (byte)(knxAddress >> 8);
                    knxMessage[4] = (byte)(knxAddress % 256);
                }

                knxMessage[5] = Helper.calculateChecksum(knxMessage);

                return(knxMessage);
            }
            else
            {
                byte[] knxMessage = { 0x5A, 0x05, commandType, 0x00, 0x00, 0x00, 0x00, 0x00 };
                byte   val        = 0;

                switch (cbValueType.SelectedIndex)
                {
                case -1:     // Nothing selected
                    MessageBox.Show("You have to select a value type", "Missing Input", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return(null);

                case 0:     // 1-6 Bit
                    knxMessage = new byte[] { 0x5A, 0x05, commandType, 0x00, 0x00, 0x00, 0x00, 0x00 };

                    try
                    {
                        val = Convert.ToByte(tbValue.Text);
                    }
                    catch
                    {
                        MessageBox.Show("For 1-6 Bit type, value can be between 0-63 decimal", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return(null);
                    }
                    finally
                    {
                        knxMessage[6] = val;
                    }

                    if (val < 0 || val > 63)
                    {
                        MessageBox.Show("For 1-6 Bit type, value can be between 0-63 decimal", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return(null);
                    }

                    break;

                case 1:     // 1 Byte
                    knxMessage    = new byte[] { 0x5A, 0x05, commandType, 0x00, 0x00, 0x00, 0x00, 0x00 };
                    knxMessage[5] = 0x01;

                    try
                    {
                        val = Convert.ToByte(tbValue.Text);
                    }
                    catch
                    {
                        MessageBox.Show("For 1 byte type, value can be beetween 0-255 decimal", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return(null);
                    }
                    finally
                    {
                        knxMessage[6] = val;
                    }

                    if (val < 0 || val > 255)
                    {
                        MessageBox.Show("For 1 byte type, value can be beetween 0-255 decimal", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return(null);
                    }
                    break;

                case 2:     // 2 Byte
                    knxMessage = new byte[] { 0x5A, 0x06, commandType, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
                    int convertedValue = 0;
                    knxMessage[5] = 0x02;

                    try
                    {
                        convertedValue = KNXConversion.Value2Eis5(Convert.ToDouble(tbValue.Text));
                    }
                    catch
                    {
                        MessageBox.Show("For 2 byte type, value will be converted depending on DPT9", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return(null);
                    }
                    finally
                    {
                        knxMessage[6] = (byte)(convertedValue >> 8);
                        knxMessage[7] = (byte)(convertedValue % 256);
                    }

                    break;
                }

                int knxAddress = 0;
                try
                {
                    knxAddress = KNXConversion.GroupETS2Addr(tbKnxGroupAddress.Text);
                }
                catch
                {
                    MessageBox.Show("KNX Group Address Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return(null);
                }
                finally
                {
                    knxMessage[3] = (byte)(knxAddress >> 8);
                    knxMessage[4] = (byte)(knxAddress % 256);
                }

                knxMessage[knxMessage.Length - 1] = Helper.calculateChecksum(knxMessage);

                return(knxMessage);
            }
        }