Пример #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;
        }
Пример #2
0
        private void CreateConfigs()
        {
            // start the device polling.
            // Polling requests a status update every specified number of milliseconds.
            this.currentMotor.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
            this.currentMotor.EnableDevice();

            // needs a delay to give time for the device to be enabled
            Thread.Sleep(500);

            // call GetMotorConfiguration on the device to initialize the DeviceUnitConverter object required for real world unit parameters
            // Sets up proper unit conversion for the correct device.  Only call this function ONCE
            MotorConfiguration motorSettings = this.currentMotor.LoadMotorConfiguration(this.serialNo);

            // Simply retrieves the "motor device settings"
            KCubeDCMotorSettings currentDeviceSettings = this.currentMotor.MotorDeviceSettings as KCubeDCMotorSettings;

            // display info about device

            // Retrieves a device info block
            DeviceInfo deviceInfo = this.currentMotor.GetDeviceInfo();

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

            // Getting the homing velocity
            uint homeVel = currentMotor.GetHomingVelocity_DeviceUnit();


            // After the device is opened we want to save the velocity
            // Retrieves the "velocity parameters" in real world units
            VelocityParameters_DeviceUnit velPars = this.currentMotor.GetVelocityParams_DeviceUnit();

            // Restricts the velocity allowed to be the user-defined velocity
            decimal dVelocity = this.velocity;

            velPars.MaxVelocity = (int)(homeVel);
            this.currentMotor.SetVelocityParams_DeviceUnit(velPars);
        }
Пример #3
0
        private void OpenConnection()
        {
            // open a connection to the device.
            try
            {
                Console.WriteLine("Opening device {0}", this.serialNo);
                this.currentMotor.Connect(this.serialNo);
            }
            catch (Exception)
            {
                // connection failed
                Console.WriteLine("Failed to open device {0}", this.serialNo);
                Console.ReadKey();
                return;
            }


            // wait for the device settings to initialize
            if (!this.currentMotor.IsSettingsInitialized())
            {
                try
                {
                    this.currentMotor.WaitForSettingsInitialized(5000);
                }
                catch (Exception)
                {
                    Console.WriteLine("Settings failed to initialize");
                }
            }

            MotorConfiguration configuration = this.currentMotor.LoadMotorConfiguration(this.serialNo);

            if (configuration != null)
            {
                string settingName = configuration.DeviceSettingsName;
                Console.WriteLine(settingName);
            }
        }
        public override void HomeAll()
        {
            // start the device polling
            device.StartPolling(250);
            // call GetMotorConfiguration on the device to initialize the DeviceUnitConverter object required for real world unit parameters
            MotorConfiguration motorSettings         = device.GetMotorConfiguration(this.Config.Name);
            DCMotorSettings    currentDeviceSettings = device.MotorDeviceSettings as DCMotorSettings;
            // display info about device
            DeviceInfo deviceInfo = device.GetDeviceInfo();

            try
            {
                device.Home(60000);
            }
            catch (Exception ex)
            {
                this.LastError = string.Format("Failed to home device {0}\r\n{1}", this, ex.Message);
            }
            finally
            {
                device.StopPolling();
            }
        }
Пример #5
0
 protected StateShutterMoving(SimulatorStateMachine machine, MotorConfiguration direction)
     : base(machine)
 {
     this.direction = direction;
 }
Пример #6
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();
        }
Пример #7
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();
        }
Пример #8
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;
        }
Пример #9
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);
        }
Пример #10
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();
        }
        public void RunState()
        {
            // Here's where we call the other methods

            // ASEN_SHA



            // ASEN_MotorControl Set Up
            this.motor1 = new ASEN_MotorControl(serials[0], this.velocity);
            //ASEN_MotorControl motor2 = new ASEN_MotorControl(serials[1], this.velocity);
            //ASEN_MotorControl motor3 = new ASEN_MotorControl(serials[2], this.velocity);

            Dictionary <string, string> SettingValues = new Dictionary <string, string>();



            MotorConfiguration motorConfig = new MotorConfiguration(serials[0]);

            motorConfig = motor1.GetMotorConfiguration(serials[0], 1);



            // Initializing each motor one-by-one
            motor1.InitializeMotor();
            //motor2.InitializeMotor();
            //motor3.InitializeMotor();

            // Homing the motors first
            motor1.HomeMotor();
            //motor2.HomeMotor();
            //motor3.HomeMotor();

            // Now we move to whatever positon we desire
            motor1.MoveMotor(RCWS_DFORE);
            //motor2.MoveMotor(MA_X);
            //motor3.MoveMotor(MA_Y);



            // ASEN_RCWS Initializing Camera
            this.currentRCWS = new ASEN_RCWS(cameraInUse);
            currentRCWS.InitializeCamera();


            /*
             * // ASEN_SHA Initializing Device
             * this.currentSHA = new ASEN_SHA();
             * currentSHA.CameraConnectionAndSetup();
             *
             *
             *
             * // ASEN_Environmental
             * this.teensy = new ASEN_ENV(this.teensyPort, path);
             * this.READ = true;
             *
             *
             *
             * Task teensyRead = Task.Factory.StartNew(() => TeensyParallel(ref this.teensyLock));
             * Task imageRead = Task.Factory.StartNew(() => ImagingParallel());
             *
             * Task.WaitAll(imageRead);
             *
             * // After the image is done reading, we have to set READ to false.
             * // Note that we have to block access to this variable as it is also shared by teensy read
             * lock (this.teensyLock)
             * {
             *  this.READ = false;
             * }
             *
             * Task.WaitAll(teensyRead);
             *
             * currentRCWS.Disconnect();
             * //currentSHA.CloseCamera();
             */
        }