Ejemplo n.º 1
0
        public void ConnectStage()
        {
            if (!this._isConnected)
            {
                try
                {
                    // Create the stage object.
                    this.MicroscopeMotor = BenchtopBrushlessMotor.CreateBenchtopBrushlessMotor(this.SerialNumber);
                    this.MicroscopeMotor.Connect(this.SerialNumber);
                }
                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();
                }

                try
                {
                    // Create the axes
                    this.MicroscopeXAxis = this.MicroscopeMotor.GetChannel(1);
                    this.MicroscopeXAxis.StartPolling(this.PollingFrequencyInMillis);
                    if (!this.MicroscopeXAxis.IsSettingsInitialized())
                    {
                        this.MicroscopeXAxis.WaitForSettingsInitialized(this.InitalizationTimeoutInMillis);
                    }
                    this.MicroscopeXAxis.EnableDevice();
                    this.XEnabled        = true;
                    this.MicroscopeYAxis = this.MicroscopeMotor.GetChannel(2);
                    this.MicroscopeYAxis.StartPolling(this.PollingFrequencyInMillis);

                    if (!this.MicroscopeYAxis.IsSettingsInitialized())
                    {
                        this.MicroscopeYAxis.WaitForSettingsInitialized(this.InitalizationTimeoutInMillis);
                    }
                    this.MicroscopeYAxis.EnableDevice();
                    this.YEnabled = true;
                    // Get the settings so you can use metric instead of encoder steps
                    this.XAxisConfiguration = this.MicroscopeXAxis.GetMotorConfiguration(this.MicroscopeXAxis.DeviceID, DeviceConfiguration.DeviceSettingsUseOptionType.UseDeviceSettings);
                    this.YAxisConfiguration = this.MicroscopeYAxis.GetMotorConfiguration(this.MicroscopeYAxis.DeviceID, DeviceConfiguration.DeviceSettingsUseOptionType.UseDeviceSettings);
                } catch (Exception ex)
                {
                    Console.WriteLine("An error occured when trying to create the stage axes, or load one of the axes MotorConfigurations.");
                    Console.WriteLine("Exception: {0}", ex.Message);
                    Console.WriteLine("Press <ENTER> to continue execution.");
                    Console.ReadLine();
                }
                this.IsConnected = true;
            }
            else if (this.IsConnected)
            {
                this.MicroscopeMotor.Disconnect(true);
                this.IsConnected = false;
                this.IsXHomed    = false;
                this.IsYHomed    = false;
                this.XEnabled    = false;
                this.YEnabled    = false;
            }
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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();
        }