public override async Task <int> Run() { try { await YAPI.RegisterHub(HubURL); YPwmInput pwm; YPwmInput pwm1 = null; YPwmInput pwm2 = null; YModule m = null; if (Target.ToLower() == "any") { // retreive any pwm input available pwm = YPwmInput.FirstPwmInput(); if (pwm == null) { WriteLine("No module connected"); return(-1); } } else { // retreive the first pwm input from the device given on command line pwm = YPwmInput.FindPwmInput(Target + ".pwmInput1"); } // we need to retreive both channels from the device. if (await pwm.isOnline()) { m = await pwm.get_module(); pwm1 = YPwmInput.FindPwmInput(await m.get_serialNumber() + ".pwmInput1"); pwm2 = YPwmInput.FindPwmInput(await m.get_serialNumber() + ".pwmInput2"); } while (await m.isOnline()) { WriteLine("PWM1: " + await pwm1.get_frequency() + " Hz " + await pwm1.get_dutyCycle() + " % " + await pwm1.get_pulseCounter() + " pulse edges "); WriteLine("PWM2: " + await pwm2.get_frequency() + " Hz " + await pwm2.get_dutyCycle() + " % " + await pwm2.get_pulseCounter() + " pulse edges "); await YAPI.Sleep(1000); } WriteLine("Module not connected (check identification and USB cable)"); } catch (YAPI_Exception ex) { WriteLine("error: " + ex.Message); } YAPI.FreeAPI(); return(0); }
/** * <summary> * Returns the PWM frequency in Hz. * <para> * </para> * <para> * </para> * </summary> * <returns> * a floating point number corresponding to the PWM frequency in Hz * </returns> * <para> * On failure, throws an exception or returns <c>YPwmInput.FREQUENCY_INVALID</c>. * </para> */ public double get_frequency() { double res; if (_func == null) { throw new YoctoApiProxyException("No PwmInput connected"); } res = _func.get_frequency(); if (res == YAPI.INVALID_DOUBLE) { res = Double.NaN; } return(res); }
static void Main(string[] args) { string errmsg = ""; string target; YPwmInput pwm; YPwmInput pwm1 = null; YPwmInput pwm2 = null; YModule m = null; if (args.Length < 1) { usage(); } target = args[0].ToUpper(); // Setup the API to use local USB devices if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS) { Console.WriteLine("RegisterHub error: " + errmsg); Environment.Exit(0); } if (target == "ANY") { // retreive any pwm input available pwm = YPwmInput.FirstPwmInput(); if (pwm == null) { die("No module connected"); } } else { // retreive the first pwm input from the device given on command line pwm = YPwmInput.FindPwmInput(target + ".pwmInput1"); } // we need to retreive both channels from the device. if (pwm.isOnline()) { m = pwm.get_module(); pwm1 = YPwmInput.FindPwmInput(m.get_serialNumber() + ".pwmInput1"); pwm2 = YPwmInput.FindPwmInput(m.get_serialNumber() + ".pwmInput2"); } else { die("Module not connected"); } while (m.isOnline()) { Console.WriteLine("PWM1: " + pwm1.get_frequency().ToString() + " Hz " + pwm1.get_dutyCycle().ToString() + " % " + pwm1.get_pulseCounter().ToString() + " pulse edges "); Console.WriteLine("PWM2: " + pwm2.get_frequency().ToString() + " Hz " + pwm2.get_dutyCycle().ToString() + " % " + pwm2.get_pulseCounter().ToString() + " pulse edges "); Console.WriteLine(" (press Ctrl-C to exit)"); YAPI.Sleep(1000, ref errmsg); } YAPI.FreeAPI(); die("Module not connected"); }