Exemplo n.º 1
0
        private void ConnectDevice(string motorNO)
        {
            // unload any currently connected device if not of the desired type
            if (KDC101 != null)
            {
                if (KDC101.DeviceID == motorNO)
                {
                    return;
                }
                DisconnectDevice();
            }

            // create the new device
            KDC101 = KCubeDCServo.CreateKCubeDCServo(motorNO);

            try
            {
                KDC101.Connect(motorNO);
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
                return;
            }

            // wait for settings to be initialized (on the channel)
            KDC101.WaitForSettingsInitialized(5000);

            // create user interface (WPF view) via the DeviceManager
            _contentControl.Content = KCubeDCServoUI.CreateLargeView(KDC101, DeviceConfiguration.DeviceSettingsUseOptionType.UseConfiguredSettings);
        }
Exemplo n.º 2
0
 private void CreateDevice()
 {
     // create the device
     this.currentMotor = KCubeDCServo.CreateKCubeDCServo(this.serialNo);
     if (this.currentMotor == null)
     {
         // an error occured
         Console.WriteLine("{0} is not a KCubeDCServo", this.serialNo);
         Console.ReadKey();
         return;
     }
 }
Exemplo n.º 3
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;
            }
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
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);
        }