コード例 #1
0
        static void Main(string[] args)
        {
            FileSystemWatcher watch;

            if (args.Length == 1)
            {
                LogQueue logQueue = new LogQueue(LOG_FILE_NAME + "_" + args[0] + ".log");
                Configs  config   = LeConfiguracao();
                watch = new FileSystemWatcher(CNTL_PATH, "*.ini");
                watch.NotifyFilter = NotifyFilters.LastWrite;
                FileSystemEventHandler evento = new FileSystemEventHandler(OnIniChanged);

                watch.Changed += evento;
                watch.Created += evento;
                watch.Deleted += evento;
                watch.Renamed += new RenamedEventHandler(OnIniChanged);


                watch.EnableRaisingEvents = true;
                connect = new ArduinoConnect(config, args[0]);
                Thread t = new Thread(logQueue.LogFile);
                t.Start();
                t = new Thread(connect.ReadFromPort);
                t.Start();
                Thread.Sleep(-1);
            }
        }
コード例 #2
0
        private void StartPorts()
        {
            ArduinoConnect arduinoConnect;

            do
            {
                foreach (string portName in SerialPort.GetPortNames())
                {
                    if (!mapConnects.ContainsKey(portName))
                    {
                        Console.WriteLine(portName);
                        Configs config = new Configs();
                        config.IsRepeat       = new bool[] { true, true, true, true, true, true, true, true, true, true, true };
                        config.ListRepeticoes = new Int32[] { 10, 20, 25, 2 };
                        config.SleepNotExist  = 30 * 60 * 1000;
                        config.SleepTime      = 1 * 1000;
                        arduinoConnect        = new ArduinoConnect(config, portName);
                        mapConnects.Add(portName, arduinoConnect);

                        Thread thread = new System.Threading.Thread(new ThreadStart(arduinoConnect.ReadFromPort));
                        thread.Start();
                    }
                }
                stopEvent.WaitOne(1000);
            } while (this.run);
            Console.WriteLine("Programa saindo");
            foreach (ArduinoConnect connect in mapConnects.Values)
            {
                connect.Stop();
            }
        }