/// <summary> /// Attempts to set the target (width of pulses sent) of a channel. /// </summary> /// <param name="channel">Channel number from 0 to 23.</param> /// <param name="target"> /// Target, in units of quarter microseconds. For typical servos, /// 6000 is neutral and the acceptable range is 4000-8000. /// </param> void TrySetTarget(Byte channel, int target) { try { // using () // Find a device and temporarily connect. { try{ //Console.WriteLine(this.Name+" Target :"+target*4); if ((target * 4) < UInt16.MaxValue) { //Console.WriteLine("Servo:"+channel+" target:"+target) channels[channel] = Convert.ToUInt16(target * 4); //usbdevice.SetAllChannels(channels); if (ImmediateMode) { if (usbdevice == null) { connectToDevice(); } Console.WriteLine("immediate Set"); usbdevice.setTarget(channel, Convert.ToUInt16(target * 4)); } } else { Console.WriteLine("Invalid Target: " + target + " for Channel: " + this.channel); } }catch (Exception ex) { Console.WriteLine("Invalid Target " + target + ex.Message + ex.StackTrace.ToString()); usbdevice.disconnect(); usbdevice = null; connectToDevice(); } // Console.WriteLine("Servo: "+channel+" mit wert "+target); // device.Dispose() is called automatically when the "using" block ends, // allowing other functions and processes to use the device. } } catch (Exception exception) // Handle exceptions by displaying them to the user. { Console.WriteLine(exception.Message + "\n" + exception.StackTrace.ToString()); // displayException(exception); } }
// Disconnects all devices that are currently connected. public static void disconnectDevices() { if (NumOfConnectedMaestros > 0) { usc.disconnect(); } if (NumOfConnectedJrks > 0) { Jrk1.disconnect(); } if (NumOfConnectedJrks > 1) { Jrk2.disconnect(); } if (NumOfConnectedJrks > 2) { Jrk3.disconnect(); } if (NumOfConnectedJrks > 3) { Jrk4.disconnect(); } }