public void setupRobot() { robot = new iRobotCreate(); robot.OnSensorUpdateRecieved += new iRobotCreate.SensorUpdateHandler(OnSensorUpdate); robot.OnBumperChanged += new iRobotCreate.BumperChangedHandler(OnBumperChanged); robot.OnCliffDetectChanged += new iRobotCreate.CliffDetectChangedHandler(OnCliffDetectChanged); robot.OnWheelDropChanged += new iRobotCreate.WheelDropChangedHandler(OnWheelDropChanged); }
private void Form1_Load(object sender, EventArgs e) { this.KeyPreview = true; robot = new iRobotCreate(); robot.OnSensorUpdateRecieved += new iRobotCreate.SensorUpdateHandler(OnSensorUpdate); robot.OnBumperChanged += new iRobotCreate.BumperChangedHandler(OnBumperChanged); robot.OnCliffDetectChanged += new iRobotCreate.CliffDetectChangedHandler(OnCliffDetectChanged); robot.OnWheelDropChanged += new iRobotCreate.WheelDropChangedHandler(OnWheelDropChanged); if (File.Exists("config.txt")) { FileStream fs = new FileStream("config.txt", FileMode.OpenOrCreate); StreamReader filereader = new StreamReader(fs); try { string[] parts; parts = (filereader.ReadLine()).Split(' '); cbAutoConnectCOM.Checked = Boolean.Parse(parts[1]); parts = (filereader.ReadLine()).Split(' '); tbCOMPort.Text = parts[1]; parts = (filereader.ReadLine()).Split(' '); cbAutoStartServer.Checked = Boolean.Parse(parts[1]); parts = (filereader.ReadLine()).Split(' '); tbServerPort.Text = int.Parse(parts[1]).ToString(); parts = (filereader.ReadLine()).Split(' '); tbServerPassword.Text = parts[1]; parts = (filereader.ReadLine()).Split(' '); cbAutoConnectNetwork.Checked = Boolean.Parse(parts[1]); if (cbAutoConnectNetwork.Checked) { tabControl.SelectedTab = tabControl.TabPages[1]; } parts = (filereader.ReadLine()).Split(' '); tbRemoteIP.Text = parts[1]; parts = (filereader.ReadLine()).Split(' '); tbRemotePort.Text = int.Parse(parts[1]).ToString(); parts = (filereader.ReadLine()).Split(' '); tbRemotePassword.Text = parts[1]; parts = (filereader.ReadLine()).Split(' '); tbKeyBoardSpeed.Text = parts[1]; Thread.Sleep(1000); //connect the local robot if (cbAutoConnectCOM.Checked || cbAutoConnectNetwork.Checked) { delayedConnectThread = new Thread(new ThreadStart(DelayedConnectCallback)); delayedConnectThread.Start(); } if (cbAutoStartServer.Checked) { btnStartServer_Click(this, null); } } catch (Exception x) { Console.Out.WriteLine("File read error: " + x.ToString()); } filereader.Close(); fs.Close(); } else { if(udpClientListener != null) udpClientListener.Close(); SaveSettings(); } }