public static async Task Main(string[] args) { Console.WriteLine("Send IP:"); var sendIp = Console.ReadLine(); Console.WriteLine("Send port:"); var sendPort = Convert.ToInt32(Console.ReadLine()); var connection = new Connection(new IPEndPoint(IPAddress.Any, 45678), new IPEndPoint(IPAddress.Parse(sendIp), sendPort)); connection.Connected += (sender, response) => Console.WriteLine( $"Connected! CommunicationChannel: {response.CommunicationChannel} Status: {response.Status}"); connection.Disconnected += (sender, response) => Console.WriteLine( $"Disconnected! CommunicationChannel: {response.CommunicationChannel} Status: {response.Status}"); Console.WriteLine("c:\tConnect"); Console.WriteLine("d:\tDisconnect"); Console.WriteLine("s:\tSend"); Console.WriteLine("x:\tExit"); while (true) { var key = Console.ReadKey(); Console.SetCursorPosition(0, Console.CursorTop); switch (key.Key) { case ConsoleKey.C: Console.WriteLine("Connect"); connection.Connect(); break; case ConsoleKey.X: Console.WriteLine("Exit"); if (connection.IsConnected) { Console.WriteLine("Disconnect"); connection.Disconnect(); } return; case ConsoleKey.S: Console.WriteLine("Send"); await connection.SendAsync(MultiCastAddress.FromString(ReadLine("Address:")), KnxData.FromBoolean(Convert.ToBoolean(ReadLine("Value")))); break; case ConsoleKey.D: Console.WriteLine("Disconnect"); connection.Disconnect(); break; } } }
public TunnelRequest Build(byte headerLength, byte protocolVersion, ushort totalLength, byte[] responseBytes) { var structureLength = responseBytes[0]; var communicationChannel = responseBytes[1]; var sequenceCounter = responseBytes[2]; var messageCode = responseBytes[4]; var addInformationLength = responseBytes[5]; var controlField = responseBytes[6]; var controlField2 = responseBytes[7]; var npduLength = responseBytes[12]; return(new TunnelRequest(headerLength, protocolVersion, totalLength, structureLength, communicationChannel, sequenceCounter, messageCode, addInformationLength, controlField, controlField2, UniCastAddress.FromByteArray(new[] { responseBytes[8], responseBytes[9] }), MultiCastAddress.FromByteArray(new[] { responseBytes[10], responseBytes[11] }), npduLength, new[] { responseBytes[12], responseBytes[13] })); }
public TunnelRequest(byte headerLength, byte protocolVersion, ushort totalLength, byte structureLength, byte communicationChannel, byte sequenceCounter, byte messageCode, byte addInformationLength, byte controlField, byte controlField2, UniCastAddress sourceAddress, MultiCastAddress destinationAddress, byte npduLength, byte[] data) { HeaderLength = headerLength; ProtocolVersion = protocolVersion; TotalLength = totalLength; StructureLength = structureLength; CommunicationChannel = communicationChannel; SequenceCounter = sequenceCounter; MessageCode = messageCode; AddInformationLength = addInformationLength; ControlField = controlField; ControlField2 = controlField2; SourceAddress = sourceAddress; DestinationAddress = destinationAddress; NpduLength = npduLength; Data = data; }
public void ShouldThrowExceptionIfNotConnected() { var connection = GetConnection(); new Func <Task>(async() => await connection.SendAsync(MultiCastAddress.FromString("0/4/0"), KnxData.FromBoolean(false))).Should().Throw <NotConnectedException>(); }