Example #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting Dust Sensor");
            var    comPorts    = SerialPort.GetPortNames();
            string selectedCom = null;

            while (!comPorts.Contains(selectedCom))
            {
                Console.WriteLine("Select port");
                PrintComPorts(comPorts);
                var selectedPos = Console.ReadLine();
                if (!int.TryParse(selectedPos, out int index))
                {
                    continue;
                }
                if (index < 1 || index > comPorts.Length)
                {
                    continue;
                }

                selectedCom = comPorts[index - 1];
            }

            var com    = new SerialPort(selectedCom, 9600, Parity.None, 8, StopBits.One);
            var sensor = new SDS011();

            var engine = new Engine(com, sensor, Console.Out, 25, 50);

            engine.Start();

            Console.WriteLine("Press any key to exit");
            Console.ReadKey();

            engine.Stop();
        }
Example #2
0
 public MainForm()
 {
     InitializeComponent();
     random    = new Random();
     sds011    = SDS011.getInstance();
     timer1000 = new System.Threading.Timer(TimerTick1000, this, 5000, 1000);
     createChart();
 }
Example #3
0
 public static SDS011 getInstance()
 {
     if (self == null)
     {
         self = new SDS011();
     }
     return(self);
 }