Example #1
0
        private static void JSON_Init()
        {
            //json
            try
            {
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                StreamReader         sr         = File.OpenText("./Set.json"); // \\或者@"\"或者/或者./
                string set = sr.ReadToEnd();
                sr.Close();
                var p = serializer.Deserialize <JSON>(set);
                FilePath      = p.FilePath;
                mainLog       = new log(p.FilePath, p.MainLogName);
                tcpServer     = new TcpServer(p.TcpSeverPort, p.TcpSeverNum);
                gpio          = new GPIO(p.GpioGroup);
                com           = new SerialPort(p.SerialPortName, p.BaudRate, Parity.Even, 8, StopBits.One);
                Tcplog        = p.TcpLogName;
                Gpiolog       = p.GpioLogName;
                tansError     = p.TransErrorCount;
                serial_time   = p.SerialTime;
                cpu_time      = p.CpuLoopTime;
                timerInterval = p.TimerInterval;
                velocityMax   = p.VelocityCoeffient;
#if DEBUG
                currentLog = new log(p.FilePath, p.CurrentLogName);
                temp1Log   = new log(p.FilePath, p.Temp1Logname);
                temp2Log   = new log(p.FilePath, p.Temp2Logname);
                temp3Log   = new log(p.FilePath, p.Temp3Logname);
                temp4Log   = new log(p.FilePath, p.Temp4Logname);
#endif
                Console.WriteLine("初始化对象成功");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Console.WriteLine("初始化对象失败");
            }
        }