private void ConnectButton_Click(object sender, EventArgs e) { PortSettings(); try { //sp.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler); //open serial port sp.Open(); //set read time out to 500 ms // sp.ReadTimeout = 100; } catch (System.Exception ex) { MessageBox.Show(ex.Message); } if (sp.IsOpen) { MessageBox.Show("serial port has open"); connectSp = true; ConnectButton.Hide(); DisconnectButton.Show(); RefreshButton.Hide(); } else { MessageBox.Show("faild to open serial port"); connectSp = false; ConnectButton.Show(); DisconnectButton.Hide(); RefreshButton.Show(); } }
private void DisconnectButton_Click(object sender, EventArgs e) { try { connectSp = false; sp.Close(); ConnectButton.Show(); DisconnectButton.Hide(); RefreshButton.Show(); } catch (System.Exception ex) { connectSp = true; MessageBox.Show("faild to close serial port"); ConnectButton.Hide(); DisconnectButton.Show(); RefreshButton.Hide(); } }
private void Form1_Load(object sender, EventArgs e) { haar = new HaarCascade("haarcascade_frontalface_alt2.xml"); sensor = KinectSensor.KinectSensors[0]; sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30); sensor.DepthStream.Enable(DepthImageFormat.Resolution320x240Fps30); sensor.SkeletonStream.Enable(); running = false; PosX = 320; disT = false; try { sensor.Start(); } catch { MessageBox.Show("Sensor not star"); } try { sensor.ColorFrameReady += FrameReady; } catch { MessageBox.Show("colour frame not Found"); } try { sensor.DepthFrameReady += DepthFrameReady; } catch { MessageBox.Show("Defth frame not Found"); } posY = 0; sensor.ElevationAngle = 0; connectSp = false; DisconnectButton.Hide(); Application.Idle += new EventHandler(take1); }