static void Main(string[] args) { string errmsg = ""; string target; YCurrentLoopOutput loop; double value; if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS) { Console.WriteLine("RegisterHub error: " + errmsg); Environment.Exit(0); } if (args.Length < 2) { usage(); } target = args[0].ToUpper(); value = Convert.ToDouble(args[1]); if (target == "ANY") { loop = YCurrentLoopOutput.FirstCurrentLoopOutput(); if (loop == null) { Console.WriteLine("No module connected (check USB cable) "); Environment.Exit(0); } } else { loop = YCurrentLoopOutput.FindCurrentLoopOutput(target + ".currentLoopOutput"); } if (loop.isOnline()) { loop.set_current(value); int loopPower = loop.get_loopPower(); if (loopPower == YCurrentLoopOutput.LOOPPOWER_NOPWR) { Console.WriteLine("Current loop not powered"); Environment.Exit(0); } if (loopPower == YCurrentLoopOutput.LOOPPOWER_LOWPWR) { Console.WriteLine("Insufficient voltage on current loop"); Environment.Exit(0); } Console.WriteLine("current loop set to " + value.ToString() + " mA"); } else { Console.WriteLine("Module not connected"); Console.WriteLine("check identification and USB cable"); } YAPI.FreeAPI(); }
public override async Task <int> Run() { try { await YAPI.RegisterHub(HubURL); YCurrentLoopOutput loop; double value = Convert.ToDouble(LoopCurrent); if (Target.ToLower() == "any") { loop = YCurrentLoopOutput.FirstCurrentLoopOutput(); if (loop == null) { WriteLine("No module connected (check USB cable) "); return(-1); } } else { loop = YCurrentLoopOutput.FindCurrentLoopOutput( Target + ".currentLoopOutput"); } if (await loop.isOnline()) { await loop.set_current(value); int loopPower = await loop.get_loopPower(); if (loopPower == YCurrentLoopOutput.LOOPPOWER_NOPWR) { WriteLine("Current loop not powered"); } else if (loopPower == YCurrentLoopOutput.LOOPPOWER_LOWPWR) { WriteLine("Insufficient voltage on current loop"); } else { WriteLine("current loop set to " + value + " mA"); } } else { WriteLine("Module not connected (check identification and USB cable)"); } } catch (YAPI_Exception ex) { WriteLine("error: " + ex.Message); } YAPI.FreeAPI(); return(0); }
public static YCurrentLoopOutputProxy FindCurrentLoopOutput(string name) { // cases to handle: // name ="" no matching unknwn // name ="" unknown exists // name != "" no matching unknown // name !="" unknown exists YCurrentLoopOutput func = null; YCurrentLoopOutputProxy res = (YCurrentLoopOutputProxy)YFunctionProxy.FindSimilarUnknownFunction("YCurrentLoopOutputProxy"); if (name == "") { if (res != null) { return(res); } res = (YCurrentLoopOutputProxy)YFunctionProxy.FindSimilarKnownFunction("YCurrentLoopOutputProxy"); if (res != null) { return(res); } func = YCurrentLoopOutput.FirstCurrentLoopOutput(); if (func != null) { name = func.get_hardwareId(); if (func.get_userData() != null) { return((YCurrentLoopOutputProxy)func.get_userData()); } } } else { func = YCurrentLoopOutput.FindCurrentLoopOutput(name); if (func.get_userData() != null) { return((YCurrentLoopOutputProxy)func.get_userData()); } } if (res == null) { res = new YCurrentLoopOutputProxy(func, name); } if (func != null) { res.linkToHardware(name); if (func.isOnline()) { res.arrival(); } } return(res); }
/** * <summary> * Enumerates all functions of type CurrentLoopOutput available on the devices * currently reachable by the library, and returns their unique hardware ID. * <para> * Each of these IDs can be provided as argument to the method * <c>YCurrentLoopOutput.FindCurrentLoopOutput</c> to obtain an object that can control the * corresponding device. * </para> * </summary> * <returns> * an array of strings, each string containing the unique hardwareId * of a device function currently connected. * </returns> */ public static new string[] GetSimilarFunctions() { List <string> res = new List <string>(); YCurrentLoopOutput it = YCurrentLoopOutput.FirstCurrentLoopOutput(); while (it != null) { res.Add(it.get_hardwareId()); it = it.nextCurrentLoopOutput(); } return(res.ToArray()); }