void tcpClient_OnDataReceived(object sender, TCPSlamBase.MessageArgs e) { if (e.MessageType == TCPSlamBase.MessageType.ArduinoStatus) { ArduinoStatus = (ArduinoSlam.ArduinoStatus)e.Message[0]; if (ArduinoStatus == ArduinoSlam.ArduinoStatus.Connected) { lblArduinoStatus.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { lblArduinoStatus.Content = "Connected"; })); btnArduinoConnect.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { btnArduinoConnect.Content = "Disconnect"; })); } else if (ArduinoStatus == ArduinoSlam.ArduinoStatus.Connecting) { lblArduinoStatus.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { lblArduinoStatus.Content = "Connecting..."; })); btnArduinoConnect.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { btnArduinoConnect.Content = "Disconnect"; })); } else if (ArduinoStatus == ArduinoSlam.ArduinoStatus.NotConnected) { lblArduinoStatus.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { lblArduinoStatus.Content = "Disconnected"; })); btnArduinoConnect.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { btnArduinoConnect.Content = "Connect"; })); } } else if (e.MessageType == TCPSlamBase.MessageType.KinectList) { byte count = e.Message[0]; cmbKinect.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { cmbKinect.Items.Clear(); for (byte i = 1; i <= count; i++) cmbKinect.Items.Add(new ComboBoxItem() { Content = "Kinect " + i }); if (count > 0) cmbKinect.SelectedIndex = 0; })); } else if (e.MessageType == TCPSlamBase.MessageType.KinectFrame) { cameraWindow.Dispatcher.Invoke(DispatcherPriority.Send, new Action(delegate() { cameraWindow.LoadFrame(e.Message); })); } else if (e.MessageType == TCPSlamBase.MessageType.Audio) { SoundPlayer sp = new SoundPlayer(new MemoryStream(e.Message)); sp.Play(); } else if (e.MessageType == TCPSlamBase.MessageType.XForce) { if (cameraWindow != null) cameraWindow.XForce = BitConverter.ToDouble(e.Message, 0); } else if (e.MessageType == TCPSlamBase.MessageType.YForce) { if (cameraWindow != null) cameraWindow.YForce = BitConverter.ToDouble(e.Message, 0); } else if (e.MessageType == TCPSlamBase.MessageType.ZForce) { if (cameraWindow != null) cameraWindow.ZForce = BitConverter.ToDouble(e.Message, 0); } else if (e.MessageType == TCPSlamBase.MessageType.Temperature) { if (cameraWindow != null) cameraWindow.Temperature = BitConverter.ToDouble(e.Message, 0); } }
void tcpClient_OnConnectionStatusChanged(object sender, TCPSlamClient.ClientStatusArgs e) { if (e.Status == TCPSlamClient.ClientStatus.Connected) { txtIP.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { txtIP.IsEnabled = false; })); btnConnect.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { btnConnect.Content = "Disconnect"; })); lblStatus.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { lblStatus.Content = "Status: Connected"; })); groupCommunication.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { groupCommunication.IsEnabled = true; })); groupArduino.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { groupArduino.IsEnabled = true; })); } else if (e.Status == TCPSlamClient.ClientStatus.Connecting) { txtIP.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { txtIP.IsEnabled = false; })); btnConnect.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { btnConnect.Content = "Disconnect"; })); lblStatus.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { lblStatus.Content = "Status: Connecting..."; })); groupCommunication.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { groupCommunication.IsEnabled = false; })); groupArduino.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { groupArduino.IsEnabled = false; })); } else if (e.Status == TCPSlamClient.ClientStatus.Disconnected) { txtIP.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { txtIP.IsEnabled = true; })); btnConnect.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { btnConnect.Content = "Connect"; })); lblStatus.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { lblStatus.Content = "Status: Disconnected"; })); groupCommunication.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { groupCommunication.IsEnabled = false; })); btnArduinoConnect.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { btnArduinoConnect.Content = "Connect"; })); lblArduinoStatus.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { lblArduinoStatus.Content = "Disconnected"; })); groupArduino.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { groupArduino.IsEnabled = false; })); ArduinoStatus = ArduinoSlam.ArduinoStatus.NotConnected; cmbKinect.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { cmbKinect.Items.Clear(); })); } }