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 bool Emulate //{ // get { return _emulate; } // set // { // _emulate = value; // if (IsConnected) // { // Disconnect(); // } // if (_emulate) // { // StartReadingSensorValues(); // } // else // { // StopReadingSensorValues(); // } // } //} //private bool _emulate; /// <summary> /// Connect to the NXT Brick. /// </summary> /// <param name="comPort">The COM Port associated with the Bluetooth connection. /// If left blank, uses the value of the 'ComPort' property.</param> public void Connect(string comPort = "") { if (EmulationMode) { Name = "NXT Robot Emulator"; BatteryLevelMillivolts = _randomNoGenerator.Next(7000, 7999); SetBatteryLevelUpdateTimer(3); IsConnected = true; return; } SetComPort(comPort); // create new NxtBrick obj and connect _brick = new McNxtBrick(NxtCommLinkType.Bluetooth, ComPort); try { _brick.Connect(); } catch (Exception ex) { MessageBox.Show("Error connecting. " + ex.Message); return; } // if success, do necessary prep stuff here BatteryLevelMillivolts = _brick.BatteryLevel; Name = _brick.Name; SetBatteryLevelUpdateTimer(3); InitializeAllSensors(); //StartReadingSensorValues(); // update self and inform everybody else IsConnected = _brick.IsConnected; }
static void SetupBluetoothConnection() { Console.WriteLine("\n\nEnter your Bluetooth COM-Port (Default: 40)"); byte comport = Convert.ToByte(Console.ReadLine()); brick = new McNxtBrick(NxtCommLinkType.Bluetooth, comport); Console.WriteLine("\nBluetooth connection set up at port " + comport + "."); }
public RobotEngineMc() { _brick = new McNxtBrick(NxtCommLinkType.Bluetooth, Config.SerialPortNo) { MotorA = new McNxtMotor(), MotorB = new McNxtMotor() }; _motorSync = new McNxtMotorSync(_brick.MotorA, _brick.MotorB); }
private Timer _batteryLevelUpdateTimer; // Timer to control time period at which the // battery level property should be updated. /// <summary> /// Connect to the NXT Brick. /// </summary> /// <param name="comPort">The COM Port associated with the Bluetooth connection. /// If left blank, uses the value of the 'ComPort' property.</param> public void Connect(string comPort = "") { // update the ComPort property if (comPort != "") { ComPort = byte.Parse(comPort.Remove(0, 3)); } // create new NxtBrick obj and connect _brick = new McNxtBrick(NxtCommLinkType.Bluetooth, ComPort); _brick.Connect(); // update self and inform everybody else IsConnected = _brick.IsConnected; if (ConnectionStatusHasChanged != null) { ConnectionStatusHasChanged(this, new EventArgs()); } // if success, do necessary prep stuff here SetBatteryLevelUpdateTimer(1); InitializeAllSensors(); //StartReadingSensorValues(false); }
//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; } }
static void SetupUSBConnection() { brick = new McNxtBrick(NxtCommLinkType.USB, 0); Console.WriteLine("\nUSB connection set up."); }