Exemple #1
0
        private void OnTimerEvent(object source, ElapsedEventArgs e)
        {
            App app = (App)Application.Current;

            try
            {
                if (deviceCommand == null)
                {
                    if (app.nextCommands.Count > 0)
                    {
                        deviceCommand = app.nextCommands.Dequeue();
                        app.p.Write(deviceCommand.command);
                        //Console.WriteLine("Command: " + deviceCommand.command);
                    }
                }
                else
                {
                    DeviceCommand c = deviceCommand;
                    deviceCommand = null;
                    string deviceAnswer = app.p.ReadExisting();
                    if (deviceAnswer == null)
                    {
                        deviceAnswer = string.Empty;
                    }
                    //Console.WriteLine("Answer: " + deviceAnswer);
                    if (!c.handler.CheckAnswer(c.command, deviceAnswer))
                    {
                        MessageBox.Show("Command = " + c.command + ", answer = " + deviceAnswer,
                                        "Wrong device answer", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    if (app.nextCommands.Count == 0 && !disableCheckStatus)
                    {
                        app.nextCommands.Enqueue(new DeviceCommand("s", this));
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Comm port error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemple #2
0
        public MainWindow()
        {
            InitializeComponent();
            App app = (App)Application.Current;

            if (app.nextCommands != null)
            {
                if (app.settings.ContainsKey("window.position"))
                {
                    string[] parts = app.settings["window.position"].Split(';');
                    if (parts.Length == 4)
                    {
                        double x = double.Parse(parts[0]);
                        double y = double.Parse(parts[1]);
                        double w = double.Parse(parts[2]);
                        double h = double.Parse(parts[3]);
                        this.Left   = x;
                        this.Top    = y;
                        this.Width  = w;
                        this.Height = h;
                    }
                }
                drill.loadSettings(app.settings);
                heater1.loadSettings(app.settings);
                heater2.loadSettings(app.settings);
                heater3.loadSettings(app.settings);

                timer = new System.Timers.Timer(250);

                // Hook up the Elapsed event for the timer.
                timer.Elapsed += new ElapsedEventHandler(OnTimerEvent);
                timer.Enabled  = true;

                app.nextCommands.Enqueue(new DeviceCommand("s", this));//status
                deviceCommand      = null;
                disableCheckStatus = false;
            }
        }