static async Task GetSensorsAll() { string response = null; //Interface Device SingletonDevice singletonDevice = SingletonDevice.Source; for (; ;) { response = singletonDevice.GetData("GET /sensors/all"); Console.WriteLine(response); await Task.Delay(1000); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapGet("/", async context => { //Interface Device SingletonDevice singletonDevice = SingletonDevice.Source; var response = singletonDevice.GetData("GET /sensors/all"); //await context.Response.WriteAsync("Hello World!"); await context.Response.WriteAsync(response); }); }); }
public static async Task Main(string[] args) { var exitEvent = new ManualResetEvent(false); Console.CancelKeyPress += (sender, eventArgs) => { eventArgs.Cancel = true; exitEvent.Set(); }; // try { //Logs log = LogManager.GetCurrentClassLogger(); log.Debug("Init Main"); log.Debug("Version: {0}", Environment.Version.ToString()); log.Debug("OS: {0}", Environment.OSVersion.ToString()); log.Debug("Command: {0}", Environment.CommandLine.ToString()); //base programm //Interface Device SingletonDevice singletonDevice = SingletonDevice.Source; //Run Console.WriteLine("Run!"); log.Debug("Run!"); Console.WriteLine("Serial ports available:"); log.Debug("Serial ports available:"); Console.WriteLine("-----------------------"); string CurrentportName = ""; foreach (var portName in SerialPort.GetPortNames()) { Console.WriteLine(portName); log.Debug(portName); CurrentportName = portName; } Console.WriteLine("-----------------------"); log.Debug("-----------------------"); Console.WriteLine("[Please press any key]"); Console.ReadLine(); // //string nameport = "COM12"; //string nameport = "/dev/ttyACM0"; //open COM-port singletonDevice.OpenSerialPort(CurrentportName); //Get Data Console.WriteLine("Get Data:"); log.Debug("Get Data:"); Console.WriteLine("[For Exit press CTRL+C:]"); //=== GetSensorsAll(); //===Run HTTP String[] s1 = new String[1]; s1[0] = ""; WeatherStationCubietruckHttp.Program.Main(args); //Wait exitEvent.WaitOne(); //=== //Console.WriteLine("[Please press any key]"); //Console.ReadLine(); } catch (Exception e) { //NLog: catch setup errors log.Error(e, "Stopped program because of exception"); throw; } finally { //Interface Device SingletonDevice singletonDevice = SingletonDevice.Source; if (singletonDevice.IsOpen) { singletonDevice.CloseSerialPort(); } Console.WriteLine(); Console.WriteLine("Exit App"); log.Debug("Exit App"); // Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux) NLog.LogManager.Shutdown(); } }