diff --git a/CocktailWeb/Pages/Index.razor b/CocktailWeb/Pages/Index.razor index 6085c4a..cf453b0 100644 --- a/CocktailWeb/Pages/Index.razor +++ b/CocktailWeb/Pages/Index.razor @@ -1,4 +1,5 @@ @page "/" +@using System.IO.Ports Index @@ -6,4 +7,47 @@ Welcome to your new app. - + + + +

+ +

+ + + +@code { + SerialPort? port; + string? portname = "COM5"; + string? receivedText; + + public async Task SendData() + { + if (port == null && portname != null) + { + port = new SerialPort(portname); + port.BaudRate = 9600; + port.DataReceived += port_DataReceived; + port.DataBits = 8; + port.StopBits = StopBits.One; + port.Parity = Parity.None; + port.Handshake = Handshake.None; + port.RtsEnable = true; + + } + if (port == null || port.IsOpen) return; // Port konnte nicht initialisiert werden oder ist bereits geöffnet - dann nicht nochmal öffnen + port.Open(); + port.WriteLine(""); + + } + + private void port_DataReceived(object sender, SerialDataReceivedEventArgs e) + { + if (port != null) + { + var text = port.ReadExisting(); + receivedText = text; + port.Close(); + } + } +}