From 08cd3b374c6fb24dcfc1e83b788f3f3745b54d04 Mon Sep 17 00:00:00 2001 From: Tino Hager Date: Mon, 23 Sep 2024 10:21:21 +0200 Subject: [PATCH] simulator add log-off --- src/Portalum.Zvt.TerminalSimulator/Program.cs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/Portalum.Zvt.TerminalSimulator/Program.cs b/src/Portalum.Zvt.TerminalSimulator/Program.cs index 0c2368e..6009416 100644 --- a/src/Portalum.Zvt.TerminalSimulator/Program.cs +++ b/src/Portalum.Zvt.TerminalSimulator/Program.cs @@ -11,6 +11,8 @@ class Program static void Main(string[] args) { _tcpServer = new SimpleTcpServer("127.0.0.1", 20007); + _tcpServer.Events.ClientConnected += Events_ClientConnected; + _tcpServer.Events.ClientDisconnected += Events_ClientDisconnected; _tcpServer.Events.DataReceived += Events_DataReceived; _tcpServer.Start(); @@ -18,11 +20,23 @@ static void Main(string[] args) Console.WriteLine("Wait for connections, press any key for quit"); Console.ReadLine(); + _tcpServer.Events.ClientConnected -= Events_ClientConnected; + _tcpServer.Events.ClientDisconnected -= Events_ClientDisconnected; _tcpServer.Events.DataReceived -= Events_DataReceived; _tcpServer.Stop(); _tcpServer.Dispose(); } + private static void Events_ClientConnected(object? sender, ConnectionEventArgs e) + { + Console.WriteLine($"ClientConnected - {e.IpPort}"); + } + + private static void Events_ClientDisconnected(object? sender, ConnectionEventArgs e) + { + Console.WriteLine($"ClientDisconnected - {e.IpPort}"); + } + private static void Events_DataReceived(object? sender, DataReceivedEventArgs e) { if (_tcpServer == null) @@ -93,6 +107,19 @@ private static void Events_DataReceived(object? sender, DataReceivedEventArgs e) return; } + // Log-Off (06 02) + if (data.StartsWith(new byte[] { 0x06, 0x02 })) + { + Console.WriteLine($"Receive Log-Off - [{hexData}]"); + + Thread.Sleep(500); + + Console.WriteLine("Send Command Completion"); + _tcpServer.Send(e.IpPort, _commandCompletionPackage); + + return; + } + Console.WriteLine($"Unknown command for simulator - [{hexData}]"); } } \ No newline at end of file