public Form1() { InitializeComponent(); DeviceManagerCLI.BuildDeviceList(); List <string> serialNumbers = DeviceManagerCLI.GetDeviceList(TCubeDCServo.DevicePrefix); richTextBox1.Text = serialNumbers.Count().ToString(); for (int i = 0; i < serialNumbers.Count(); i++) { device[i] = TCubeDCServo.CreateTCubeDCServo(serialNumbers[i]); device[i].Connect(serialNumbers[i]); if (!device[i].IsSettingsInitialized()) { device[i].WaitForSettingsInitialized(5000); } device[i].StartPolling(250); // call GetMotorConfiguration on the device to initialize the DeviceUnitConverter object required for real world unit parameters MotorConfiguration motorSettings = device[i].GetMotorConfiguration(serialNumbers[i]); DCMotorSettings currentDeviceSettings = device[i].MotorDeviceSettings as DCMotorSettings; // display info about device DeviceInfo deviceInfo = device[i].GetDeviceInfo(); richTextBox1.AppendText(Environment.NewLine + "Device " + deviceInfo.SerialNumber + " " + deviceInfo.Name + " " + device[i].GetMoveAbsolutePosition().ToString("F4") + Environment.NewLine); } ccd = new MaxIm.CCDCamera(); ccd.LinkEnabled = true; ccd.MultiStarGuiding = true; ccd.GuiderExpose(1.0); while (ccd.GuiderRunning) { Thread.Sleep(1000); } ccd.GuiderTrack(0.1); // Thread.Sleep(1000); timer1.Enabled = true; }
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); } }
public Main() { InitializeComponent(); if (Properties.Settings.Default.UpgradeRequired) { Properties.Settings.Default.Upgrade(); Properties.Settings.Default.UpgradeRequired = false; Properties.Settings.Default.Save(); } derrX[0] = 0; derrX[1] = 0; derrX[2] = 0; derrY[0] = 0; derrY[1] = 0; derrY[2] = 0; stopWatch.Start(); //Get the list of IM devices DeviceManagerCLI.BuildDeviceList(); List <string> serialNumbersTIM = DeviceManagerCLI.GetDeviceList(TCubeInertialMotor.DevicePrefix); serialNumbersTDC = DeviceManagerCLI.GetDeviceList(TCubeDCServo.DevicePrefix); richTextBox1.AppendText("TIM devices: " + serialNumbersTIM.Count() + " | TDC devices: " + serialNumbersTDC.Count() + Environment.NewLine); //Put the devices into an array for (int i = 0; i < serialNumbersTDC.Count(); i++) { devicesTDC[i] = TCubeDCServo.CreateTCubeDCServo(serialNumbersTDC[i]); TIM = false; } for (int i = 0; i < serialNumbersTIM.Count(); i++) { //TIM takes preference devicesTIM[i] = TCubeInertialMotor.CreateTCubeInertialMotor(serialNumbersTIM[i]); TIM = true; } if (TIM) { KpxUD.Value = (decimal)Properties.Settings.Default.Kpx; KixUD.Value = (decimal)Properties.Settings.Default.Kix; KdxUD.Value = (decimal)Properties.Settings.Default.Kdx; KpyUD.Value = (decimal)Properties.Settings.Default.Kpy; KiyUD.Value = (decimal)Properties.Settings.Default.Kiy; KdyUD.Value = (decimal)Properties.Settings.Default.Kdy; minMoveXUD.Value = (decimal)Properties.Settings.Default.minMoveX; minMoveYUD.Value = (decimal)Properties.Settings.Default.minMoveY; imaxxUD.Value = (decimal)Properties.Settings.Default.imaxX; imaxyUD.Value = (decimal)Properties.Settings.Default.imaxY; reverseX.Checked = Properties.Settings.Default.revx; reverseY.Checked = Properties.Settings.Default.revy; deviceTIM = devicesTIM[0]; //Connect and initialise deviceTIM.Connect(serialNumbersTIM[0]); if (!deviceTIM.IsSettingsInitialized()) { deviceTIM.WaitForSettingsInitialized(5000); } deviceTIM.StartPolling(100); // call GetMotorConfiguration on the device to initialize the DeviceUnitConverter object required for real world unit parameters //MotorConfiguration motorSettings = device[i].GetMotorConfiguration(serialNumbers[i]); InertialMotorConfiguration motorSettings = deviceTIM.GetInertialMotorConfiguration(serialNumbersTIM[0]); ThorlabsInertialMotorSettings currentDeviceSettings = deviceTIM.InertialMotorDeviceSettings as ThorlabsInertialMotorSettings; // display info about device DeviceInfo deviceInfo = deviceTIM.GetDeviceInfo(); richTextBox1.AppendText("Selected device " + deviceInfo.Name + " serial: " + deviceInfo.SerialNumber + Environment.NewLine);// device[i].GetPosition(ch1).ToString("F4") ch1 = InertialMotorStatus.MotorChannels.Channel1; ch2 = InertialMotorStatus.MotorChannels.Channel2; //Set step rate and acceleration currentDeviceSettings.Drive.Channel(ch1).StepRate = 1000; currentDeviceSettings.Drive.Channel(ch1).StepAcceleration = 100000; currentDeviceSettings.Drive.Channel(ch2).StepRate = 1000; currentDeviceSettings.Drive.Channel(ch2).StepAcceleration = 100000; //apply setting deviceTIM.SetSettings(currentDeviceSettings, true, true); //get motor positions and print motorX = deviceTIM.GetPosition(ch1);//GetPosition(ch1); motorY = deviceTIM.GetPosition(ch2); } else { //TDC KpxUD.Value = (decimal)Properties.Settings.Default.Kpx2; KixUD.Value = (decimal)Properties.Settings.Default.Kix2; KdxUD.Value = (decimal)Properties.Settings.Default.Kdx2; KpyUD.Value = (decimal)Properties.Settings.Default.Kpy2; KiyUD.Value = (decimal)Properties.Settings.Default.Kiy2; KdyUD.Value = (decimal)Properties.Settings.Default.Kdy2; minMoveXUD.Value = (decimal)Properties.Settings.Default.minMoveX2; minMoveYUD.Value = (decimal)Properties.Settings.Default.minMoveY2; imaxxUD.Value = (decimal)Properties.Settings.Default.imaxX2; imaxyUD.Value = (decimal)Properties.Settings.Default.imaxY2; reverseX.Checked = Properties.Settings.Default.revx2; reverseY.Checked = Properties.Settings.Default.revy2; stepUpDown.DecimalPlaces = 2; stepUpDown.Increment = (decimal)0.05; for (int i = 0; i < serialNumbersTDC.Count(); i++) { devicesTDC[i] = TCubeDCServo.CreateTCubeDCServo(serialNumbersTDC[i]); richTextBox1.AppendText(i + " Serial: " + serialNumbersTDC[i]); try { devicesTDC[i].Connect(serialNumbersTDC[i]); if (!devicesTDC[i].IsSettingsInitialized()) { devicesTDC[i].WaitForSettingsInitialized(5000); } devicesTDC[i].StartPolling(100); MotorConfiguration motorSettings = devicesTDC[i].GetMotorConfiguration(serialNumbersTDC[i], DeviceConfiguration.DeviceSettingsUseOptionType.UseDeviceSettings); //serialNumbersTDC[i] DCMotorSettings currentDeviceSettings = devicesTDC[i].MotorDeviceSettings as DCMotorSettings; // display info about device DeviceInfo deviceInfo = devicesTDC[i].GetDeviceInfo(); richTextBox1.AppendText(i + " Device " + deviceInfo.Name + " " + deviceInfo.SerialNumber + " " + devicesTDC[i].GetMoveAbsolutePosition().ToString("F4") + Environment.NewLine); } catch (Exception ex) { richTextBox1.AppendText(" " + ex.Message + Environment.NewLine); } } } motorXlbl.Text = "X: " + motorX.ToString(); motorYlbl.Text = "Y: " + motorY.ToString(); if (TIM) { //get status of ch1 //InertialMotorStatus status = deviceTIM.ChannelStatus(ch1); // richTextBox1.AppendText(status.Status + " " + status.Position + " " + status.IsError + " " + status.IsMoving + Environment.NewLine);// device[i].GetPosition(ch1).ToString("F4") } else { } //Create MaxIm DL object ccd = new MaxIm.CCDCamera(); // ccd.Notify += notify(); //Connect CCD ccd.LinkEnabled = true; /* * ccd.MultiStarGuiding = true; * * ccd.GuiderExpose(1.0); * * while (ccd.GuiderRunning) { * Thread.Sleep(100); * } * * ccd.GuiderTrack(1.0); */ //Thread.Sleep(2000); //Notify on new guider image(?) ccd.EventMask = 256; ccd.Notify += new MaxIm._CameraEvents_NotifyEventHandler(notify); //Sets minimum correction interval timer1.Interval = Convert.ToInt16(correctionUpDown.Value * 1000); timer1.Enabled = true; ready = true; }