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"); }
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); } }