private void button1_Click(object sender, EventArgs e) { nxt = new McNxtBrick(NxtCommLinkType.Bluetooth, Convert.ToByte(Convert.ToInt16(textBox1.Text))); nxt.Sensor4 = new NxtUltrasonicSensor(); nxt.Sensor4.PollInterval = 50; nxt.Connect(); if (!nxt.IsConnected) { label1.Text = "Connection Error!"; return; } else { nxt.MotorB = new McNxtMotor(); nxt.MotorC = new McNxtMotor(); motors = new McNxtMotorSync(nxt.MotorB, nxt.MotorC); ((NxtUltrasonicSensor)nxt.Sensor4).PollInterval = 20; ((NxtUltrasonicSensor)nxt.Sensor4).Poll(); label1.Text = "Connected"; button1.Enabled = false; } while (true) { MainLoop(); } }
public RobotEngineMc() { _brick = new McNxtBrick(NxtCommLinkType.Bluetooth, Config.SerialPortNo) { MotorA = new McNxtMotor(), MotorB = new McNxtMotor() }; _motorSync = new McNxtMotorSync(_brick.MotorA, _brick.MotorB); }
//Brick connection procedure logic private void button_connect_Click(object sender, EventArgs e) { if (!isConnectedToBrick) { byte COMport = byte.Parse(COMportInput.Text); if (RB_McRXE.Checked) { //Create Motor Control NXT Brick and Bluetooth use USB to communicate with it. if (RB_Bluetooth.Checked) { McBrick = new McNxtBrick(NxtCommLinkType.Bluetooth, COMport); } //Create Motor Control NXT Brick, and use USB to communicate with it. if (RB_USB.Checked) { brick = new McNxtBrick(NxtCommLinkType.USB, COMport); } // Create a Motor Control motor. McMotorA = new McNxtMotor(); McMotorB = new McNxtMotor(); McMotorC = new McNxtMotor(); //Synched motors McMotorPair = new McNxtMotorSync(McMotorB, McMotorC); // Attach it to port A of the NXT brick. McBrick.MotorA = McMotorA; McBrick.MotorB = McMotorB; McBrick.MotorC = McMotorC; // Connect to the NXT. McBrick.Connect(); if (!McBrick.IsMotorControlRunning()) { McBrick.StartMotorControl(); } motorControlActive = true; } else { //Create NXT Brick and Bluetooth use USB to communicate with it. if (RB_Bluetooth.Checked) { NxtBrick brick = new NxtBrick(NxtCommLinkType.Bluetooth, COMport); } // Create a NXT brick, and use USB to communicate with it. if (RB_USB.Checked) { NxtBrick brick = new NxtBrick(NxtCommLinkType.USB, COMport); } // Create a motor. motorA = new NxtMotor(); motorB = new NxtMotor(); motorC = new NxtMotor(); // Attach it to port A of the NXT brick. brick.MotorA = motorA; brick.MotorB = motorB; brick.MotorC = motorC; // Connect to the NXT. brick.Connect(); } ConnectedText.Visible = true; isConnectedToBrick = true; } }