Beispiel #1
0
 /// <summary>
 /// Disconnect from Lego NXT brick.
 /// </summary>
 ///
 public void Disconnect( )
 {
     lock (this)
     {
         if (communicationInterface != null)
         {
             communicationInterface.Disconnect( );
             communicationInterface = null;
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// Connect to NXT brick.
        /// </summary>
        ///
        /// <param name="portName">Serial port name to use for communication, for example COM1.</param>
        ///
        /// <returns>Returns <b>true</b> on successful connection or <b>false</b>
        /// otherwise.</returns>
        ///
        /// <remarks>If connection to NXT brick was established before the call, existing connection will be reused.
        /// If it is required to force reconnection, then <see cref="Disconnect"/> method should be called before.
        /// </remarks>
        ///
        public bool Connect(string portName)
        {
            lock (this)
            {
                if (communicationInterface != null)
                {
                    return(true);
                }

                // create communication interface,
                communicationInterface = new SerialCommunication(portName);
                // connect and check if NXT is alive
                if ((communicationInterface.Connect( )) && (IsAlive( )))
                {
                    return(true);
                }

                Disconnect( );
            }
            return(false);
        }
Beispiel #3
0
 /// <summary>
 /// Disconnect from Lego NXT brick.
 /// </summary>
 /// 
 public void Disconnect( )
 {
     lock ( sync )
     {
         if ( communicationInterface != null )
         {
             communicationInterface.Disconnect( );
             communicationInterface = null;
         }
     }
 }
Beispiel #4
0
        /// <summary>
        /// Connect to NXT brick.
        /// </summary>
        /// 
        /// <param name="portName">Serial port name to use for communication, for example COM1.</param>
        /// 
        /// <returns>Returns <b>true</b> on successful connection or <b>false</b>
        /// otherwise.</returns>
        /// 
        /// <remarks>If connection to NXT brick was established before the call, existing connection will be reused.
        /// If it is required to force reconnection, then <see cref="Disconnect"/> method should be called before.
        /// </remarks>
        /// 
        public bool Connect( string portName )
        {
            lock ( sync )
            {
                if ( communicationInterface != null )
                    return true;

                // create communication interface,
                communicationInterface = new SerialCommunication( portName );
                // connect and check if NXT is alive
                if ( ( communicationInterface.Connect( ) ) && ( IsAlive( ) ) )
                    return true;

                Disconnect( );
            }
            return false;
        }