Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
 /// <summary> Tests potentiometer parameters. </summary>
 /// <param name="device"> The device. </param>
 public static void TestPotentiometerParameters(TCubeDCServo device)
 {
     try
     {
         PotentiometerParameters_DeviceUnit potentiometerParameters     = device.GetPotentiometerParams_DeviceUnit();
         PotentiometerParameters            realPotentiometerParameters = device.GetPotentiometerParams();
         realPotentiometerParameters[0].Velocity += 0.5m;
         realPotentiometerParameters[1].Velocity += 0.5m;
         realPotentiometerParameters[2].Velocity += 0.5m;
         realPotentiometerParameters[3].Velocity += 0.5m;
         device.SetPotentiometerParams(realPotentiometerParameters);
         Thread.Sleep(250);
         device.SetPotentiometerParams_DeviceUnit(potentiometerParameters);
         Thread.Sleep(250);
         PotentiometerParameters_DeviceUnit newPotentiometerParameters = device.GetPotentiometerParams_DeviceUnit();
     }
     catch (DeviceException ex)
     {
         Console.WriteLine("Failed to update settings {0} - {1}", ex.DeviceID, ex.Message);
     }
 }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        private static bool WaitForMessage(TCubeDCServo cube, int messageTypeID, int requiredMessageID)
        {
            while (true)
            {
                ushort messageType;
                ushort messageID;
                uint   messageData;

                // if no messages waiting
                if (cube.MessageQueueSize() == 0)
                {
                    // reset wait for message event and wait for a message
                    _event.Reset();
                    _event.WaitOne();
                }

                // get the message
                cube.GetNextMessage(out messageType, out messageID, out messageData);

                // if message is correct
                if ((messageType == messageTypeID) && (messageID == requiredMessageID))
                {
                    return(true);
                }

                if (cube.HasLastMsgTimerOverrun())
                {
                    Int64 lastMsg;
                    cube.TimeSinceLastMsgReceived(out lastMsg);
                    Console.WriteLine("device not responded, lastMsg {0}", lastMsg);
                    cube.Close();
                    Console.ReadKey();
                    return(false);
                }
            }
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            TCubeDCServo.RegisterDevice();
            KCubeDCServo.RegisterDevice();

            // get parameters from command line
            int argc = args.Count();

            if (argc < 1)
            {
                Console.WriteLine("Usage = DC_Console_net_managed [serial_no] [position: optional (0 - 50)] [velocity: optional (0 - 5)]");
                Console.ReadKey();
                return;
            }

            decimal position = 0m;

            if (argc > 1)
            {
                position = decimal.Parse(args[1]);
            }

            decimal velocity = 0m;

            if (argc > 2)
            {
                velocity = decimal.Parse(args[2]);
            }

            string serialNo = args[0];

            try
            {
                // build device list
                DeviceManagerCLI.BuildDeviceList();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception raised by BuildDeviceList {0}", ex);
                Console.ReadKey();
                return;
            }

            // get available KCube DC Servos and check our serial number is correct
            List <string> serialNumbers = DeviceManagerCLI.GetDeviceList(new List <int> {
                KCubeDCServo.DevicePrefix, TCubeDCServo.DevicePrefix
            });

            if (!serialNumbers.Contains(serialNo))
            {
                if (serialNumbers.Count > 0)
                {
                    serialNo = serialNumbers[0];
                    Console.WriteLine("using serial number {0}", serialNo);
                }
                else
                {
                    Console.WriteLine("{0} is not a valid serial number", serialNo);
                    Console.ReadKey();
                    return;
                }
            }

            // create the device
            IGenericCoreDeviceCLI device = DeviceFactory.CreateDevice(serialNo);
            IGenericAdvancedMotor motor  = device as IGenericAdvancedMotor;

            if (motor == null)
            {
                Console.WriteLine("{0} is not a DCServo", serialNo);
                Console.ReadKey();
                return;
            }

            // connect device
            try
            {
                Console.WriteLine("Opening device {0}", serialNo);
                device.Connect(serialNo);

                if (!motor.IsSettingsInitialized())
                {
                    motor.WaitForSettingsInitialized(5000);
                }

                // display info about device
                DeviceInfo di = device.GetDeviceInfo();
                Console.WriteLine("Device {0} = {1}", di.SerialNumber, di.Name);

                // start the device polling
                motor.StartPolling(250);
            }
            catch (DeviceException ex)
            {
                Console.WriteLine("Failed to open device {0} - {1}", ex.DeviceID, ex.Message);
                Console.ReadKey();
                return;
            }

            DeviceUnitConverter deviceUnitConverter;

            try
            {
                // call GetMotorConfiguration on the device to initialize the DeviceUnitConverter object required for real unit parameters
                MotorConfiguration motorSettings = motor.GetMotorConfiguration(serialNo);
                motorSettings.DeviceSettingsName = "PRM1-Z8";
                motorSettings.UpdateCurrentConfiguration();

                MotorDeviceSettings motorDeviceSettings = motor.MotorDeviceSettings;
                motor.SetSettings(motorDeviceSettings, true, false);

                // test code to test get / sert of parameters using real world units
                TestVelocityParameters(motor);
                TestJogParameters(motor);
                TestHomingParameters(motor);
                TestLimitParameters(motor);
                if (device is TCubeDCServo)
                {
                    TestPotentiometerParameters(device as TCubeDCServo);                     // TDC Only
                }

                motorSettings.UpdateCurrentConfiguration();
                deviceUnitConverter = motor.UnitConverter;
            }
            catch (DeviceException ex)
            {
                Console.WriteLine("Failed prepare settings {0} - {1}", ex.DeviceID, ex.Message);
                Console.ReadKey();
                return;
            }

            try
            {
                if (!Home_1(motor))
                {
                    Console.WriteLine("Failed to home device");
                    Console.ReadKey();
                    return;
                }
            }
            catch (DeviceException ex)
            {
                Console.WriteLine("Failed to Home device settings {0} - {1}", ex.DeviceID, ex.Message);
                Console.ReadKey();
                return;
            }

            try
            {
                // if position is set
                if (position != 0)
                {
                    // update velocity if required using real world methods
                    if (velocity != 0)
                    {
                        VelocityParameters velPars = motor.GetVelocityParams();
                        velPars.MaxVelocity = velocity;
                        motor.SetVelocityParams(velPars);
                    }

                    if (!MoveTo_1(motor, position, deviceUnitConverter))
                    {
                        Console.WriteLine("Failed to set position");
                        Console.ReadKey();
                    }
                }
                else
                {
                    char c = '\0';
                    do
                    {
                        do
                        {
                            Console.WriteLine("Press a key");
                            Console.WriteLine("0 to exit");
                            Console.WriteLine("1 to test StopImmediate()");
                            Console.WriteLine("2 to test Stop(5000)");
                            Console.WriteLine("3 to test Stop(WaitEvent)");
                            c = Console.ReadKey().KeyChar;
                        } while (c < '0' || c > '3');

                        if (c != '0')
                        {
                            motor.MoveContinuous(MotorDirection.Forward);
                            Console.WriteLine("Press any key to stop");
                            Console.ReadKey();
                            StatusBase status;
                            if (c == '1')
                            {
                                motor.Stop(5000);
                            }
                            if (c == '2')
                            {
                                motor.StopImmediate();
                            }
                            if (c == '3')
                            {
                                ManualResetEvent waitEvent = new ManualResetEvent(false);
                                waitEvent.Reset();
                                motor.Stop(p =>
                                {
                                    Console.WriteLine("Message Id {0}", p);
                                    waitEvent.Set();
                                });
                                if (!waitEvent.WaitOne(5000))
                                {
                                    Console.WriteLine("Failed to Stop");
                                }
                            }
                            do
                            {
                                status = motor.Status;
                                Console.WriteLine("Status says {0} ({1:X})", status.IsInMotion ? "Moving" : "Stopped", status.Status);
                                Thread.Sleep(50);
                            } while (status.IsInMotion);
                        }
                    } while (c != '0');
                }
            }
            catch (DeviceException ex)
            {
                Console.WriteLine("Failed to Move device settings {0} - {1}", ex.DeviceID, ex.Message);
                Console.ReadKey();
                return;
            }

            try
            {
                device.Disconnect(true);
            }
            catch (DeviceException ex)
            {
                Console.WriteLine("Failed to Disconnect {0} - {1}", ex.DeviceID, ex.Message);
            }

            Console.ReadKey();
        }
