Exemplo n.º 1
0
 void SendReadCommand(string cmd)
 {
     CommPort.ReadExisting();
     logger.Verbose($"Sent ReadCmd:{cmd}	");
     cmd += "?\r";
     CommPort.Write(cmd);
 }
Exemplo n.º 2
0
        protected override void OnStartup(StartupEventArgs e)
        {
            if (e.Args.Length != 1)
            {
                MessageBox.Show("usage: gen_freq_meter_level_meter [port_name]", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                Shutdown(1);
                return;
            }

            if (!"NODEVICE".Equals(e.Args[0]))
            {
                string answer;

                try
                {
                    p              = new CommPort(e.Args[0], string.Empty);
                    p.ReadTimeout  = 300;
                    p.WriteTimeout = 300;
                    p.Open();
                    p.Write("I");
                    Thread.Sleep(100);
                    answer = p.ReadExisting();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Comm port openning error", MessageBoxButton.OK, MessageBoxImage.Error);
                    Shutdown(2);
                    return;
                }

                if (answer != "GNFMLM10")
                {
                    MessageBox.Show("Wrong device answer to identify command: " + (answer == null ? string.Empty : answer), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    Shutdown(3);
                    return;
                }

                nextCommands = new Queue <DeviceCommand>();
            }
            else
            {
                nextCommands = null;
            }

            settings = new Dictionary <string, string>();
            if (File.Exists(settingsFile))
            {
                foreach (string line in File.ReadAllLines(settingsFile))
                {
                    string[] parts = line.Split(' ');
                    if (parts.Length == 2)
                    {
                        settings.Add(parts[0], parts[1]);
                    }
                }
            }

            base.OnStartup(e);
        }
Exemplo n.º 3
0
        protected override void OnStartup(StartupEventArgs e)
        {
            if (e.Args.Length != 1)
            {
                MessageBox.Show("usage: lmeter [port_name]", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                Shutdown(1);
                return;
            }

            string answer;

            try
            {
                p              = new CommPort(e.Args[0], string.Empty);
                p.ReadTimeout  = 300;
                p.WriteTimeout = 300;
                p.Open();
                p.Write("I");
                Thread.Sleep(100);
                answer = p.ReadExisting();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Comm port opening error", MessageBoxButton.OK, MessageBoxImage.Error);
                Shutdown(2);
                return;
            }

            if (answer != "LMETER1.0")
            {
                MessageBox.Show("Wrong device answer to identify command: " + (answer == null ? string.Empty : answer), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                Shutdown(3);
                return;
            }

            string cs = ConfigurationManager.AppSettings["C"];

            if (cs == null || !double.TryParse(cs, out c))
            {
                MessageBox.Show("Wrong C parameter: " + (cs == null ? string.Empty : cs), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                Shutdown(4);
                return;
            }

            base.OnStartup(e);
        }
Exemplo n.º 4
0
        bool GetCommandResponse(int timeout, out string response)
        {
            var flag = false;

            response = string.Empty;
            var stopwatch = Stopwatch.StartNew();

            while (stopwatch.ElapsedMilliseconds < timeout + 250)
            {
                if (CommPort.BytesToRead > 0)
                {
                    response += CommPort.ReadExisting();
                    if (response.StartsWith("\r\n", StringComparison.Ordinal))
                    {
                        response = response.TrimStart('\r', '\n');
                    }

                    if (!response.Contains("\r\n", StringComparison.Ordinal))
                    {
                        continue;
                    }

                    flag = true;
                    break;
                }

                Thread.CurrentThread.Join(200);
            }

            if (!flag)
            {
                logger.Verbose($" *** Cmd Response: Timeout:{stopwatch.ElapsedMilliseconds}msec resp:'{response}'");
                responding = false;
                return(false);
            }

            response = response.Replace("OK:", string.Empty, StringComparison.OrdinalIgnoreCase)
                       .Replace("\r\n", string.Empty, StringComparison.OrdinalIgnoreCase);
            return(true);
        }
Exemplo n.º 5
0
        protected override void OnStartup(StartupEventArgs e)
        {
            if (e.Args.Length != 1)
            {
                MessageBox.Show("usage: charger [port_name]", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                Shutdown(1);
                return;
            }

            string answer;

            try
            {
                p              = new CommPort(e.Args[0], string.Empty);
                p.ReadTimeout  = 300;
                p.WriteTimeout = 300;
                p.Open();
                p.Write("I\r");
                Thread.Sleep(100);
                answer = p.ReadExisting();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Comm port opening error", MessageBoxButton.OK, MessageBoxImage.Error);
                Shutdown(2);
                return;
            }

            if (answer != "CHG10")
            {
                MessageBox.Show("Wrong device answer to identify command: " + (answer == null ? string.Empty : answer), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                Shutdown(3);
                return;
            }

            base.OnStartup(e);
        }
Exemplo n.º 6
0
        protected override void OnStartup(StartupEventArgs e)
        {
            if (e.Args.Length != 1)
            {
                MessageBox.Show("usage: drillironc [port_name]", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                Shutdown(1);
                return;
            }

            string answer;

            try
            {
                p              = new CommPort(e.Args[0], string.Empty);
                p.ReadTimeout  = 300;
                p.WriteTimeout = 300;
                p.Open();
                p.Write("I");
                Thread.Sleep(100);
                answer = p.ReadExisting();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Comm port opening error", MessageBoxButton.OK, MessageBoxImage.Error);
                Shutdown(2);
                return;
            }

            if (answer != "DRILLIRONC1.0")
            {
                MessageBox.Show("Wrong device answer to identify command: " + (answer == null ? string.Empty : answer), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                Shutdown(3);
                return;
            }

            drill_title   = ConfigurationManager.AppSettings["drill_title"];
            program_title = ConfigurationManager.AppSettings["program_title"];

            heaterProfiles = new List <HeaterProfile> [3];
            for (int i = 0; i < 3; i++)
            {
                heaterProfiles[i] = new List <HeaterProfile>();
            }
            for (int i = 1; ; i++)
            {
                double multipler, adder;
                int    heaterID;
                string prefix    = "profile" + i;
                string parameter = prefix + "_title";
                string title     = ConfigurationManager.AppSettings[parameter];
                if (title == null)
                {
                    break;
                }
                parameter = prefix + "_heaterID";
                string value = ConfigurationManager.AppSettings[parameter];
                if (value == null || !int.TryParse(value, out heaterID) || heaterID < 1 || heaterID > 3)
                {
                    MessageBox.Show("Wrong " + parameter + " parameter: " + (value == null ? string.Empty : value), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    Shutdown(4);
                    return;
                }
                parameter = prefix + "_adder";
                value     = ConfigurationManager.AppSettings[parameter];
                if (value == null || !double.TryParse(value, out adder))
                {
                    MessageBox.Show("Wrong " + parameter + " parameter: " + (value == null ? string.Empty : value), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    Shutdown(4);
                    return;
                }
                parameter = prefix + "_multipler";
                value     = ConfigurationManager.AppSettings[parameter];
                if (value == null || !double.TryParse(value, out multipler) || multipler == 0)
                {
                    MessageBox.Show("Wrong " + parameter + " parameter: " + (value == null ? string.Empty : value), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    Shutdown(4);
                    return;
                }
                parameter = prefix + "_dual_temp";
                value     = ConfigurationManager.AppSettings[parameter];
                bool dual_temp_enabled = value != null && value.Equals("true", StringComparison.OrdinalIgnoreCase);
                heaterProfiles[heaterID - 1].Add(new HeaterProfile(title, i, heaterID, multipler, adder, dual_temp_enabled));
            }
            nextCommands = new Queue <DeviceCommand>();
            settings     = new Dictionary <string, string>();
            if (File.Exists(settingsFile))
            {
                foreach (string line in File.ReadAllLines(settingsFile))
                {
                    string[] parts = line.Split(' ');
                    if (parts.Length == 2)
                    {
                        settings.Add(parts[0], parts[1]);
                    }
                }
            }
            base.OnStartup(e);
        }