public override void Init() { LogHelper.InsertLog(string.Format("Initializing the stage [{0}]", this)); /* Create the device */ device = TCubeDCServo.CreateTCubeDCServo(this.Config.Name); if (device.Equals(null)) { this.LastError = string.Format("{0} is not a TCubeDCServo.", this.Config.Name); return(false); } else { /* Connect to the device */ try { device.Connect(this.Config.Name); } catch (Exception ex) { this.LastError = string.Format("Unable to connect to the device {0}\r\n{1}", this.Config.Name, ex.Message); return(false); } /* wait for the device settings to initialize */ if (!device.IsSettingsInitialized()) { try { device.WaitForSettingsInitialized(5000); } catch (Exception ex) { this.LastError = string.Format("Settings failed to initialize\r\n{0}", ex.Message); return(false); } } this.IsInitialized = true; return(true); } }
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e) { // get list of devices DeviceManagerCLI.BuildDeviceList(); List <string> devices = DeviceManagerCLI.GetDeviceList(83); if (devices.Count == 0) { MessageBox.Show("No Devices"); return; } // get first serial number for example string serialNo = devices[0]; // create device _tCubeDCServo = TCubeDCServo.CreateDevice(serialNo) as TCubeDCServo; if (_tCubeDCServo == null) { MessageBox.Show("Unknown Device Type"); return; } // connect device try { _tCubeDCServo.Connect(serialNo); // wait for settings to be initialized _tCubeDCServo.WaitForSettingsInitialized(5000); } catch (DeviceException ex) { MessageBox.Show(ex.Message); return; } // create view _contentControl.Content = TCubeDCServoUI.CreateLargeView(_tCubeDCServo); }