private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            arduino = new ArduinoSlam();
            arduino.OnStatusChanged += new EventHandler<ArduinoSlam.StatusArgs>(arduino_OnStatusChanged);
            arduino.OnSensorInfoReady += new EventHandler<ArduinoSlam.SensorInfoArgs>(arduino_OnSensorInfoReady);
            arduino.Connect();

            kinectManager = new KinectSlam();
            kinectManager.OnAudioReady += new EventHandler<KinectSlam.AudioStreamArgs>(kinectManager_OnAudioReady);

            tcpServer = new TCPSlamServer();
            tcpServer.Port = 9988;
            tcpServer.OnConnectionStatusChanged += new EventHandler<TCPSlamServer.ServerStatusArgs>(tcpServer_OnConnectionStatusChanged);
            tcpServer.OnDataReceived += new EventHandler<TCPSlamBase.MessageArgs>(tcpServer_OnDataReceived);
            txtIP.Text = Common.GetIP();
            try
            {
                tcpServer.IPAddress = IPAddress.Parse(txtIP.Text);
                tcpServer.StartServer();
            }
            catch
            {
                Console.WriteLine("Invalid IP: " + txtIP.Text);
            }
        }
 void tcpServer_OnConnectionStatusChanged(object sender, TCPSlamServer.ServerStatusArgs e)
 {
     if (e.Status == TCPSlamServer.ServerStatus.Connected)
     {
         txtIP.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { txtIP.IsEnabled = false; }));
         btnListen.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { btnListen.Content = "Disconnect"; }));
         lblStatus.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { lblStatus.Content = "Status: Connected"; }));
         groupBandwidth.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { groupBandwidth.IsEnabled = true; }));
         SendArduinoStatus();
         SendKinectList();
     }
     else if (e.Status == TCPSlamServer.ServerStatus.Disconnected)
     {
         txtIP.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { txtIP.IsEnabled = true; }));
         btnListen.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { btnListen.Content = "Listen"; }));
         lblStatus.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { lblStatus.Content = "Status: Disconnected"; }));
         groupBandwidth.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { groupBandwidth.IsEnabled = false; }));
         kinectManager.StopSensor();
         sendVideo = false;
         if (!userDisconnect)
             tcpServer.StartServer();
         else
             userDisconnect = false;
     }
     else if (e.Status == TCPSlamServer.ServerStatus.Listening)
     {
         txtIP.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { txtIP.IsEnabled = false; }));
         btnListen.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { btnListen.Content = "Stop"; }));
         lblStatus.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { lblStatus.Content = "Status: Listening"; }));
         groupBandwidth.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { groupBandwidth.IsEnabled = false; }));
     }
 }