private void ConnectDevice(string motorNO) { // unload any currently connected device if not of the desired type if (KDC101 != null) { if (KDC101.DeviceID == motorNO) { return; } DisconnectDevice(); } // create the new device KDC101 = KCubeDCServo.CreateKCubeDCServo(motorNO); try { KDC101.Connect(motorNO); } catch (Exception err) { MessageBox.Show(err.Message); return; } // wait for settings to be initialized (on the channel) KDC101.WaitForSettingsInitialized(5000); // create user interface (WPF view) via the DeviceManager _contentControl.Content = KCubeDCServoUI.CreateLargeView(KDC101, DeviceConfiguration.DeviceSettingsUseOptionType.UseConfiguredSettings); }
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e) { // This instructs the DeviceManager to build and maintain the list of // devices connected. We then print a list of device name strings called // “devices” which contain the prefix “27” DeviceManagerCLI.BuildDeviceList(); List <string> devices = DeviceManagerCLI.GetDeviceList(27); // IF statement – if the number of devices connected is zero, the Window // will display “No Devices”. if (devices.Count == 0) { MessageBox.Show("No Devices"); return; } // Selects the first device serial number from “devices” list. string serialNo = devices[0]; // Creates the device. We assign an instance of the device to _kCubeDCServo KCubeDCServo _kCubeDCServo = KCubeDCServo.CreateKCubeDCServo(serialNo); // Connect to the device & wait for initialisation. This is contained in a // Try/Catch Error Handling Statement. try { _kCubeDCServo.Connect(serialNo); // wait for settings to be initialized _kCubeDCServo.WaitForSettingsInitialized(5000); } catch (DeviceException ex) { MessageBox.Show(ex.Message); return; } // Create the Kinesis Panel View for KDC101 _contentControl.Content = KCubeDCServoUI.CreateLargeView(_kCubeDCServo); }