//All flipper functions
 public static void BuildDeviceList()
 {
     //Builds the list of filter flippers connected to the computer
     //Necessary per the flipper documentation
     try
     {
         DeviceManagerCLI.BuildDeviceList();
     }
     catch
     {
         MessageBox.Show("There was an error building the device list.");
         return;
     }
 }
Example #2
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;
        }
Example #3
0
        private void buttonConnect_Click(object sender, EventArgs e)
        {
            if (_kCubePositionAligner != null)
            {
                MessageBox.Show("Device already connected");
                return;
            }

            const string serialNumber = "69250117";

            // All of this operation has been placed inside a single "catch-all"
            // exception handler. This is to reduce the size of the example code.
            // Normally you would have a try...catch per API call and catch the
            // specific exceptions that could be thrown (details of which can be
            // found in the Kinesis .NET API document).
            try
            {
                // Instructs the DeviceManager to build and maintain the list of
                // devices connected.
                DeviceManagerCLI.BuildDeviceList();

                _kCubePositionAligner = KCubePositionAligner.CreateKCubePositionAligner(serialNumber);

                // Establish a connection with the device.
                _kCubePositionAligner.Connect(serialNumber);

                // Wait for the device settings to initialize. We ask the device to
                // throw an exception if this takes more than 5000ms (5s) to complete.
                _kCubePositionAligner.WaitForSettingsInitialized(5000);

                // This starts polling the device at intervals of 250ms (0.25s).
                _kCubePositionAligner.StartPolling(250);

                // Initialize the DeviceUnitConverter object required for real world
                // unit parameters.
                _kCubePositionAligner.GetPositionAlignerConfiguration(serialNumber);

                // We are now able to enable the device for commands.
                _kCubePositionAligner.EnableDevice();

                // Place the device in OpenLoop mode. The position will be monitored
                // but the X DIFF and Y DIFF outputs will remain under our control.
                _kCubePositionAligner.SetOperatingMode(PositionAlignerStatus.OperatingModes.OpenLoop, false);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to connect to device\n" + ex);
            }
        }
Example #4
0
        private void initializeFiber(string serial)
        {
            try
            {
                // Instructs the DeviceManager to build and maintain the list of devices connected.
                DeviceManagerCLI.BuildDeviceList();
            }
            catch (Exception)
            {
                this.fiberLabel.Text = "Not connected";
                return;
            }

            try
            {
                _kCubeDCServoMotor = KCubeDCServo.CreateKCubeDCServo(serial);
                // Establish a connection with the device.
                _kCubeDCServoMotor.Connect(serial);
            }
            catch (Exception)
            {
                this.fiberLabel.Text = "Unable to connect";
                return;
            }

            try
            {
                // Wait for the device settings to initialize. We ask the device to
                // throw an exception if this takes more than 5000ms (5s) to complete.
                _kCubeDCServoMotor.WaitForSettingsInitialized(5000);
                // Initialize the DeviceUnitConverter object required for real world unit parameters.
                _kCubeDCServoMotor.LoadMotorConfiguration(_kCubeDCServoMotor.DeviceID, DeviceConfiguration.DeviceSettingsUseOptionType.UseFileSettings);
                // This starts polling the device at intervals of 250ms (0.25s).
                _kCubeDCServoMotor.StartPolling(250);
                // We are now able to enable the device for commands.
                _kCubeDCServoMotor.EnableDevice();
                // Enable buttons and contros
                ToggleFiberButtons(true);
                this.fiberLabel.Text = "Connected";
                return;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to initialize fiber controller\n" + ex);
                return;
            }
        }
Example #5
0
        private void buttonConnect_Click(object sender, EventArgs e)
        {
            if (_longTravelStage != null)
            {
                MessageBox.Show("Device already connected");
                return;
            }

            const string serialNumber = "45848872";

            // All of this operation has been placed inside a single "catch-all"
            // exception handler. This is to reduce the size of the example code.
            // Normally you would have a try...catch per API call and catch the
            // specific exceptions that could be thrown (details of which can be
            // found in the Kinesis .NET API document).
            try
            {
                // Instructs the DeviceManager to build and maintain the list of
                // devices connected.
                DeviceManagerCLI.BuildDeviceList();

                _longTravelStage = LongTravelStage.CreateLongTravelStage(serialNumber);

                // Establish a connection with the device.
                _longTravelStage.Connect(serialNumber);

                // Wait for the device settings to initialize. We ask the device to
                // throw an exception if this takes more than 5000ms (5s) to complete.
                _longTravelStage.WaitForSettingsInitialized(5000);

                // Initialize the DeviceUnitConverter object required for real world
                // unit parameters.
                _longTravelStage.GetMotorConfiguration(serialNumber);

                // This starts polling the device at intervals of 250ms (0.25s).
                _longTravelStage.StartPolling(250);

                // We are now able to enable the device for commands.
                _longTravelStage.EnableDevice();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to connect to device\n" + ex);
            }
        }
