コード例 #1
0
ファイル: BrickControl.cs プロジェクト: rwoodley/Miscellany
        public static void RunForward()
        {
            NxtBrick brick = new NxtBrick(NxtCommLinkType.USB, 0);

            // Attach a motor to port B.
            brick.MotorB = new NxtMotor();

            // Connect to the NXT.
            brick.Connect();
            Console.WriteLine("NXT name: " + brick.Name);
            System.Diagnostics.Debug.WriteLine("NXT name: " + brick.Name);

            // Write out the firmware version of the NXT-brick.
            var conn = new NxtUsbConnection();
            NxtGetFirmwareVersionReply? reply = conn.GetFirmwareVersion();
            if (reply.HasValue)
                System.Diagnostics.Debug.WriteLine("NXT firmware version: " + reply.Value.firmwareVersion);

            // see: http://www.mindsqualls.net/MotorControl.aspx
            MotorControlProxy.StartMotorControl(brick.CommLink);
            System.Threading.Thread.Sleep(500);

            MotorControlProxy.CONTROLLED_MOTORCMD(brick.CommLink, MotorControlMotorPort.PortB,"111", "000360", '5');
            System.Diagnostics.Debug.WriteLine("Done");
            System.Threading.Thread.Sleep(5000);
            MotorControlProxy.StopMotorControl(brick.CommLink);
            brick.Disconnect();
        }
コード例 #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.");
            }
        }
コード例 #3
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.");
     }
 }