private void Connect_btn_Click(object sender, EventArgs e) { // Try to connect then check connection and throw error if found try { // Setup the NXT Brick _nxt = new NxtBrick(NxtCommLinkType.Bluetooth, Convert.ToByte(Port_txt.Text)) { MotorA = _ar, MotorC = _cr }; _nxt.Connect(); if (_nxt.IsConnected) { _defaultEngine.RecognizeAsync(RecognizeMode.Multiple); Connected_lbl.Visible = true; Port_txt.BackColor = Color.Green; Connect_btn.Enabled = false; Battery_checker.Enabled = true; } } catch (Exception ex) { MessageBox.Show(ex.Message); Connected_lbl.Visible = false; Port_txt.BackColor = Color.Red; // Writes the Exception to the Log WriteToLog(ex.Message); } }
private void ConnectSafe() { try { _brick.Connect(); } catch (Exception e) { Logger.Warn(string.Format("Ошибка подключения к роботу: {0}", e.Message)); } }
public void Connect() { try { m_brick.Connect(); } catch (IOException) { // Do nothing ATM } m_connected = m_brick.IsConnected; }
static void Main() { Init(); brick = new NxtBrick(NxtCommLinkType.USB, 0); //brick = new NxtBrick(NxtCommLinkType.Bluetooth, 40); var sound = new NxtSoundSensor(); var touch = new NxtTouchSensor(); var sonar = new NxtUltrasonicSensor(); brick.MotorA = new NxtMotor(); brick.MotorC = new NxtMotor(); motorPair = new NxtMotorSync(brick.MotorA, brick.MotorC); brick.Sensor1 = sonar; brick.Sensor3 = touch; brick.Sensor4 = sound; sound.PollInterval = 50; sound.OnPolled += sound_OnPolled; sonar.PollInterval = 50; sonar.ThresholdDistanceCm = 25; sonar.OnPolled += sonar_OnPolled; sonar.OnWithinThresholdDistanceCm += OnWithinThreshold; sonar.ContinuousMeasurementCommand(); touch.PollInterval = 50; touch.OnPressed += OnCollision; brick.Connect(); motorPair.Run(75, 0, 0); Console.WriteLine("Press any key to stop."); Console.ReadKey(); brick.Disconnect(); }
static void Main(string[] args) { VertsX = new float[0]; VertsY = new float[0]; VertsZ = new float[0]; FacesA = new int[0]; FacesB = new int[0]; FacesC = new int[0]; Console.WriteLine("\n=== === ===\nWELCOME\n=== === ==="); Console.WriteLine("Welcome to ProjectX 3D Printing Software!"); Console.WriteLine("Press any Key to start print Configuration."); Console.ReadKey(); Console.WriteLine("\n\n"); Console.WriteLine("\n=== === ===\nCONNECTION SETUP\n=== === ==="); Console.WriteLine("ProjectX will now detect your NXT Device."); Console.WriteLine("Type 'B' if you are using a Bluetooth Connection,"); Console.WriteLine("or 'U' if you are using a USB Cable."); Console.WriteLine("Make sure your NXT is turned on and connected properly before continuing."); bool hasChosen = false; while (!hasChosen) { ConsoleKeyInfo key = Console.ReadKey(); if (key.Key == ConsoleKey.B) { hasChosen = true; SetupBluetoothConnection(); } if (key.Key == ConsoleKey.U) { hasChosen = true; SetupUSBConnection(); } } //Verbindungskontrolle Console.WriteLine("Trying to connect to NXT ..."); brick.Connect(); int timeout = 5000; Stopwatch sw = Stopwatch.StartNew(); while (sw.ElapsedMilliseconds < timeout && !brick.IsConnected) { System.Threading.Thread.Sleep(100); } if (brick.IsConnected) { PingNXT(); } else { Console.WriteLine("Connection Failed."); } //Einlesen Der .obj-Datei Console.WriteLine("\n=== === ===\nMODEL SELECTION\n=== === ==="); Console.WriteLine("\n\nPlease give the Path of the 3D model you are willing to print. OBJ Format is supported."); string objPath = Console.ReadLine(); StreamReader objReader = new StreamReader(objPath); DecodeObjFile(objReader); Console.WriteLine("Object with name " + objName + " found."); Console.WriteLine("A total of " + VertsX.Length + " Vertices and " + FacesA.Length + " faces were found."); //Kalibrierung der Motoren Console.WriteLine("\n=== === ===\nMOTOR CALIBRATION\n=== === ==="); LinkMotorAxis(); Calibrate(); SetDimensions(); //Einstellung der Auflösung Console.WriteLine("\n=== === ===\nRESOLUTION\n=== === ==="); SetResolution(); //Anpassen der modellgröße FindScale(); //Drucken PreparePrint(); Print(); Console.ReadKey(); brick.Disconnect(); }
//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; } }
public bool Connect() { m_brick.Connect(); return(m_brick.IsConnected); }