Example #6
0
        static void Main()
        {
            try
            {
                // build device list
                DeviceManagerCLI.BuildDeviceList();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception raised by BuildDeviceList {0}", ex.ToString());
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Application.Run(new StageControl());

            //decimal value = LinLi.GetMoveAbsolutePosition();

            //guitLinLi.SetMoveAbsolutePosition(40);
        }
        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);
        }
        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);
        }
Example #9
0
        static void Main(string[] args)
        {
            // Get parameters from command line
            int argc = args.Count();

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

            // Get the test motor position
            decimal position = 0m;

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

            // Get the test velocity
            decimal velocity = 0m;

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

            // get the test BSC203 serial number
            string serialNo = args[0];

            try
            {
                // Tell the device manager to get the list of all devices connected to the computer
                DeviceManagerCLI.BuildDeviceList();
            }
            catch (Exception ex)
            {
                // An error occurred - see ex for details
                Console.WriteLine("Exception raised by BuildDeviceList {0}", ex);
                Console.ReadKey();
                return;
            }

            // Get available Benchtop Stepper Motor and check our serial number is correct - by using the device prefix
            // i.e for serial number 70000123, device prefix is 70)
            List <string> serialNumbers = DeviceManagerCLI.GetDeviceList(BenchtopStepperMotor.DevicePrefix70);

            if (!serialNumbers.Contains(serialNo))
            {
                // The requested serial number is not a BSC203 or is not connected
                Console.WriteLine("{0} is not a valid serial number", serialNo);
                Console.ReadKey();
                return;
            }

            // Create the BenchtopStepperMotor device
            BenchtopStepperMotor device = BenchtopStepperMotor.CreateBenchtopStepperMotor(serialNo);

            if (device == null)
            {
                // An error occured
                Console.WriteLine("{0} is not a BenchtopStepperMotor", serialNo);
                Console.ReadKey();
                return;
            }

            // Open a connection to the device.
            try
            {
                Console.WriteLine("Opening device {0}", serialNo);
                device.Connect(serialNo);
            }
            catch (Exception)
            {
                // Connection failed
                Console.WriteLine("Failed to open device {0}", serialNo);
                Console.ReadKey();
                return;
            }

            // Get the correct channel - channel 1
            StepperMotorChannel channel = device.GetChannel(1);

            if (channel == null)
            {
                // Connection failed
                Console.WriteLine("Channel unavailable {0}", serialNo);
                Console.ReadKey();
                return;
            }

            // Wait for the device settings to initialize - timeout 5000ms
            if (!channel.IsSettingsInitialized())
            {
                try
                {
                    channel.WaitForSettingsInitialized(5000);
                }
                catch (Exception)
                {
                    Console.WriteLine("Settings failed to initialize");
                }
            }

            // Start the device polling
            // The polling loop requests regular status requests to the motor to ensure the program keeps track of the device.
            channel.StartPolling(250);
            // Needs a delay so that the current enabled state can be obtained
            Thread.Sleep(500);
            // Enable the channel otherwise any move is ignored
            channel.EnableDevice();
            // Needs a delay to give time for the device to be enabled
            Thread.Sleep(500);

            // Call LoadMotorConfiguration on the device to initialize the DeviceUnitConverter object required for real world unit parameters
            //  - loads configuration information into channel
            // Use the channel.DeviceID "70xxxxxx-1" to get the channel 1 settings. This is different to the serial number
            MotorConfiguration motorConfiguration = channel.LoadMotorConfiguration(channel.DeviceID);

            // Not used directly in example but illustrates how to obtain device settings
            ThorlabsBenchtopStepperMotorSettings currentDeviceSettings = channel.MotorDeviceSettings as ThorlabsBenchtopStepperMotorSettings;

            // Display info about device
            DeviceInfo deviceInfo = channel.GetDeviceInfo();

            Console.WriteLine("Device {0} = {1}", deviceInfo.SerialNumber, deviceInfo.Name);

            Home_Method1(channel);
            // or
            //Home_Method2(channel);
            bool homed = channel.Status.IsHomed;

            // If a position is requested
            if (position != 0)
            {
                // Update velocity if required using real world methods
                if (velocity != 0)
                {
                    VelocityParameters velPars = channel.GetVelocityParams();
                    velPars.MaxVelocity = velocity;
                    channel.SetVelocityParams(velPars);
                }

                Move_Method1(channel, position);
                // or
                // Move_Method2(channel, position);

                Decimal newPos = channel.Position;
                Console.WriteLine("Device Moved to {0}", newPos);
            }

            channel.StopPolling();
            device.Disconnect(true);

            Console.ReadKey();
        }
