Ejemplo n.º 1
0
        private void openClosePortBtn_Click(object sender, EventArgs e)
        {
            if (port.IsOpen)
            {
                try
                {
                    port.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                State = AppState.PORT_CLOSED;
            }
            else
            {
                try
                {
                    port.PortName = portNameCbx.SelectedItem.ToString();
                    port.Open();

                    State = AppState.PORT_OPENED;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 2
0
        private bool ReopenPort()
        {
            bool result = false;

            InvokeWriteStateLbl("Reopening port");
            InvokeSwitchProgressBarMode(ProgressBarStyle.Marquee);
            InvokeWriteLogString("Reopening port...\r\n");
            try
            {
                nmeaPort.Close();
                nmeaPort.PortBaudRate  = BaudRate.baudRate115200;
                nmeaPort.IsRawModeOnly = true;
                Thread.Sleep(1000);
                nmeaPort.Open();
                Thread.Sleep(2000);

                action = UCNL_FW_ACTION.FW_UPDATE_INIT;
                result = RequestTransferSize();
            }
            catch (Exception ex)
            {
                ProcessException(ex, false);
            }

            return(result);
        }
Ejemplo n.º 3
0
        private void connectionBtn_Click(object sender, EventArgs e)
        {
            if (gtrPort.IsOpen)
            {
                gtrPort.PortError      -= gtrPortErrorEventHandler;
                gtrPort.NewNMEAMessage -= gtrPortNewNMEAMessageEventHandler;

                try
                {
                    gtrPort.Close();
                }
                catch (Exception ex)
                {
                    ProcessException(ex, true);
                }

                if (settingsProvider.Data.IsGNSSEmulator)
                {
                    try
                    {
                        gnssEmulatorPort.Close();
                    }
                    catch (Exception ex)
                    {
                        ProcessException(ex, false);
                    }
                }

                OnConnectionClosed();
            }
            else
            {
                try
                {
                    gtrPort.Open();
                    gtrPort.PortError      += gtrPortErrorEventHandler;
                    gtrPort.NewNMEAMessage += gtrPortNewNMEAMessageEventHandler;

                    OnConnectionOpened();
                }
                catch (Exception ex)
                {
                    ProcessException(ex, true);
                    OnConnectionClosed();
                }

                if ((gtrPort.IsOpen) && (settingsProvider.Data.IsGNSSEmulator))
                {
                    try
                    {
                        gnssEmulatorPort.Open();
                    }
                    catch (Exception ex)
                    {
                        ProcessException(ex, false);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private void connectionBtn_Click(object sender, System.EventArgs e)
        {
            if (inPort.IsOpen)
            {
                try
                {
                    inPort.Close();
                }
                catch (Exception ex)
                {
                    ProcessException(ex, true);
                }

                if (settingsProvider.Data.IsUseOutPort)
                {
                    try
                    {
                        outPort.Close();
                    }
                    catch (Exception ex)
                    {
                        ProcessException(ex, true);
                    }
                }

                connectionBtn.Checked = false;
                connectionBtn.Text    = "CONNECT";
                settingsBtn.Enabled   = true;
            }
            else
            {
                try
                {
                    inPort.Open();

                    connectionBtn.Text    = "DISCONNECT";
                    connectionBtn.Checked = true;
                    settingsBtn.Enabled   = false;
                }
                catch (Exception ex)
                {
                    ProcessException(ex, true);
                }

                if (settingsProvider.Data.IsUseOutPort)
                {
                    try
                    {
                        outPort.Open();
                    }
                    catch (Exception ex)
                    {
                        ProcessException(ex, true);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void startUploadingBtn_Click(object sender, EventArgs e)
        {
            SetCtrlState(false);
            startUploadingBtn.Enabled = false;

            if ((nmeaPort != null) && (nmeaPort.IsOpen))
            {
                try
                {
                    nmeaPort.Close();
                }
                catch (Exception ex)
                {
                    ProcessException(ex, false);
                }
            }

            nmeaPort = new NMEASerialPort(new SerialPortSettings(PortName, InitialBaudrate, Parity.None, DataBits.dataBits8, StopBits.One, Handshake.None));
            nmeaPort.NewNMEAMessage  += new EventHandler <NewNMEAMessageEventArgs>(nmeaPort_NewMessage);
            nmeaPort.PortError       += new EventHandler <SerialErrorReceivedEventArgs>(nmeaPort_PortError);
            nmeaPort.RawDataReceived += new EventHandler <RawDataReceivedEventArgs>(nmeaPort_RawData);

            try
            {
                nmeaPort.Open();
            }
            catch (Exception ex)
            {
                ProcessException(ex, true);
                SetCtrlState(true);
                startUploadingBtn.Enabled = true;
            }

            if (!startUploadingBtn.Enabled)
            {
                packetIdx = 0;
                repeats   = 0;

                if (isEmptyDeviceChb.Checked)
                {
                    action = UCNL_FW_ACTION.FW_UPDATE_INIT;
                    nmeaPort.IsRawModeOnly = true;
                    RequestTransferSize();
                }
                else
                {
                    action = UCNL_FW_ACTION.REQUEST_DEVICE_INFO;
                    nmeaPort.IsRawModeOnly = false;
                    RequestDevInfo();
                }
            }
        }
Ejemplo n.º 6
0
        private void connectionBtn_Click(object sender, EventArgs e)
        {
            if (port.IsOpen)
            {
                try
                {
                    port.Close();
                }
                catch (Exception ex)
                {
                    var lStr = logger.Write(ex);
                    InvokeAppendText(commLogTxb, lStr);
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                try
                {
                    port.Open();
                }
                catch (Exception ex)
                {
                    var lStr = logger.Write(ex);
                    InvokeAppendText(commLogTxb, lStr);
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            if (port.IsOpen)
            {
                connectionBtn.Checked = true;
                connectionBtn.Text    = "Disconnect";
                settingsBtn.Enabled   = false;
                mainSplit.Enabled     = true;
                statusLbl.Text        = string.Format("State: Connected to {0}", settingsProvider.Data.RedLINEPortName);
            }
            else
            {
                connectionBtn.Checked = false;
                connectionBtn.Text    = "Connect";
                settingsBtn.Enabled   = true;
                mainSplit.Enabled     = false;
                statusLbl.Text        = "State: Disconnected";
            }
        }
Ejemplo n.º 7
0
        public void Start()
        {
            if (!inPort.IsOpen)
            {
                if (AUXGNSSUsed)
                {
                    try
                    {
                        auxGNSSPort.Open();
                    }
                    catch (Exception ex)
                    {
                        LogEvent.Rise(auxGNSSPort, new LogEventArgs(LogLineType.ERROR, ex));
                    }
                }

                if (OutPortUsed)
                {
                    try
                    {
                        outPort.Open();
                    }
                    catch (Exception ex)
                    {
                        LogEvent.Rise(outPort, new LogEventArgs(LogLineType.ERROR, ex));
                    }
                }

                try
                {
                    inPort.Open();
                }
                catch (Exception ex)
                {
                    LogEvent.Rise(inPort, new LogEventArgs(LogLineType.CRITICAL, ex));
                    throw ex;
                }
            }
            else
            {
                throw new InvalidOperationException("Already running");
            }
        }
Ejemplo n.º 8
0
        private bool CheckNextPort()
        {
            portSettings.PortName = portNames[curPortIdx];
            bool result = false;

            try
            {
                port = new NMEASerialPort(portSettings);
                port.NewNMEAMessage = new EventHandler <NewNMEAMessageEventArgs>(port_NewNMEAMessage);
                port.PortError      = new EventHandler <SerialErrorReceivedEventArgs>(port_PortError);
                port.Open();

                var queryStr = NMEAParser.BuildProprietarySentence(ManufacturerCodes.TNT, "4", new object[] { (int)LocalDataIDs.LOC_DATA_DEVICE_INFO, 0 });
                port.SendData(queryStr);

                if (ConnectionEstablished != null)
                {
                    ConnectionEstablished(this, new EventArgs());
                }

                timer.Start();

                result = true;
            }
            catch (Exception ex)
            {
                if (port.IsOpen)
                {
                    port.Close();
                }

                UnsubscribePort();
                port.Dispose();
            }

            return(result);
        }
Ejemplo n.º 9
0
 public void Open()
 {
     port.Open();
 }
Ejemplo n.º 10
0
 public void Open()
 {
     InitDeviceInformation();
     port.Open();
     timer.Start();
 }