async Task RealMain() { Init(); Sup.LogDebugMessage(message: "ZeroWsensors : ----------------------------"); Sup.LogDebugMessage(message: "ZeroWsensors : Entering Main"); Console.WriteLine($"{Sup.Version()} {Sup.Copyright}"); Sup.LogDebugMessage($"{Sup.Version()} {Sup.Copyright}"); Console.WriteLine("This program comes with ABSOLUTELY NO WARRANTY;\n" + "This is free software, and you are welcome to redistribute it under certain conditions."); Sup.LogDebugMessage("This program comes with ABSOLUTELY NO WARRANTY;\n" + "This is free software, and you are welcome to redistribute it under certain conditions."); #region MainLoop // Start the loop using (StreamWriter of = new StreamWriter("CUSensorArray.txt", true)) { int Clock = 0; do { string thisLine = ""; // Do this condional because the ctrl-c interrupt can be given aanywhere. Sup.LogTraceInfoMessage(message: "ZeroWsensors : Getting sensor values from the Main 10 second loop"); if (Continue) { Clock++; for (int i = 0; i < MaxNrSerialSensors; i++) { thisSerial[i].DoWork(); // Takes care of the reading of the serial devices } for (int i = 0; i < MaxNrI2cSensors; i++) { thisI2C[i].DoWork(); // Takes care of the reading of the I2C devices } // So we came here 6 times every 10 seconds. Create the minute values and remove the existing list, create a new one // The average values are always real averages even if some fetches failed in which case the list is shorter // This is the basic work of the sensor handler: fetch data and write to local logfile if (Clock == 6) { Clock = 0; for (int i = 0; i < MaxNrSerialSensors; i++) { thisSerial[i].SetMinuteValuesFromObservations(); } for (int i = 0; i < MaxNrI2cSensors; i++) { thisI2C[i].SetMinuteValuesFromObservations(); } // Now we do the AirLink handling which is assumed to be called once per minute with the observation list to create // all other necessary lists and calculated values from there if (AirLinkEmulation) { thisEmulator.DoAirLink(); // When all done Write out the values to SensorCommunity if (DoSensorCommunity) { await thisSensorCommunity.Send(thisEmulator); } } // Write out to the logfile for (int i = 0; i < MaxNrSerialSensors; i++) { thisLine += $";{thisSerial[ i ].MinuteValues.Pm1_atm:F1};{thisSerial[ i ].MinuteValues.Pm25_atm:F1};{thisSerial[ i ].MinuteValues.Pm10_atm:F1}"; } for (int i = 0; i < MaxNrI2cSensors; i++) { thisLine += $";{thisI2C[ i ].MinuteValues.TemperatureC:F1};{thisI2C[ i ].MinuteValues.Humidity:F0}"; } Sup.LogTraceInfoMessage(message: "ZeroWsensors : Writing out the data to the logfile"); Sup.LogTraceInfoMessage(message: $"{DateTime.Now:dd-MM-yyyy HH:mm}{thisLine}"); of.WriteLine($"{DateTime.Now:dd-MM-yyyy HH:mm}{thisLine}"); of.Flush(); } } // This is really hardcoded and should NOT change. The whole thing is based on 6 measurements per minute, so loop every 10 seconds Thread.Sleep(10000); } while (Continue); // Do-While } // Using the datafile #endregion Sup.LogDebugMessage("SensorArray Gracefull exit... End"); Trace.Flush(); Trace.Close(); return; } // Real main()