Пример #1
0
        void MonitorThread()
        {
            waitHandles.Add(mStopEvent);
            while (true)
            {
                int i = WaitHandle.WaitAny(waitHandles.ToArray());
                if (i == waitHandles.Count() - 1)
                {
                    break;
                }
                else
                {
                    SerialMonitor smonitor = serials[i];
                    AddStatus(smonitor);
                }
            }

            Uninit();
        }
Пример #2
0
        public void Init()
        {
            String s          = System.IO.File.ReadAllText(System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Serialconfig.json"));
            var    serializer = new JavaScriptSerializer();

            config = (Dictionary <String, Object>)serializer.DeserializeObject(s);

            //var seriportLabels = new JavaScriptSerializer();
            //var portlabels = (Dictionary<String, Object>)serializer.DeserializeObject(Settings.Default.PORTLABELS);

            //var seri = new JavaScriptSerializer();
            //var StripIndex = (Dictionary<String, Object>)serializer.DeserializeObject(Settings.Default.STRIPINDEX);

            //config["portlabel"] = portlabels["portlabel"];
            //config["stripindexs"] = StripIndex["stripindexs"];

            //GroupCnt = (((Object[])config["portlabel"]).ToArray(typeof(int))).Length;
            GroupCnt = ((Object[])config["portlabel"]).Cast <int>().ToArray().Length;

            List <string> sComsConfig = ((Object[])config["serialports"]).Select(i => i.ToString()).ToList();//GetColorSensorPorts();

            Program.logIt($"Config file include:{String.Join(", ", sComsConfig.ToArray())}");

            List <string> sComsPC = GetColorSensorPorts();

            Program.logIt($"System Exists include:{String.Join(", ", sComsPC.ToArray())}");

            List <String> sComs = sComsConfig.Intersect(sComsPC).ToList();

            Program.logIt($"serial coms count {sComs.Count}");

            if (sComsConfig.Count == 1 && sComsPC.Count == 1)
            {
                Program.logIt($"using pc list serial port, because config 1 com.");
                sComs = sComsPC;
            }
            //if (config.ContainsKey("serialports"))
            //{
            //    if (((Object[])config["serialports"]).Length > 1)
            //    {
            //        sComs = ((Object[])config["serialports"]).Cast<String>().ToList();
            //    }
            //}

            int index = 0;

            for (int i = 0; i < sComs.Count; i++)
            {
                String sComName = sComs[i];

                {
                    SerialMonitor sertmp = new SerialMonitor();
                    sertmp.Index = index++;

                    Program.logIt($"{sComName} opening");
                    int iretry = 5;

                    while (!sertmp.Open(sComName))
                    {
                        Thread.Sleep(1000);
                        if (iretry-- < 0)
                        {
                            break;
                        }
                    }
                    //if (!Settings.Default.LIGHTLED)
                    //{
                    //    sertmp.SendData("N\r");
                    //    sertmp.SendData("N\r");
                    //}
                    serials.Add(sertmp);
                    waitHandles.Add(sertmp.mDataEvent);
                }
            }

            MAX_Groupt = serials.Count();

            status_leds = new RGB[GroupCnt * MAX_Groupt];
            for (int i = 0; i < GroupCnt * MAX_Groupt; i++)
            {
                status_leds[i] = new RGB(0, 0, 0);
            }

            for (int i = 1; i <= arduinoServer.Properties.Settings.Default.MAX_SUPPORT_LABEL; i++)
            {
                buttonstatus[i] = false;
            }

            Thread.Sleep(5000);
            //Cleanup();

            Thread thread1 = new Thread(MonitorThread);

            thread1.Start();

            EZUSB ezUSB = new EZUSB();

            ezUSB.AddUSBEventWatcher(USBEventHandler, USBEventHandler, new TimeSpan(0, 0, 1));

            FinishInit = true;
        }