/// <summary>
 /// <para>Constructor.</para>
 /// </summary>
 /// <remarks>
 /// <para>Introduced with v2.0 of the framework.</para>
 /// </remarks>
 /// <param name="commLinkType">Indicates whether Bluetooth or USB should be used for the communication with the NXT brick.</param>
 /// <param name="serialPortNo">The COM port used. Only relevant for Bluetooth links.</param>
 public NxtBrick(NxtCommLinkType commLinkType, byte serialPortNo)
     : this()
 {
     switch (commLinkType)
     {
         case NxtCommLinkType.Bluetooth:
             CommLink = new NxtBluetoothConnection(serialPortNo);
             break;
         case NxtCommLinkType.USB:
             CommLink = new NxtUsbConnection();
             break;
         default:
             throw new ArgumentException("Unknown commLinkType.");
     }
 }
Exemple #2
0
        /// <summary>
        /// <para>Constructor.</para>
        /// </summary>
        /// <remarks>
        /// <para>Introduced with v2.0 of the framework.</para>
        /// </remarks>
        /// <param name="commLinkType">Indicates whether Bluetooth or USB should be used for the communication with the NXT brick.</param>
        /// <param name="serialPortNo">The COM port used. Only relevant for Bluetooth links.</param>
        public NxtBrick(NxtCommLinkType commLinkType, byte serialPortNo)
            : this()
        {
            switch (commLinkType)
            {
            case NxtCommLinkType.Bluetooth:
                CommLink = new NxtBluetoothConnection(serialPortNo);
                break;

            case NxtCommLinkType.USB:
                CommLink = new NxtUsbConnection();
                break;

            default:
                throw new ArgumentException("Unknown commLinkType.");
            }
        }
        /*
         * Connects to the NXTBrick with the given comport using the given connectiontype
         */
        public bool ConnectToDevice(NxtCommLinkType connectionType, byte comPort)
        {
            brick = new NxtBrick(connectionType, comPort);

            brick.MotorA = new NxtMotor();
            brick.MotorC = new NxtMotor();

            motorPair = new NxtMotorSync(brick.MotorA, brick.MotorC);

            try
            {
                brick.Connect();
                return true;
            }
            catch
            {
                return false;
            }
        }
 /// <summary>
 /// <para>Constructor.</para>
 /// </summary>
 /// <remarks>
 /// <para>It requires that MotorControl is downloaded to the NXT block and is running.</para>
 /// </remarks>
 /// <param name="commLinkType">Indicates whether Bluetooth or USB should be used for the communication with the NXT brick.</param>
 /// <param name="serialPortNo">The COM port used. Only relevant for Bluetooth links.</param>
 public McNxtBrick(NxtCommLinkType commLinkType, byte serialPortNo)
     : base(commLinkType, serialPortNo)
 {
 }
Exemple #5
0
 /// <summary>
 /// <para>Constructor.</para>
 /// </summary>
 /// <remarks>
 /// <para>It requires that MotorControl is downloaded to the NXT block and is running.</para>
 /// </remarks>
 /// <param name="commLinkType">Indicates whether Bluetooth or USB should be used for the communication with the NXT brick.</param>
 /// <param name="serialPortNo">The COM port used. Only relevant for Bluetooth links.</param>
 public McNxtBrick(NxtCommLinkType commLinkType, byte serialPortNo) :
     base(commLinkType, serialPortNo)
 {
 }
        private NxtBrick ConnectBrick(int brickNo, NxtCommLinkType linkType, int comPort)
        {
            var brick = new NxtBrick(linkType, (byte)comPort);

            if (linkType == NxtCommLinkType.Bluetooth) {
                var attempts = 3;
                for (int attempt = 0; attempt < attempts; attempt++) {
                    Logger.Log("Connecting to brick {0} on port {1}. \t\tAttempt {2} of {3}...", brickNo, comPort,
                                      attempt + 1, attempts);
                    try {
                        brick.Connect();
                        Logger.Log("\tBrick {0} successfully connected (port: {1})", brickNo, comPort);
                        break;
                    }
                    catch (IOException) {
                        if (attempt + 1 == attempts)
                            throw;
                    }
                }
            }

            Logger.Log("Connected to brick {0}", brickNo);

            return brick;
        }
 public JointMotorConfig(int comPort1, NxtCommLinkType link1, int comPort2, NxtCommLinkType link2, int comPort3, NxtCommLinkType link3)
 {
     ComPorts = new[] {comPort1, comPort2, comPort3};
     LinkTypes = new[] {link1, link2, link3};
 }