static void getConf(Usc usc, string filename) { Stream file = File.Open(filename, FileMode.Create); StreamWriter sw = new StreamWriter(file); ConfigurationFile.save(usc.getUscSettings(), sw); sw.Close(); file.Close(); }
/// <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()); } }
/// <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> Usc connectToDevice() { // Get a list of all connected devices of this type. 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. uscdevice.getUscSettings().channelSettings[channel].mode = ChannelMode.Output; return(uscdevice); // Return the device. } } 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)."); }
static void getConf(Usc usc, string filename) { Stream file = File.Open(filename, FileMode.Create); StreamWriter sw = new StreamWriter(file); ConfigurationFile.save(usc.getUscSettings(), sw); sw.Close(); file.Close(); }