예제 #1
0
        static async Task MainAsync(string[] args)
        {
            try
            {
                CALog.LogInfoAndConsoleLn(LogID.A, RpiVersion.GetWelcomeMessage($"Upload temperature data to cloud"));
                Console.WriteLine("Initializing...");
                using (var serial = await SerialNumberMapper.DetectDevices())
                {
                    if (args.Length > 0 && args[0] == "-listdevices")
                    {
                        return; // SerialNumberMapper already lists devices, no need for further output.
                    }
                    // close all ports which are not Hub10
                    serial.McuBoards.Where(x => !x.productType.Contains("Temperature") && !x.productType.Contains("Hub10STM")).ToList().ForEach(x => x.SafeClose(System.Threading.CancellationToken.None).Wait());

                    var email = IOconfSetup.UpdateIOconf(serial);

                    using var cmd   = new CommandHandler(serial);
                    using var usb   = new ThermocoupleBox(cmd);
                    using var cloud = new ServerUploader(cmd.GetFullSystemVectorDescription(), cmd);
                    CALog.LogInfoAndConsoleLn(LogID.A, "Now connected to server...");
                    _ = Task.Run(() => cmd.RunSubsystems());

                    int i = 0;
                    var uploadThrottle = new TimeThrottle(100);
                    while (cmd.IsRunning)
                    {
                        var(sensorsSamples, vectorTime) = cmd.GetFullSystemVectorValues();
                        cloud.SendVector(sensorsSamples.Select(v => v.Value).ToList(), vectorTime);
                        Console.Write($"\r data points uploaded: {i++}"); // we don't want this in the log file.
                        uploadThrottle.Wait();
                        if (i == 20)
                        {
                            DULutil.OpenUrl(cloud.GetPlotUrl());
                        }
                    }
                }
                CALog.LogInfoAndConsoleLn(LogID.A, Environment.NewLine + "Bye..." + Environment.NewLine + "Press any key to exit");
            }
            catch (Exception ex)
            {
                ShowHumanErrorMessages(ex);
            }

            Console.ReadKey();
        }
        public async Task Scale()
        {
            //Set the scale in RS232 mode by holding MODE until display show Prt, then press TARA.
            //Then press MODE until you see 'Cont in', then press TARA. Then connect to COM port with 9600 baud.

            var mapper = await SerialNumberMapper.DetectDevices();

            var list = mapper.ByProductType("Scale");

            for (int i = 0; i < 50; i++)
            {
                string str = string.Empty;
                foreach (var scale in list)
                {
                    str += (await scale.SafeReadLine(CancellationToken.None)).Replace("\r", "      ");
                }

                Debug.Print(str);
            }
        }