Пример #1
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;
            }
        }
Пример #2
0
        private void buttonConnect_Click(object sender, EventArgs e)
        {
            if (_kCubeDCServoMotor != null)
            {
                MessageBox.Show("Device already connected");
                return;
            }

            const string serialNumber = "27250312";

            // 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();

                _kCubeDCServoMotor = KCubeDCServo.CreateKCubeDCServo(serialNumber);

                // Establish a connection with the device.
                _kCubeDCServoMotor.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.
                _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();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to connect to device\n" + ex);
            }
        }
Пример #3
0
        public void init()
        {
            LinLi = KCubeDCServo.CreateKCubeDCServo(KDC101_left);
            if (LinLi == null)
            {
                MessageBox.Show("Device A is not a KDC101");
            }

            LinRe = KCubeDCServo.CreateKCubeDCServo(KDC101_right);
            if (LinRe == null)
            {
                MessageBox.Show("Device B is not a KDC101");
            }

            RotLi = KCubeBrushlessMotor.CreateKCubeBrushlessMotor(KBD101_left);
            if (RotLi == null)
            {
                MessageBox.Show("Device D is not a KBD101");
            }

            RotRe = KCubeBrushlessMotor.CreateKCubeBrushlessMotor(KBD101_right);
            if (RotRe == null)
            {
                MessageBox.Show("Device D is not a KBD101");
            }

            // Open a connection to the device.
            try
            {
                LinLi.Connect(KDC101_left);
            }
            catch (Exception)
            {
                // Connection failed
                MessageBox.Show("Failed to open device A");
            }

            try
            {
                LinRe.Connect(KDC101_right);
            }
            catch (Exception)
            {
                // Connection failed
                MessageBox.Show("Failed to open device B");
            }

            try
            {
                RotLi.Connect(KBD101_left);
            }
            catch (Exception)
            {
                // Connection failed
                MessageBox.Show("Failed to open device C");
            }

            try
            {
                RotRe.Connect(KBD101_right);
            }
            catch (Exception)
            {
                // Connection failed
                MessageBox.Show("Failed to open device D");
            }

            // Wait for the device settings to initialize - timeout 5000ms
            LinLi.WaitForSettingsInitialized(500);
            LinRe.WaitForSettingsInitialized(500);
            RotLi.WaitForSettingsInitialized(500);
            RotRe.WaitForSettingsInitialized(500);

            // Initialize the DeviceUnitConverter object required for real world
            // unit parameters.
            LinLi.LoadMotorConfiguration(KDC101_left, DeviceConfiguration.DeviceSettingsUseOptionType.UseFileSettings);
            LinRe.LoadMotorConfiguration(KDC101_right, DeviceConfiguration.DeviceSettingsUseOptionType.UseFileSettings);
            RotLi.LoadMotorConfiguration(KBD101_left, DeviceConfiguration.DeviceSettingsUseOptionType.UseFileSettings);
            RotRe.LoadMotorConfiguration(KBD101_right, DeviceConfiguration.DeviceSettingsUseOptionType.UseFileSettings);

            // Start the device polling
            // The polling loop requests regular status requests to the motor to ensure the program keeps track of the device.
            LinLi.StartPolling(50);
            LinRe.StartPolling(50);
            RotLi.StartPolling(50);
            RotRe.StartPolling(50);

            // Needs a delay so that the current enabled state can be obtained
            Thread.Sleep(50);

            // Enable the channel otherwise any move is ignored
            LinLi.EnableDevice();
            LinRe.EnableDevice();
            RotLi.EnableDevice();
            RotRe.EnableDevice();

            // Needs a delay to give time for the device to be enabled
            Thread.Sleep(50);
        }