/// <summary>
        /// Initialize the values.
        /// </summary>
        public HomeViewModel()
        {
            // Set the list
            CommPortList = SerialOptions.PortOptions;
            BaudRateList = SerialOptions.BaudRateOptions;

            // Setup plot
            VelPlot = new BinPlot3D();
            VelPlot.CylinderRadius = 0;
            VelPlot.ColormapBrushSelection = ColormapBrush.ColormapBrushEnum.Jet;
            VelPlot.MinVelocity = Settings.Default.MinVelocity;
            VelPlot.MaxVelocity = Settings.Default.MaxVelocity;

            Legend = new ContourPlotLegendViewModel(VelPlot.ColormapBrushSelection, VelPlot.MinVelocity, VelPlot.MaxVelocity);

            PlotSize = Settings.Default.PlotSize;

            // Try to select any available comm ports
            if (!string.IsNullOrEmpty(Settings.Default.AdcpCommPort))
            {
                _SelectedAdcpCommPort = Settings.Default.AdcpCommPort;
                RaisePropertyChangedEventImmediately("SelectedAdcpCommPort");
            }
            else if (CommPortList.Count > 0)
            {
                _SelectedAdcpCommPort = CommPortList[0];
                RaisePropertyChangedEventImmediately("SelectedAdcpCommPort");
            }

            // Output Serial Port
            if (!string.IsNullOrEmpty(Settings.Default.OutputCommPort))
            {
                _SelectedOutputCommPort = Settings.Default.OutputCommPort;
                RaisePropertyChangedEventImmediately("SelectedOutputCommPort");
            }
            else if (CommPortList.Count > 1)
            {
                _SelectedOutputCommPort = CommPortList[1];
                RaisePropertyChangedEventImmediately("SelectedOutputCommPort");
            }

            // Get the latest baud rates
            _SelectedAdcpBaudRate = Settings.Default.AdcpBaud;
            _SelectedOutputBaudRate = Settings.Default.OutputBaud;
            RaisePropertyChangedEventImmediately("SelectedAdcpBaudRate");
            RaisePropertyChangedEventImmediately("SelectedOutputBaudRate");

            // Create the Serial options
            _adcpSerialOptions = new SerialOptions() { Port = SelectedAdcpCommPort, BaudRate = SelectedAdcpBaudRate };
            _outputSerialOptions = new SerialOptions() { Port = _SelectedOutputCommPort, BaudRate = SelectedOutputBaudRate };

            // Create codec to decode the data
            // Subscribe to process event
            _binaryCodec = new AdcpBinaryCodec();
            _binaryCodec.ProcessDataEvent += new AdcpBinaryCodec.ProcessDataEventHandler(_binaryCodec_ProcessDataEvent);

            // Initialize the list to accumulate a running average
            _runningAvgBuffer = new List<AvgData>();

            // Initialize output buffer
            _outputBuffer = new AvgDataBuffer();

            // Create the timer
            CreateTimer();

            // Try to connect the serial ports
            ConnectAdcp();
            ConnectOutputSerialPort();

            // Settings ViewModel
            SettingsVM = new SettingsViewModel(this);
        }
예제 #2
0
        /// <summary>
        /// Initialize all the codecs.
        /// </summary>
        public AdcpCodec()
        {
            // Counters
            _binaryCounter = 0;
            _dvlCounter = 0;
            _pd0Counter = 0;
            _pd6_13Counter = 0;
            _pd4_5Counter = 0;

            // Binary Codecs
            _binaryCodec = new AdcpBinaryCodec();
            _binaryCodec.ProcessDataEvent += new AdcpBinaryCodec.ProcessDataEventHandler(_binaryCodec_ProcessDataEvent);
            _binaryCodec.ProcessDataCompleteEvent += binaryCodec_ProcessDataCompleteEvent;

            // DVL Codec
            _dvlCodec = new AdcpDvlCodec();
            _dvlCodec.ProcessDataEvent += new AdcpDvlCodec.ProcessDataEventHandler(_dvlCodec_ProcessDataEvent);
            _dvlCodec.ProcessDataCompleteEvent += dvlCodec_ProcessDataCompleteEvent;

            // PD0 Codec
            _pd0Codec = new Pd0Codec();
            _pd0Codec.ProcessDataEvent += new Pd0Codec.ProcessDataEventHandler(_pd0Codec_ProcessDataEvent);
            _pd0Codec.ProcessDataCompleteEvent += pd0Codec_ProcessDataCompleteEvent;

            // PD6 and PD13 Codec
            _pd6_13Codec = new Pd6_13Codec();
            _pd6_13Codec.ProcessDataEvent += new Pd6_13Codec.ProcessDataEventHandler(_pd6_13Codec_ProcessDataEvent);
            _pd6_13Codec.ProcessDataCompleteEvent += pd6_13Codec_ProcessDataCompleteEvent;

            // PD4 and PD5 Codec
            _pd4_5Codec = new PD4_5Codec();
            _pd4_5Codec.ProcessDataEvent += new PD4_5Codec.ProcessDataEventHandler(_pd4_5Codec_ProcessDataEvent);
            _pd4_5Codec.ProcessDataCompleteEvent += pd4_5Codec_ProcessDataCompleteEvent;
        }