private void Form1_Load(object sender, EventArgs e) { try { // 일단 객체 생성을 시도해보고... // (범위는 [0, 1000], 이동 비율은 0.2퍼센트씩 => 각 방향을 500단계로 나타내겠죠) joystick = new USB_Joystick(0, 1000, .20, this); } catch (Exception) // 오류나면(아마도 조이스틱이 없는 경우) 예외처리 { throw; } // 조이스틱 객체 사용을 위해 정해놓은 값 할당 joystick.PresetValues(); // 타이머 시작 timer2.Start(); txtComNum.Text = "COM26"; txtBaudRate.Text = "115200"; }
private void Connection(string IP, int port) { try { // 카메라 webControl1.Source = new System.Uri("http://" + IP + ":8080/?action=stream"); webControl2.Source = new System.Uri("http://" + IP + ":8081/?action=stream"); // 구글맵 webControl3.Source = new System.Uri("http://" + IP + ":8080/gmap.html"); // 서버 접속 Client = new TcpClient(); Client.Connect(IP, port); stream = Client.GetStream(); Connected = true; Reader = new StreamReader(stream); Writer = new StreamWriter(stream); ReceiveThread = new Thread(new ThreadStart(Receive)); ReceiveThread.Start(); button1.Text = "Disconnent"; textBox1.ReadOnly = true; textBox2.ReadOnly = true; textBox3.ReadOnly = true; radioButton1.Checked = true; radioButton1.Text = "서버 : Connected"; //조이스틱 joystick.PresetValues(); timer1.Start(); // APM 접속 comPort.BaseStream = new TcpSerial(); comPort.BaseStream.Host = IP; comPort.BaseStream.Port = textBox3.Text; comPort.MAV.cs.ResetInternals(); comPort.BaseStream.DtrEnable = false; comPort.BaseStream.RtsEnable = false; comPort.giveComport = false; comPort.Open(true); if (comPort.BaseStream.IsOpen) { radioButton2.Checked = true; radioButton2.Text = "보드 : Connected"; System.Threading.ThreadPool.QueueUserWorkItem(mainloop); hud1.Enabled = true; hud1.Visible = true; } else { about_blank(); disconnect(); throw new Exception("APM 접속 실패"); } mode = 1360; // 수동 조종 (1360: 수동조종, 1361: 자세제어) flap = 1400; // OFF (1100: ON, 1400:OFF) servo1 = 1700; // TRIM servo2 = 1500; // TRIM joystickthread = new Thread(new ThreadStart(joysticksend)) { IsBackground = true, Priority = ThreadPriority.AboveNormal, Name = "Main joystick sender" }; joystickthread.Start(); // 시리얼 리더 serialreaderthread = new Thread(SerialReader) { IsBackground = true, Name = "Main Serial reader", Priority = ThreadPriority.AboveNormal }; serialreaderthread.Start(); } catch (Exception e) { MessageBox.Show(e.Message); } }