Example #10
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();
        }
Example #11
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;
        }
Example #12
0
        public int ConnectStage()
        {
            try
            {
                if (SerialNumber.Equals("73000001"))
                {
                    /*
                     * 73000001 is the initial SN given to any
                     * BBD203 controller by the Kinesis Simulation software
                     * this is most likely running under simulation and should
                     * use that startup sequence.
                     */
                    SimulationManager.Instance.InitializeSimulations();
                }
                else
                {
                    // Otherwise populate the device manager like you normally do.
                    DeviceManagerCLI.BuildDeviceList();
                }
            } catch (Exception ex)
            {
                Console.WriteLine("An error occured when trying to build the device list for the stage.");
                Console.WriteLine("Exception: {0}", ex.Message);
                Console.WriteLine("Press <ENTER> to continue execution.");
                Console.ReadLine();
                return(-1);
            }
            // Create the stage object and attempt to connect to it.
            try
            {
                this._microscopemotor = BenchtopBrushlessMotor.CreateBenchtopBrushlessMotor(this._serial);
                this._microscopemotor.Connect(this._serial);
            } catch (Exception ex)
            {
                Console.WriteLine("An error occured when trying to create the actual stage object.");
                Console.WriteLine("Exception: {0}", ex.Message);
                Console.WriteLine("Press <ENTER> to continue execution.");
                Console.ReadLine();
            }

            // Setup the axes
            // X - Stepover Axis
            // Y - Scanning Axis
            this._stepoverchannel = this._microscopemotor.GetChannel(2);
            this._stepoverchannel.StartPolling(this._pollFrequency);
            if (!this._stepoverchannel.IsSettingsInitialized())
            {
                this._stepoverchannel.WaitForSettingsInitialized(this._initTimeoutMillis);
            }
            this._scanningchannel = this._microscopemotor.GetChannel(1);
            this._scanningchannel.StartPolling(this._pollFrequency);
            if (!this._scanningchannel.IsSettingsInitialized())
            {
                this._scanningchannel.WaitForSettingsInitialized(this._initTimeoutMillis);
            }
            // Enable both axes
            this._stepoverchannel.EnableDevice();
            this._scanningchannel.EnableDevice();
            // Load the motor configurations off the device
            this._stepoverconfig = this._stepoverchannel.GetMotorConfiguration(this._stepoverchannel.DeviceID, DeviceConfiguration.DeviceSettingsUseOptionType.UseDeviceSettings);
            this._scanningconfig = this._scanningchannel.GetMotorConfiguration(this._scanningchannel.DeviceID, DeviceConfiguration.DeviceSettingsUseOptionType.UseDeviceSettings);
            this._isConnected    = true;
            // Start various stage polling functions
            this._pollingactive = true;
            return(0);
        }
Example #13
0
        static void Main(string[] args)
        {
            // get parameters from command line
            int argc = args.Count();

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

            short channel = 1;

            if (argc > 2)
            {
                channel = short.Parse(args[1]);
            }

            decimal position = 0m;

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

            decimal velocity = 0m;

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

            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 TCube DC Servos and check our serial number is correct
            List <string> serialNumbers = DeviceManagerCLI.GetDeviceList(BenchtopBrushlessMotor.DevicePrefix);

            if (!serialNumbers.Contains(serialNo))
            {
                Console.WriteLine("{0} is not a valid serial number", serialNo);
                Console.ReadKey();
                return;
            }

            // create the device
            BenchtopBrushlessMotor device = BenchtopBrushlessMotor.CreateDevice(serialNo) as BenchtopBrushlessMotor;

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

            //BrushlessMotorChannel benchtopChannel = device.GetChannel(channel);
            BrushlessMotorChannel benchtopChannel = device[channel] as BrushlessMotorChannel;

            if (benchtopChannel == null)
            {
                Console.WriteLine("{0} is not a valid channel number", channel);
                Console.ReadKey();
                return;
            }

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

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

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

                // start the device polling
                benchtopChannel.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 = benchtopChannel.GetMotorConfiguration(serialNo);

                // test code to test get / sert of parameters using real world units
                TestVelocityParameters(benchtopChannel);
                TestJogParameters(benchtopChannel);
                TestHomingParameters(benchtopChannel);
                TestLimitParameters(benchtopChannel);

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

            try
            {
                if (!Home_1(benchtopChannel))
                {
                    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 = benchtopChannel.GetVelocityParams();
                        velPars.MaxVelocity = velocity;
                        benchtopChannel.SetVelocityParams(velPars);
                    }

                    if (!MoveTo_1(benchtopChannel, position, deviceUnitConverter))
                    {
                        Console.WriteLine("Failed to set position");
                        Console.ReadKey();
                    }
                }
            }
            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();
        }