public static KnxAddress Parse(string address) { if (address.Contains(".")) { return(KnxIndividualAddress.Parse(address)); } return(KnxGroupAddress.Parse(address)); }
public void StringParserTestFreeStyle() { var ga = KnxGroupAddress.Parse("230"); Assert.IsInstanceOf <KnxFreeStyleGroupAddress>(ga); KnxFreeStyleGroupAddress threeLevelGa = (KnxFreeStyleGroupAddress)ga; Assert.AreEqual(230, threeLevelGa.SubGroup); Assert.AreEqual(true, threeLevelGa.Equals(230)); Assert.AreEqual(true, threeLevelGa.Equals("230")); }
private static void LightOnOff(KnxConnection connection) { Console.WriteLine("Press [ENTER] to send command ({0}) - false", LightOnOffAddress); Console.ReadLine(); connection.Action(KnxGroupAddress.Parse(LightOnOffAddress), false); Thread.Sleep(200); Console.WriteLine("Press [ENTER] to send command ({0}) - true", LightOnOffAddress); Console.ReadLine(); connection.Action(KnxGroupAddress.Parse(LightOnOffAddress), true); Thread.Sleep(200); }
public void StringParserTestTwoLevel() { var ga = KnxGroupAddress.Parse("18/230"); Assert.IsInstanceOf <KnxTwoLevelGroupAddress>(ga); KnxTwoLevelGroupAddress threeLevelGa = (KnxTwoLevelGroupAddress)ga; Assert.AreEqual(18, threeLevelGa.MainGroup); Assert.AreEqual(230, threeLevelGa.SubGroup); Assert.AreEqual(true, threeLevelGa.Equals(18, 230)); Assert.AreEqual(true, threeLevelGa.Equals("18/230")); }
public void ByteParserTest() { var gaThreeLevel = KnxGroupAddress.Parse(new byte[] { 0xa0, 0xb4 }, KnxGroupAddressStyle.ThreeLevel); var gaTwoLevel = KnxGroupAddress.Parse(new byte[] { 0xa0, 0xb4 }, KnxGroupAddressStyle.TwoLevel); var gaFreeStyle = KnxGroupAddress.Parse(new byte[] { 0xa0, 0xb4 }, KnxGroupAddressStyle.Free); Assert.IsInstanceOf <KnxThreeLevelGroupAddress>(gaThreeLevel); Assert.IsInstanceOf <KnxTwoLevelGroupAddress>(gaTwoLevel); Assert.IsInstanceOf <KnxFreeStyleGroupAddress>(gaFreeStyle); Assert.AreEqual("20/0/180", gaThreeLevel.ToString()); Assert.AreEqual("20/180", gaTwoLevel.ToString()); Assert.AreEqual("41140", gaFreeStyle.ToString()); }
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(); }
public void TunnelingActionFeedbackTest() { ResetEvent = new ManualResetEventSlim(); KnxConnection connection = new KnxConnectionTunneling("127.0.0.1", 3671, "127.0.0.1", 3672) { Debug = false }; connection.KnxEventDelegate += Event; connection.Connect(); Thread.Sleep(50); connection.Action(KnxGroupAddress.Parse(LightOnOffAddress), true); if (!ResetEvent.Wait(Timeout)) { Assert.Fail("Didn't receive feedback from the action"); } }
public void Parse_InputValue_CorrectSubGroup(string input, int expected) { KnxGroupAddress addr = KnxGroupAddress.Parse(input); Assert.Equal(expected, addr.SubGroup); }