laatzen/Common/TempFlansh/Program.cs
2022-04-06 10:42:16 +02:00

74 lines
2.4 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Pipes;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TempFlansh
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Console.WriteLine("Comport");
short cport = short.Parse(Console.ReadLine());
var ap = TempHelper.UniversalOpenCom(cport, 4800, 8, 0, 0);
var helper = new TempHelper();
var filename = $"{DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")}_temp.log";
//while (true)
//{
// var outT = $"{DateTime.Now} {helper.ReadCurrentDisplayValue().ToString()}";
// File.AppendAllLines(filename, new List<string>() { outT });
// Console.WriteLine(outT);
// Thread.Sleep(1000);
//}
using (NamedPipeServerStream pipeServer = new NamedPipeServerStream("TempPipe", PipeDirection.Out))
{
Console.WriteLine("NamedPipeServerStream object created.");
// Wait for a client to connect
Console.Write("Waiting for client connection...");
pipeServer.WaitForConnection();
Console.Write("Open Comport");
Console.WriteLine("Client connected.");
try
{
// Read user input and send that to the client process.
using (StreamWriter sw = new StreamWriter(pipeServer))
{
sw.AutoFlush = true;
while (true)
{
sw.WriteLine(helper.ReadCurrentDisplayValue().ToString());
Thread.Sleep(100);
}
}
}
// Catch the IOException that is raised if the pipe is broken
// or disconnected.
catch (IOException e)
{
Console.WriteLine("ERROR: {0}", e.Message);
}
}
//Application.EnableVisualStyles();
//Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new Form1());
}
}
}