コード例 #1
0
 public void ClearSession()
 {
     var connection = new MockSerialConnection();
     var session = new ArduinoSession(connection);
     session.Clear();
     session.Dispose();
 }
コード例 #2
0
        public void FirmataSetup(String porta)
        {
            try
            {
                if (arduino != null)
                {
                    arduino.Clear();
                    arduino.Dispose();
                }

                connection = new EnhancedSerialConnection(porta, SerialBaudRate.Bps_9600);
                arduino    = new ArduinoSession(connection);

                _COMStatusLabel.Text = porta;
                _MessageLabel.Text   = "Connected.";

                Ready = true;
            }
            catch (Exception e)
            {
                _COMStatusLabel.Text = porta;
                _MessageLabel.Text   = e.Message;

                Ready = false;
            }
        }
コード例 #3
0
        public void ClearSession()
        {
            var connection = new MockSerialConnection();
            var session    = new ArduinoSession(connection);

            session.Clear();
            session.Dispose();
        }
コード例 #4
0
ファイル: ArduinoModel.cs プロジェクト: RMichaelSwan/Skybots
        /*//For setting the connection manually.
         * //Example: setExactConnection("COM2", SerialBaudRate.Bps_57600);
         * private void SetExactConnection(string COM_Port, SerialBaudRate baudRate)
         * {
         *  CloseConnection(); //close any existing connection
         *
         *  try
         *  {
         *      _connection = new EnhancedSerialConnection(COM_Port, baudRate);
         *      if (_connection == null)
         *      {
         *          _comOK = false;
         *      }
         *      else
         *      {
         *          _comOK = true;
         *      }
         *
         *  }
         *  catch
         *  {
         *      _comOK = false;
         *      _connection.Close();
         *  }
         * }*/

        public void Reconnect()
        {
            if (_comOK)
            {
                _keepAliveTimer.Stop();
                _session.Clear();
                _keepAliveTimer.Start();
            }
            else
            {
                SetConnection();
                if (_comOK)
                {
                    _session = new ArduinoSession(_connection);
                    _keepAliveTimer.Start();
                }
            }
        }
コード例 #5
0
        public void Clear(int attempts = 1, int waitBetweenAttempts = 0)
        {
            lock (SendMessageLock)
            {
                String    errMsg         = null;
                Exception innerException = null;
                for (int i = 0; i < attempts; i++)
                {
                    errMsg = null;
                    try
                    {
                        Sampler?.Stop();
                        Tracing?.TraceEvent(TraceEventType.Information, 0, "Attempt ({0} of {1}) to clear session @ {2}", i + 1, attempts, PortAndNodeID);
                        _session.Clear();
                        Tracing?.TraceEvent(TraceEventType.Information, 0, "Session @ {0} cleared", PortAndNodeID);
                        Sampler?.Start();
                        break;
                    }
                    catch (Exception e)
                    {
                        errMsg         = String.Format("ArduinoDeviceManager::Clear Session @ {0} produced exception {1} {2}", PortAndNodeID, e.GetType(), e.Message);
                        innerException = e;
                        Tracing?.TraceEvent(TraceEventType.Information, 0, errMsg);

                        if (waitBetweenAttempts > 0 && attempts > 1)
                        {
                            System.Threading.Thread.Sleep(waitBetweenAttempts);
                        }
                    }
                }

                if (errMsg != null)
                {
                    throw new ArduinoException(errMsg, innerException);
                }
                else
                {
                    //Do some resetting
                    MessageReceivedSuccess = true; //to avoid message timeout exceptions upon the first message sent after this clear
                }
            }
        }