/// <summary> /// Create a connection to the ADCP serial port with /// the given options. If no options are given, return null. /// </summary> /// <param name="options">Options to connect to the serial port.</param> /// <returns>Adcp Serial Port based off the options</returns> public AdcpSerialPort ConnectSerial(SerialOptions options) { // If there is a connection, disconnect if (_serialPort != null) { DisconnectSerial(); } if (options != null) { // Set the connection //Status.Status = eAdcpStatus.Connected; // Create the connection and connect _serialPort = new AdcpSerialPort(options); _serialPort.Connect(); // Publish that the ADCP serial port is new //PublishAdcpSerialConnection(); DisplayStatus(string.Format("Connect Serial: {0}", _serialPort.ToString())); // Set flag //IsAdcpFound = true; return(_serialPort); } return(null); }
/// <summary> /// Create a connection to the GPS serial port with /// the given options. If no options are given, return null. /// </summary> /// <param name="options">Options to connect to the serial port.</param> /// <returns>Adcp Serial Port based off the options</returns> public GpsSerialPort ConnectGpsSerial(SerialOptions options) { // If there is a connection, disconnect if (_gpsSerialPort != null) { DisconnectGpsSerial(); } if (options != null) { // Set the connection //Status.Status = eAdcpStatus.Connected; // Create the connection and connect _gpsSerialPort = new GpsSerialPort(options); _gpsSerialPort.Connect(); _gpsSerialPort.IsEnabled = true; // Subscribe to receive ADCP data _gpsSerialPort.ReceiveGpsSerialDataEvent += new GpsSerialPort.ReceiveGpsSerialDataEventHandler(ReceiveGpsSerialData); // Publish that the ADCP serial port is new //PublishAdcpSerialConnection(); DispalyStatus(string.Format("GPS Connect: {0}", _gpsSerialPort.ToString())); // Set flag //IsAdcpFound = true; return(_gpsSerialPort); } return(null); }
/// <summary> /// Initialize values. /// </summary> /// <param name="serialOptions"></param> public SerialConnection(SerialOptions serialOptions) { // Initialize ranges _serialOptions = serialOptions; // Serial port options try { _serialPort = new SerialPort(serialOptions.Port, serialOptions.BaudRate); // Serial port } catch (Exception) { // If the port is an old connection or no port is given and // that connection cannot be made, then it will throw an // Argument exception. This will then set the variable with no port. _serialPort = new SerialPort(); } // Initialize the thread _threadWait = new EventWaitHandle(false, EventResetMode.AutoReset); _threadInterval = DEFAULT_SERIAL_INTERVAL; _stopThread = false; _pauseReadThread = false; _isSendingData = false; _readThread = new Thread(new ParameterizedThreadStart(ReadThreadMethod)); _readThread.Priority = ThreadPriority.Normal; _readThread.Name = "Serial Connection"; //_readThread.Start(); _validateMsg = ""; }
/// <summary> /// Set the default values for all the options. /// /// Try to use the last ADCP/GPS serial option. If the /// last option was never set, then the default settings will /// still be used for the serial options. /// </summary> private void SetDefaults() { Revision = ProjectManagerDatabaseWriter.PULSE_TABLE_REVISION; PrjFolderPath = Pulse.Commons.GetProjectDefaultFolderPath(); FontSize = DEFAULT_FONT_SIZE; MaxFileSize = 1048576 * 50; // 50 MegaBytes AdcpCommType = AdcpConnection.AdcpCommTypes.Serial; AdcpSerialOptions = new SerialOptions(); Gps1SerialOptions = new SerialOptions(); Gps2SerialOptions = new SerialOptions(); Nmea1SerialOptions = new SerialOptions(); Nmea2SerialOptions = new SerialOptions(); IsGps1SerialEnabled = false; IsGps2SerialEnabled = false; IsNmea1SerialEnabled = false; IsNmea2SerialEnabled = false; EthernetOptions = new AdcpEthernetOptions(); PredictorUserInput = new PredictionModelInput(); SelectedProjectID = 0; ValidationViewOptions = new ValidationTestViewOptions(); GraphicalViewOptions = new ViewDataGraphicalOptions(); BackscatterOptions = new BackscatterOptions(); AverageOptions = new AverageOptions(); TankTestOptions = new TankTestOptions(); ViewDataWavesOptions = new ViewDataWavesOptions(); AdcpConfig = new AdcpConfiguration(); RecoverDataOptions = new RecoverDataOptions(); DataOutputOptions = new DataOutputViewOptions(); WpMagDirOutputOptions = new WpMagDirOutputViewOptions(); DataFormatOptions = new DataFormatOptions(); LastViewedPage = ViewNavEvent.ViewId.HomeView; }
/// <summary> /// Initalize the lists. /// </summary> /// <param name="name"></param> public InputTerminalViewModel(string name) { base.DisplayName = name; _outputVM = IoC.Get <OutputDataViewModel>(); _serialOptions = new SerialOptions(); CommPortList = SerialOptions.PortOptions; BaudRateList = SerialOptions.BaudRateOptions; SelectedBaud = 115200; GpsCommPortList = SerialOptions.PortOptions; _gpsSerialOptions = new SerialOptions(); SelectedGpsBaud = 9600; StatusOutput = ""; _adcpCodec = new AdcpCodec(); _adcpCodec.ProcessDataEvent += _adcpCodec_ProcessDataEvent; // Scan for ADCP command ScanAdcpCommand = ReactiveUI.Legacy.ReactiveCommand.Create(); ScanAdcpCommand.Subscribe(_ => ScanForAdcp()); // Disconnect Serial ConnectAdcpCommand = ReactiveUI.Legacy.ReactiveCommand.Create(); ConnectAdcpCommand.Subscribe(_ => ConnectAdcpSerial()); // Disconnect Serial DisconnectAdcpCommand = ReactiveUI.Legacy.ReactiveCommand.Create(); DisconnectAdcpCommand.Subscribe(_ => DisconnectAdcpSerial()); // Scan for GPS command ScanGpsCommand = ReactiveUI.Legacy.ReactiveCommand.Create(); ScanGpsCommand.Subscribe(_ => ScanForGps()); // Disconnect Serial ConnectGpsCommand = ReactiveUI.Legacy.ReactiveCommand.Create(); ConnectGpsCommand.Subscribe(_ => ConnectGpsSerial()); // Disconnect Serial DisconnectGpsCommand = ReactiveUI.Legacy.ReactiveCommand.Create(); DisconnectGpsCommand.Subscribe(_ => DisconnectGpsSerial()); // Start Pinging if not pinging StartPingingCommand = ReactiveUI.Legacy.ReactiveCommand.Create(); StartPingingCommand.Subscribe(_ => StartPinging()); // Stop Pinging if not pinging StopPingingCommand = ReactiveUI.Legacy.ReactiveCommand.Create(); StopPingingCommand.Subscribe(_ => StopPinging()); // Send the command to the ADCP SendAdcpCmdCommand = ReactiveUI.Legacy.ReactiveCommand.Create(); SendAdcpCmdCommand.Subscribe(_ => SendAdcpCommand()); }
/// <summary> /// Disconnect then connect with the new options given. /// </summary> /// <param name="options">Options to connect the ADCP serial port.</param> public void ReconnectSerial(SerialOptions options) { // Disconnect DisconnectSerial(); // Wait for Disconnect to finish Thread.Sleep(RTI.AdcpSerialPort.WAIT_STATE); // Connect ConnectSerial(options); }
/// <summary> /// Create a string of all the parameters and values for serial options. Then set them in the database. /// </summary> /// <param name="adcpSerialOptions">Serial port options.</param> public void SetLastPulseAdcpSerialOptions(SerialOptions adcpSerialOptions) { // Get the current options from the database // Then replace the ADCP serial options with the new options. PulseOptions options = GetPulseOptions(); if (adcpSerialOptions != null) { options.AdcpSerialOptions = adcpSerialOptions; } // Set the pulse options SetPulseOptions(options); }
/// <summary> /// Create a string of all the parameters and values for NMEA 2 serial options. Then set them in the database. /// </summary> /// <param name="enableNmeaSerial">Flag is NMEA 2 serial port is enabled.</param> /// <param name="nmeaSerialOptions">NMEA 2 serial port options.</param> public void SetLastPulseNmea2SerialOptions(bool enableNmeaSerial, SerialOptions nmeaSerialOptions) { // Get the current options from the database // Then replace the NMEA serial options with the new options. PulseOptions options = GetPulseOptions(); if (nmeaSerialOptions != null) { options.IsNmea2SerialEnabled = enableNmeaSerial; options.Nmea2SerialOptions = nmeaSerialOptions; } // Set the pulse options SetPulseOptions(options); }
/// <summary> /// Create a string of all the parameters and values for GPS 2 serial options. Then set them in the database. /// </summary> /// <param name="enableGpsSerial">Flag is GPS 2 serial port is enabled.</param> /// <param name="gpsSerialOptions">GPS 2 serial port options.</param> public void SetLastPulseGps2SerialOptions(bool enableGpsSerial, SerialOptions gpsSerialOptions) { // Get the current options from the database // Then replace the GPS serial options with the new options. PulseOptions options = GetPulseOptions(); if (gpsSerialOptions != null) { options.IsGps2SerialEnabled = enableGpsSerial; options.Gps2SerialOptions = gpsSerialOptions; } // Set the pulse options SetPulseOptions(options); }
/// <summary> /// Determine if the given object is equal to this /// object. This will check if the Status Value match. /// </summary> /// <param name="obj">Object to compare with this object.</param> /// <returns>TRUE = Status Value matched.</returns> public override bool Equals(object obj) { //Check for null and compare run-time types. if (obj == null || GetType() != obj.GetType()) { return(false); } SerialOptions p = (SerialOptions)obj; return(Port == p.Port && BaudRate == p.BaudRate && DataBits == p.DataBits && Parity == p.Parity && StopBits == p.StopBits); }
/// <summary> /// Initialize the object. /// </summary> public WpMagDirOutputViewModel() : base("Water Profile Direction and Magnitude Data Output") { base.DisplayName = "Data Output"; // Subscribe to receive ensembles _eventAggregator = IoC.Get <IEventAggregator>(); _eventAggregator.Subscribe(this); // Get PulseManager _pm = IoC.Get <PulseManager>(); _fileSizeMonitor = 0; // Get the options from the database GetOptionsFromDatabase(); FormatList = new List <string>(); FormatList.Add(WpMagDirOutputViewOptions.TRANSFORM_SHIP); FormatList.Add(WpMagDirOutputViewOptions.TRANSFORM_EARTH); FormatList.Add(WpMagDirOutputViewOptions.TRANSFORM_INSTRUMENT); HeadingSourceList = Enum.GetValues(typeof(Transform.HeadingSource)).Cast <Transform.HeadingSource>().ToList(); _serialOptions = new SerialOptions(); CommPortList = SerialOptions.PortOptions; BaudRateList = SerialOptions.BaudRateOptions; DataOutput = ""; // Scan for ADCP command ScanCommand = ReactiveUI.ReactiveCommand.Create(); ScanCommand.Subscribe(_ => ScanForSerialPorts()); // Disconnect Serial ConnectCommand = ReactiveUI.ReactiveCommand.Create(); ConnectCommand.Subscribe(_ => ConnectAdcpSerial()); // Disconnect Serial DisconnectCommand = ReactiveUI.ReactiveCommand.Create(); DisconnectCommand.Subscribe(_ => DisconnectSerial()); }
/// <summary> /// Set the Pulse options. /// </summary> /// <param name="prjFolderPath">Project folder path.</param> /// <param name="fontSize">Font Size.</param> /// <param name="maxFileSize">Max file size.</param> /// <param name="adcpCommType">ADCP Communication type.</param> /// <param name="adcpOptions">Adcp Serial Options.</param> /// <param name="isGps1Enabled">Flag if GPS 1 serial port is enabled.</param> /// <param name="isGps2Enabled">Flag if GPS 2 serial port is enabled.</param> /// <param name="isNmea1Enabled">Flag if NMEA 1 serial port is enabled.</param> /// <param name="isNmea2Enabled">Flag if NMEA 2 serial port is enabled.</param> /// <param name="gps1Options">Gps 1 Serial options.</param> /// <param name="gps2Options">Gps 2 Serial options.</param> /// <param name="nmea1Options">NMEA 1 Serial options.</param> /// <param name="nmea2Options">NMEA 2 Serial options.</param> /// <param name="ethernetOption">Ethernet options.</param> /// <param name="predictorUserInput">ADCP Predictor User Input.</param> /// <param name="selectedProjectID">Selected Project ID.</param> /// <param name="validationViewOptions">Validation View Options.</param> /// <param name="graphicalViewOptions">Graphical View Options.</param> /// <param name="backscatterOptions">Backscatter options.</param> /// <param name="averageOptions">Average Options.</param> /// <param name="tankTestOptions">Tank Test Options.</param> /// <param name="viewDataWavesOptions">Waves options.</param> /// <param name="adcpConfig">ADCP Config.</param> /// <param name="recoverDataOptions">Recover Data Options.</param> /// <param name="dataOutputOptions">Data Ouput Options.</param> /// <param name="wpMagDirOutputOptions">Water Profile Magnitude and Direction Output Options.</param> /// <param name="dataFormatOptions">Data Format Options.</param> /// <param name="lastViewedPage">Last paged view.</param> public PulseOptions(string prjFolderPath, int fontSize, int maxFileSize, AdcpConnection.AdcpCommTypes adcpCommType, SerialOptions adcpOptions, bool isGps1Enabled, bool isGps2Enabled, bool isNmea1Enabled, bool isNmea2Enabled, SerialOptions gps1Options, SerialOptions gps2Options, SerialOptions nmea1Options, SerialOptions nmea2Options, AdcpEthernetOptions ethernetOption, PredictionModelInput predictorUserInput, int selectedProjectID, ValidationTestViewOptions validationViewOptions, ViewDataGraphicalOptions graphicalViewOptions, BackscatterOptions backscatterOptions, AverageOptions averageOptions, TankTestOptions tankTestOptions, ViewDataWavesOptions viewDataWavesOptions, AdcpConfiguration adcpConfig, RecoverDataOptions recoverDataOptions, DataOutputViewOptions dataOutputOptions, WpMagDirOutputViewOptions wpMagDirOutputOptions, DataFormatOptions dataFormatOptions, ViewNavEvent.ViewId lastViewedPage) { PrjFolderPath = prjFolderPath; FontSize = fontSize; MaxFileSize = maxFileSize; AdcpCommType = adcpCommType; AdcpSerialOptions = adcpOptions; IsGps1SerialEnabled = isGps1Enabled; IsGps2SerialEnabled = isGps2Enabled; IsNmea1SerialEnabled = isNmea1Enabled; IsNmea2SerialEnabled = isNmea2Enabled; Gps1SerialOptions = gps1Options; Gps2SerialOptions = gps2Options; Nmea1SerialOptions = nmea1Options; Nmea2SerialOptions = nmea2Options; EthernetOptions = ethernetOption; PredictorUserInput = predictorUserInput; SelectedProjectID = selectedProjectID; ValidationViewOptions = validationViewOptions; GraphicalViewOptions = graphicalViewOptions; BackscatterOptions = backscatterOptions; AverageOptions = averageOptions; TankTestOptions = tankTestOptions; ViewDataWavesOptions = viewDataWavesOptions; AdcpConfig = adcpConfig; RecoverDataOptions = recoverDataOptions; DataOutputOptions = dataOutputOptions; WpMagDirOutputOptions = wpMagDirOutputOptions; DataFormatOptions = dataFormatOptions; LastViewedPage = lastViewedPage; }
/// <summary> /// Initialize values. /// </summary> public AdcpConfiguration() { // Initialize values SubsystemConfigDict = new Dictionary <string, AdcpSubsystemConfig>(); Commands = new AdcpCommands(); _serialNumber = new SerialNumber(); DeploymentOptions = new DeploymentOptions(); AdcpSerialOptions = new AdcpSerialPort.AdcpSerialOptions(); IsGps1SerialEnabled = false; IsGps2SerialEnabled = false; IsNmea1SerialEnabled = false; IsNmea2SerialEnabled = false; Gps1SerialOptions = new SerialOptions(); Gps2SerialOptions = new SerialOptions(); Nmea1SerialOptions = new SerialOptions(); Nmea2SerialOptions = new SerialOptions(); HardwareOptions = new EngConf(); EthernetOptions = new AdcpEthernetOptions(); VesselMountOptions = new VesselMountOptions(); EngPort = ""; AdditionalCommands = ""; }
/// <summary> /// Initialize values. /// </summary> public AdcpConfiguration(SerialNumber serial) { // Initialize values SubsystemConfigDict = new Dictionary <string, AdcpSubsystemConfig>(); Commands = new AdcpCommands(); _serialNumber = serial; SetCepo(_serialNumber.SubsystemsString(), _serialNumber); // Must go after Commands is created DeploymentOptions = new DeploymentOptions(); AdcpSerialOptions = new AdcpSerialPort.AdcpSerialOptions(); IsGps1SerialEnabled = false; IsGps2SerialEnabled = false; IsNmea1SerialEnabled = false; IsNmea2SerialEnabled = false; Gps1SerialOptions = new SerialOptions(); Gps2SerialOptions = new SerialOptions(); Nmea1SerialOptions = new SerialOptions(); Nmea2SerialOptions = new SerialOptions(); HardwareOptions = new EngConf(); EthernetOptions = new AdcpEthernetOptions(); VesselMountOptions = new VesselMountOptions(); EngPort = ""; AdditionalCommands = ""; }
/// <summary> /// Initialize the display. /// </summary> public void Init() { // Init the serial options _serialOption = new SerialOptions(); _serialPort = null; _AdcpCommandHistory = new ObservableCollection <string>(); StatusMsg = ""; RecordingSize = ""; _IsRecording = false; NotifyOfPropertyChange(() => IsRecording); _rawFileSize = 0; _rawAdcpRecordDir = ""; _rawAdcpRecordFile = null; RawAdcpRecordFileName = ""; _rawAdcpRecordFileLock = new object(); _IsConnected = false; SelectedBaudRate = 115200; SelectedDataBit = 8; SelectedParity = System.IO.Ports.Parity.None; SelectedStopBit = System.IO.Ports.StopBits.One; CommPortList = SerialOptions.PortOptions; BaudRateList = SerialOptions.BaudRateOptions; DataBitList = SerialOptions.DataBitsOptions; ParityList = SerialOptions.ParityOptions; StopBitList = SerialOptions.StopBitsOptions; NotifyOfPropertyChange(() => CommPortList); NotifyOfPropertyChange(() => BaudRateList); NotifyOfPropertyChange(() => DataBitList); NotifyOfPropertyChange(() => ParityList); NotifyOfPropertyChange(() => StopBitList); NotifyOfPropertyChange(() => IsConnected); }
/// <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); }
/// <summary> /// Constructor /// /// </summary> /// <param name="adcpSerialOptions"></param> public AdcpSerialPort(SerialOptions adcpSerialOptions) : base(adcpSerialOptions) { // Set the default mode to ADCP mode Mode = AdcpSerialModes.ADCP; }
/// <summary> /// Initialize all the values. /// </summary> public AdcpSerialOptions() { SerialOptions = new SerialOptions(); SerialNumber = new SerialNumber(); Hardware = ""; Firmware = new Firmware(); }
/// <summary> /// Test each baud rate until a good baud rate is found for the /// port given. /// /// A good baud rate is one that when the BREAK statement /// is decode, it has valid data. If the BREAK statement is /// garabage, it cannot be decoded. /// /// A quick way to decode the BREAK statement is to just check /// for a phrase in the buffer. /// </summary> /// <param name="port">Serial port to test.</param> /// <returns>Options to connect to the serial port.</returns> public AdcpSerialOptions TestSerialBaudConnection(string port) { // Get a list of all the baud rates List<int> bauds = SerialOptions.BaudRateOptions; // Ensure the the serial port is not open now if (IsOpen()) { Disconnect(); } // Test all the baud rates until one is found foreach (var baud in bauds) { // Create a serial connection _serialOptions = new SerialOptions(); _serialOptions.Port = port; _serialOptions.BaudRate = baud; Connect(); Thread.Sleep(AdcpSerialPort.WAIT_STATE); // Verify the connection was created if (IsOpen()) { // Stop pinging just in case StopPinging(); // Clear buffer ReceiveBufferString = ""; // Send a Break SendBreak(); // Wait for an output //Thread.Sleep(1000); // Get the buffer output string buffer = ReceiveBufferString; if (!string.IsNullOrEmpty(ReceiveBufferString)) { Debug.WriteLine("AdcpSerialPort.TestSerialBaudConnection(): " + ReceiveBufferString); //Decode the data to see if the response is not garabage if (ReceiveBufferString.Contains(" Rowe Technologies Inc.")) { // Decode the Break response Commands.BreakStmt breakStmt = Commands.AdcpCommands.DecodeBREAK(ReceiveBufferString); // Close the connection Disconnect(); // Return the options used to find the ADCP return new AdcpSerialOptions() { SerialOptions = _serialOptions, SerialNumber = breakStmt.SerialNum, Firmware = breakStmt.FirmwareVersion, Hardware = breakStmt.Hardware }; } else { // Nothing found for this baud rate so shutdown the connection Disconnect(); } } } } return null; }
/// <summary> /// Send a BREAK to the port. /// If there is no response, then it is /// probably not an ADCP. Even if the baud rate is /// wrong, the BREAK should send something back. /// </summary> /// <param name="port">Serial port to test.</param> /// <returns>TRUE = A response was give for the port.</returns> protected bool TestSerialPortConnection(string port) { try { // Shutdown the serial port if it is currently open if (IsOpen()) { Disconnect(); } // Create a serial connection _serialOptions = new SerialOptions(); _serialOptions.Port = port; Connect(); if (IsOpen()) { // Clear the buffer ReceiveBufferString = ""; // Send a break to the Port and see if there was a response string response = SendDataGetReply("", true, 500); // Send a BREAK and wait 0.5 seconds if (!string.IsNullOrEmpty(response)) { // Shutdown the connection Disconnect(); // Something responded return true; } // Shutdown the connection Disconnect(); } } catch (Exception e) { log.Error("Error Searching for an ADCP", e); Disconnect(); return false; } // Never got a response Disconnect(); return false; }
/// <summary> /// Create a GPS with the given options. /// </summary> /// <param name="gpsSerialOptions">Serial port options.</param> /// <param name="isEnabled">Flag if the port is enabled by default. Default value is false.</param> public GpsSerialPort(SerialOptions gpsSerialOptions, bool isEnabled = false) : base(gpsSerialOptions) { IsEnabled = isEnabled; }
/// <summary> /// Initialize the object. /// </summary> public DataOutputViewModel() : base("Data Output") { base.DisplayName = "Data Output"; // Subscribe to receive ensembles _eventAggregator = IoC.Get <IEventAggregator>(); _eventAggregator.Subscribe(this); // Get PulseManager _pm = IoC.Get <PulseManager>(); // Get the options from the database GetOptionsFromDatabase(); NumBinsSelected = 4; FormatList = new List <string>(); FormatList.Add(DataOutputViewOptions.ENCODING_Binary_ENS); FormatList.Add(DataOutputViewOptions.ENCODING_PD0); FormatList.Add(DataOutputViewOptions.ENCODING_PD6_PD13); FormatList.Add(DataOutputViewOptions.ENCODING_VMDAS); //FormatList.Add(ENCODING_PD0); //FormatList.Add(ENCODING_RETRANSFORM_PD6); CoordinateTransformList = new List <PD0.CoordinateTransforms>(); CoordinateTransformList.Add(PD0.CoordinateTransforms.Coord_Beam); CoordinateTransformList.Add(PD0.CoordinateTransforms.Coord_Instrument); CoordinateTransformList.Add(PD0.CoordinateTransforms.Coord_Ship); CoordinateTransformList.Add(PD0.CoordinateTransforms.Coord_Earth); HeadingSourceList = Enum.GetValues(typeof(Transform.HeadingSource)).Cast <Transform.HeadingSource>().ToList(); _serialOptions = new SerialOptions(); CommPortList = SerialOptions.PortOptions; BaudRateList = SerialOptions.BaudRateOptions; _manualWT = new VesselMount.VmManualWaterTrack(); NumBins = 200; DataOutput = ""; _codecVmDas = new VmDasAsciiCodec(); _codecPd6_13 = new EnsToPd6_13Codec(); // Bin List BinList = new List <int>(); for (int x = 1; x <= 200; x++) { BinList.Add(x); } // Scan for ADCP command ScanCommand = ReactiveUI.ReactiveCommand.Create(); ScanCommand.Subscribe(_ => ScanForSerialPorts()); // Disconnect Serial ConnectCommand = ReactiveUI.ReactiveCommand.Create(); ConnectCommand.Subscribe(_ => ConnectAdcpSerial()); // Disconnect Serial DisconnectCommand = ReactiveUI.ReactiveCommand.Create(); DisconnectCommand.Subscribe(_ => DisconnectSerial()); }
/// <summary> /// Initialize values. /// </summary> public AdcpConfiguration(SerialNumber serial) { // Initialize values SubsystemConfigDict = new Dictionary<string, AdcpSubsystemConfig>(); Commands = new AdcpCommands(); _serialNumber = serial; SetCepo(_serialNumber.SubsystemsString(), _serialNumber); // Must go after Commands is created DeploymentOptions = new DeploymentOptions(); AdcpSerialOptions = new AdcpSerialPort.AdcpSerialOptions(); Gps1SerialOptions = new SerialOptions(); Gps2SerialOptions = new SerialOptions(); Nmea1SerialOptions = new SerialOptions(); Nmea2SerialOptions = new SerialOptions(); HardwareOptions = new EngConf(); EthernetOptions = new AdcpEthernetOptions(); VesselMountOptions = new VesselMountOptions(); }
/// <summary> /// Display the object to a string. /// </summary> /// <returns>String of the object.</returns> public override string ToString() { string result = SerialOptions.ToString(); return(result); }
/// <summary> /// Test each baud rate until a good baud rate is found for the /// port given. /// /// A good baud rate is one that when the BREAK statement /// is decode, it has valid data. If the BREAK statement is /// garabage, it cannot be decoded. /// /// A quick way to decode the BREAK statement is to just check /// for a phrase in the buffer. /// </summary> /// <param name="port">Serial port to test.</param> /// <returns>Options to connect to the serial port.</returns> public AdcpSerialOptions TestSerialBaudConnection(string port) { // Get a list of all the baud rates List<int> bauds = SerialOptions.BaudRateOptions; //List<int> bauds = new List<int>(); //bauds.Add(115200); //bauds.Add(921600); ////bauds.Add(460800); ////bauds.Add(230400); ////bauds.Add(115200); ////bauds.Add(38400); //bauds.Add(19200); ////bauds.Add(9600); //bauds.Insert(0, SerialOptions.DEFAULT_BAUD); // Add this to the front of the list so the default is tried first to speed up the process // Ensure the the serial port is not open now if (IsOpen()) { Disconnect(); } // Test all the baud rates until one is found foreach (var baud in bauds) { // Create a serial connection _serialOptions = new SerialOptions(); _serialOptions.Port = port; _serialOptions.BaudRate = baud; Connect(); // Verify the connection was created if (IsOpen()) { // Clear the buffer ReceiveBufferString = ""; // Send a break to the Port and see if there was a response bool response = SendDataWaitReply(Commands.AdcpCommands.CMD_BREAK, 500); // True will send a break with no command Thread.Sleep(AdcpSerialPort.WAIT_STATE); // Wait to get the BREAK response, the initial response will be the echo back of BREAK if (response) { if (!string.IsNullOrEmpty(ReceiveBufferString)) { // Decode the data to see if the response is not garabage if (ReceiveBufferString.Contains(" Rowe Technologies Inc.")) { // Decode the Break response Commands.BreakStmt breakStmt = Commands.AdcpCommands.DecodeBREAK(ReceiveBufferString); // Close the connection Disconnect(); // Return the options used to find the ADCP return new AdcpSerialOptions() { SerialOptions = _serialOptions, SerialNumber = breakStmt.SerialNum, Firmware = breakStmt.FirmwareVersion, Hardware = breakStmt.Hardware }; } else { // Nothing found for this baud rate so shutdown the connection Disconnect(); } } } else { // Nothing found for this baud rate so shutdown the connection Disconnect(); } } } return null; }
/// <summary> /// Initialize the view model. /// </summary> public OutputDataViewModel(string name) { base.DisplayName = name; NumBinsSelected = 4; MinBin = 1; MaxBin = 200; SelectedFormat = ENCODING_PD6_PD13; FormatList = new List <string>(); FormatList.Add(ENCODING_Binary_ENS); FormatList.Add(ENCODING_PD0); FormatList.Add(ENCODING_PD6_PD13); FormatList.Add(ENCODING_VMDAS); //FormatList.Add(ENCODING_PD0); //FormatList.Add(ENCODING_RETRANSFORM_PD6); SelectedCoordTransform = PD0.CoordinateTransforms.Coord_Earth; CoordinateTransformList = new List <PD0.CoordinateTransforms>(); CoordinateTransformList.Add(PD0.CoordinateTransforms.Coord_Beam); CoordinateTransformList.Add(PD0.CoordinateTransforms.Coord_Instrument); CoordinateTransformList.Add(PD0.CoordinateTransforms.Coord_Ship); CoordinateTransformList.Add(PD0.CoordinateTransforms.Coord_Earth); _serialOptions = new SerialOptions(); CommPortList = SerialOptions.PortOptions; BaudRateList = SerialOptions.BaudRateOptions; _SelectedBaud = 115200; IsRetransformData = true; IsRecording = false; IsUseGpsHeading = true; HeadingOffset = 0.0f; ShipXdcrOffset = 0.0f; DataOutput = ""; _codecVmDas = new VmDasAsciiCodec(); _codecPd6_13 = new EnsToPd6_13Codec(); // Bin List BinList = new List <int>(); for (int x = 1; x <= 200; x++) { BinList.Add(x); } // Scan for ADCP command ScanCommand = ReactiveUI.Legacy.ReactiveCommand.Create(); ScanCommand.Subscribe(_ => ScanForSerialPorts()); // Disconnect Serial ConnectCommand = ReactiveUI.Legacy.ReactiveCommand.Create(); ConnectCommand.Subscribe(_ => ConnectAdcpSerial()); // Disconnect Serial DisconnectCommand = ReactiveUI.Legacy.ReactiveCommand.Create(); DisconnectCommand.Subscribe(_ => DisconnectSerial()); }
/// <summary> /// Initialize values. /// </summary> public AdcpConfiguration() { // Initialize values SubsystemConfigDict = new Dictionary<string, AdcpSubsystemConfig>(); Commands = new AdcpCommands(); _serialNumber = new SerialNumber(); DeploymentOptions = new DeploymentOptions(); AdcpSerialOptions = new AdcpSerialPort.AdcpSerialOptions(); Gps1SerialOptions = new SerialOptions(); Gps2SerialOptions = new SerialOptions(); Nmea1SerialOptions = new SerialOptions(); Nmea2SerialOptions = new SerialOptions(); HardwareOptions = new EngConf(); EthernetOptions = new AdcpEthernetOptions(); VesselMountOptions = new VesselMountOptions(); }