Ejemplo n.º 1
0
        /// <summary>
        /// Connects to a Maestro using native USB and returns the Usc object
        /// representing that connection.  When you are done with the
        /// connection, you should close it using the Dispose() method so that
        /// other processes or functions can connect to the device later.  The
        /// "using" statement can do this automatically for you.
        /// </summary>
        void  connectToDevice()
        {
            try{
                // Get a list of all connected devices of this type.
                if (usbdevice == null)
                {
                    List <DeviceListItem> connectedDevices = Usc.getConnectedDevices();
                    foreach (DeviceListItem dli in connectedDevices)
                    {
                        if ((device == null))//|| (this.device == dli.serialNumber)
                        {
                            // If you have multiple devices connected and want to select a particular
                            // device by serial number, you could simply add a line like this:
                            // if (dli.serialNumber != "00012345"){ continue; }
                            Usc uscdevice = new Usc(dli); // Connect to the device.

                            usbdevice = uscdevice;
                            // Return the device.
                        }
                    }
                }
                if (usbdevice != null)
                {
                    usbdevice.clearErrors();
                    var settings = usbdevice.getUscSettings();
                    settings.channelSettings[channel].mode = ChannelMode.Servo;

                    Console.WriteLine("Set Startup Position Servo " + channel + " to " + settings.channelSettings[channel].home);
                    settings.servoPeriod = 20;


                    usbdevice.setUscSettings(settings, false);
                    //  usbdevice.setAcceleration(channel, 0);
                    usbdevice.setSpeed(channel, 0);
                }
                else
                {
                    throw new Exception("Could not find device.  Make sure it is plugged in to USB " +
                                        "and check your Device Manager (Windows) or run lsusb (Linux).");
                }
            }catch (Exception ex) {
                Console.WriteLine("Fehler beim Verbinden mit dem Servo " + ex.Message + ex.StackTrace.ToString());
            }
        }
Ejemplo n.º 2
0
 static void configure(Usc usc, string filename)
 {
     Stream file = File.Open(filename, FileMode.Open);
     StreamReader sr = new StreamReader(file);
     List<String> warnings = new List<string>();
     UscSettings settings = ConfigurationFile.load(sr, warnings);
     usc.fixSettings(settings, warnings);
     usc.setUscSettings(settings, true);
     sr.Close();
     file.Close();
     usc.reinitialize();
 }
Ejemplo n.º 3
0
        static void configure(Usc usc, string filename)
        {
            Stream        file     = File.Open(filename, FileMode.Open);
            StreamReader  sr       = new StreamReader(file);
            List <String> warnings = new List <string>();
            UscSettings   settings = ConfigurationFile.load(sr, warnings);

            usc.fixSettings(settings, warnings);
            usc.setUscSettings(settings, true);
            sr.Close();
            file.Close();
            usc.reinitialize();
        }