Ejemplo n.º 7
0
        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;
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            // get parameters from command line
            int argc = args.Count();

            if (argc < 1)
            {
                Console.WriteLine("Usage = TDC_Console_net_managed [serial_no] [position: optional (0 - 1715200)] [velocity: optional (0 - 3838091)]");
                Console.ReadKey();
                return;
            }

            // get position
            int position = 250000;

            if (argc > 1)
            {
                position = int.Parse(args[1]);
            }

            // get velocity
            int velocity = 0;

            if (argc > 2)
            {
                velocity = int.Parse(args[2]);
            }

            // get serial no
            string serialNo = args[0];

            try
            {
                // build device list
                InstrumentManager.BuildDeviceList();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception raised by BuildDeviceList {0}", ex);
                Console.ReadKey();
                return;
            }

            // get available TCube DC Servos and check our serial number is correct
            string[] serialNumbers = InstrumentManager.GetDeviceListByType(83);
            if (!serialNumbers.Contains(serialNo))
            {
                Console.WriteLine("{0} is not a valid serial number", serialNo);
                Console.ReadKey();
                return;
            }

            // display info about device
            InstrumentManager.DeviceInfo di = InstrumentManager.GetDeviceInfo(serialNo);
            Console.WriteLine("Device {0} = {1}", di.SerialNumber(), di.Description());

            // open device
            Console.WriteLine("Opening device {0}", serialNo);
            TCubeDCServo device = new TCubeDCServo(serialNo);
            short        err    = device.Open();

            if (err != 0)
            {
                Console.WriteLine("Failed to open device {0}: error code = {1}", serialNo, err);
                Console.ReadKey();
                return;
            }

            // register a callback function to receive device messages
            device.RegisterMessageCallback(new TCubeDCServo.CallbackDelegate(MessageWaitingCallback));

            device.StartPolling(250);
            Thread.Sleep(500);
            device.EnableLastMsgTimer(true, 2000);

            // home the device
            Console.WriteLine("Homing device");
            device.ClearMessageQueue();
            device.Home();

            if (!WaitForMessage(device, MotorMessageType, MotorHomed))
            {
                return;
            }
            Console.WriteLine("Device Homed");

            // if position is set
            if (position != 0)
            {
                // update velocity if required
                if (velocity != 0)
                {
                    TCubeDCServo.VelocityParameters velPars = device.GetVelParams();
                    velPars.maxVelocity = velocity;
                    device.SetVelParams(velPars);
                }

                // move to defined position
                Console.WriteLine("Moving Device to {0}", position);
                device.ClearMessageQueue();
                device.MoveToPosition(position);
                if (!WaitForMessage(device, MotorMessageType, MotorMoved))
                {
                    return;
                }
                int newPos = GetPosition(device);
                Console.WriteLine("Device Moved to {0}({1})", newPos, position);
            }

            Console.ReadKey();
            return;
        }
Ejemplo n.º 9
0
 /// <summary> Gets a position. </summary>
 /// <param name="cube"> If non-null, the cube. </param>
 /// <returns> The position. </returns>
 private static int GetPosition(TCubeDCServo cube)
 {
     cube.RequestPosition();
     Thread.Sleep(50);
     return(cube.GetPosition());
 }