Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();

            var config = SettingsData.Load();

            measurementInterval = Convert.ToDouble(config.MeasurementSettingsData.Interval);
            measurementRunning  = false;

            HorizontalScaleMin = Convert.ToInt16(config.DisplaySettingsData.MinX);
            HorizontalScaleMax = Convert.ToInt16(config.DisplaySettingsData.MaxX);
            VerticalScaleMin   = Convert.ToInt16(config.DisplaySettingsData.MinY);
            VerticalScaleMax   = Convert.ToInt16(config.DisplaySettingsData.MaxY);

#if USE_DISPATCH_TIMER
            dispatchTimer          = new DispatcherTimer();
            dispatchTimer.Interval = TimeSpan.FromMilliseconds(measurementInterval);
            dispatchTimer.Tick    += TimerTick;
#else
            enableMeasurement = false;
#endif
            plotViewModel           = DataContext as PlotViewModel;
            plotViewModel.TimeFrame = (HorizontalScaleMax - HorizontalScaleMin);
            plotViewModel.Interval  = measurementInterval / 1000.0;
#if NOT_USED
            plotViewModel.ActionOccurred += PlotViewModelActionOccurred;
#endif

            sensor = new ZX2_SF11();

            OpenSerialPort();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Opens a new serial port connection.
        /// </summary>
        private void OpenSerialPort()
        {
            if (serialPort != null)
            {
                MessageBox.Show("Serial port is already opened!", "Serial Port", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                var config = SettingsData.Load();
                serialPort           = new SerialPort(config.SerialPortSettingsData.PortNum);
                serialPort.BaudRate  = config.SerialPortSettingsData.BaudRate;
                serialPort.Parity    = config.SerialPortSettingsData.Parity;
                serialPort.StopBits  = config.SerialPortSettingsData.StopBit;
                serialPort.DataBits  = config.SerialPortSettingsData.Databit;
                serialPort.Handshake = config.SerialPortSettingsData.FlowControl;

                // Data received event
                serialPort.DataReceived += new SerialDataReceivedEventHandler(SerialDataReceivedHandler);

                try
                {
                    serialPort.Open();
                }
                catch (Exception e)
                {
                    var asmatt = (System.Reflection.AssemblyTitleAttribute)Attribute.GetCustomAttribute(System.Reflection.Assembly.GetExecutingAssembly(),
                                                                                                        typeof(System.Reflection.AssemblyTitleAttribute));
                    MessageBox.Show(e.Message, asmatt.Title, MessageBoxButton.OK, MessageBoxImage.Error);

                    serialPort.Dispose();
                    serialPort = null;
                }
            }
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            var config = SettingsData.Load();

            cmbMinX.Text = config.DisplaySettingsData.MinX.ToString();
            cmbMaxX.Text = config.DisplaySettingsData.MaxX.ToString();
            cmbMinY.Text = config.DisplaySettingsData.MinY.ToString();
            cmbMaxY.Text = config.DisplaySettingsData.MaxY.ToString();
        }
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            var config = SettingsData.Load();

            config.MeasurementSettingsData.Interval = cmbInterval.Text;
            config.Save();

            // Accept the dialog and return the dialog result
            this.DialogResult = true;
            this.Close();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// インスタンスの取得
        /// </summary>
        /// <returns></returns>
        public static SettingsData GetInstance()
        {
            if (_currentSettings == null)
            {
                _currentSettings = SettingsData.Load();
                if (_currentSettings == null)
                {
                    _currentSettings = new SettingsData();
                }
            }

            return(_currentSettings);
        }
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            var config = SettingsData.Load();

            config.DisplaySettingsData.MinX = cmbMinX.Text;
            config.DisplaySettingsData.MaxX = cmbMaxX.Text;
            config.DisplaySettingsData.MinY = cmbMinY.Text;
            config.DisplaySettingsData.MaxY = cmbMaxY.Text;
            config.Save();

            // Accept the dialog and return the dialog result
            this.DialogResult = true;
            this.Close();
        }
Ejemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void StartMeasurement_Click(object sender, RoutedEventArgs e)
        {
            var config = SettingsData.Load();

            measurementInterval    = Convert.ToInt16(config.MeasurementSettingsData.Interval);
            plotViewModel.Interval = measurementInterval / 1000.0;
#if USE_DISPATCH_TIMER
            dispatchTimer.Interval = TimeSpan.FromMilliseconds(measurementInterval);
            dispatchTimer.Start();
#else
            measureThread = new System.Threading.Thread(new System.Threading.ThreadStart(StartMeasurement));
            measureThread.Start();
#endif
            measurementRunning = true;
        }
Ejemplo n.º 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MenuItem_View_AdjustGraph_Click(object sender, RoutedEventArgs e)
        {
            DisplaySettingsWindow sw = new DisplaySettingsWindow();

            sw.Owner = this;
            Nullable <bool> dialogResult = sw.ShowDialog();

            if (dialogResult == true)
            {
                var config = SettingsData.Load();
                HorizontalScaleMin = Convert.ToInt16(config.DisplaySettingsData.MinX);
                HorizontalScaleMax = Convert.ToInt16(config.DisplaySettingsData.MaxX);
                VerticalScaleMin   = Convert.ToInt16(config.DisplaySettingsData.MinY);
                VerticalScaleMax   = Convert.ToInt16(config.DisplaySettingsData.MaxY);
            }
        }
Ejemplo n.º 9
0
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            var config = SettingsData.Load();

            config.SerialPortSettingsData.PortNum     = cmbPortNo.Text;
            config.SerialPortSettingsData.BaudRate    = int.Parse(cmbRate.Text);
            config.SerialPortSettingsData.Databit     = int.Parse(cmbData.Text);
            config.SerialPortSettingsData.Parity      = (Parity)Enum.Parse(typeof(Parity), cmbParity.Text);
            config.SerialPortSettingsData.StopBit     = (StopBits)Enum.Parse(typeof(StopBits), cmbStopBit.Text);
            config.SerialPortSettingsData.FlowControl = (Handshake)Enum.Parse(typeof(Handshake), cmbFlowCtl.Text);
            config.Save();

            // Accept the dialog and return the dialog result
            this.DialogResult = true;
            this.Close();
        }
Ejemplo n.º 10
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
#if false
            // Center window with respect to MainWindow
            Application curApp     = Application.Current;
            Window      mainWindow = curApp.MainWindow;
            this.Left = mainWindow.Left + (mainWindow.Width - this.ActualWidth) / 2;
            this.Top  = mainWindow.Top + (mainWindow.Height - this.ActualHeight) /
#endif
            var config = SettingsData.Load();
            cmbPortNo.Text  = config.SerialPortSettingsData.PortNum;
            cmbRate.Text    = config.SerialPortSettingsData.BaudRate.ToString();
            cmbData.Text    = config.SerialPortSettingsData.Databit.ToString();
            cmbParity.Text  = config.SerialPortSettingsData.Parity.ToString();
            cmbStopBit.Text = config.SerialPortSettingsData.StopBit.ToString();
            cmbFlowCtl.Text = config.SerialPortSettingsData.FlowControl.ToString();
        }
Ejemplo n.º 11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MenuItem_Settings_Measurement_Click(object sender, RoutedEventArgs e)
        {
            MeasurementSettingsWindow sw = new MeasurementSettingsWindow();

            sw.Owner = this;
            Nullable <bool> dialogResult = sw.ShowDialog();

            if (dialogResult == true && measurementRunning == true)
            {
                dispatchTimer.Stop();

                var config = SettingsData.Load();
                measurementInterval    = Convert.ToInt16(config.MeasurementSettingsData.Interval);
                dispatchTimer.Interval = TimeSpan.FromMilliseconds(measurementInterval);

                dispatchTimer.Start();
            }
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            var config = SettingsData.Load();

            cmbInterval.Text = config.MeasurementSettingsData.Interval.ToString();
        }