public override async Task <int> Run() { try { await YAPI.RegisterHub(HubURL); YAnButton input1; YAnButton input5; if (Target.ToLower() == "any") { input1 = YAnButton.FirstAnButton(); if (input1 == null) { WriteLine("No module connected (check USB cable) "); return(-1); } Target = await(await input1.get_module()).get_serialNumber(); } input1 = YAnButton.FindAnButton(Target + ".anButton1"); input5 = YAnButton.FindAnButton(Target + ".anButton5"); while (await input1.isOnline()) { if (await input1.get_isPressed() == YAnButton.ISPRESSED_TRUE) { Write("Button 1: pressed "); } else { Write("Button 1: not pressed "); } WriteLine("- analog value: " + await input1.get_calibratedValue()); if (await input5.get_isPressed() == YAnButton.ISPRESSED_TRUE) { Write("Button 5: pressed "); } else { Write("Button 5: not pressed "); } WriteLine("- analog value: " + await input5.get_calibratedValue()); 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); }
public static YAnButtonProxy FindAnButton(string name) { // cases to handle: // name ="" no matching unknwn // name ="" unknown exists // name != "" no matching unknown // name !="" unknown exists YAnButton func = null; YAnButtonProxy res = (YAnButtonProxy)YFunctionProxy.FindSimilarUnknownFunction("YAnButtonProxy"); if (name == "") { if (res != null) { return(res); } res = (YAnButtonProxy)YFunctionProxy.FindSimilarKnownFunction("YAnButtonProxy"); if (res != null) { return(res); } func = YAnButton.FirstAnButton(); if (func != null) { name = func.get_hardwareId(); if (func.get_userData() != null) { return((YAnButtonProxy)func.get_userData()); } } } else { func = YAnButton.FindAnButton(name); if (func.get_userData() != null) { return((YAnButtonProxy)func.get_userData()); } } if (res == null) { res = new YAnButtonProxy(func, name); } if (func != null) { res.linkToHardware(name); if (func.isOnline()) { res.arrival(); } } return(res); }
/** * <summary> * Enumerates all functions of type AnButton 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>YAnButton.FindAnButton</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>(); YAnButton it = YAnButton.FirstAnButton(); while (it != null) { res.Add(it.get_hardwareId()); it = it.nextAnButton(); } return(res.ToArray()); }
static void Main(string[] args) { string errmsg = ""; string target; YAnButton input1; YAnButton input5; if (args.Length < 1) { usage(); } target = args[0].ToUpper(); if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS) { Console.WriteLine("RegisterHub error: " + errmsg); Environment.Exit(0); } if (target == "ANY") { input1 = YAnButton.FirstAnButton(); if (input1 == null) { Console.WriteLine("No module connected (check USB cable) "); Environment.Exit(0); } target = input1.get_module().get_serialNumber(); } input1 = YAnButton.FindAnButton(target + ".anButton1"); input5 = YAnButton.FindAnButton(target + ".anButton5"); if (!input1.isOnline()) { Console.WriteLine("Module not connected"); Console.WriteLine("check identification and USB cable"); Environment.Exit(0); } while (input1.isOnline()) { if (input1.get_isPressed() == YAnButton.ISPRESSED_TRUE) { Console.Write("Button 1: pressed "); } else { Console.Write("Button 1: not pressed "); } Console.WriteLine("- analog value: " + input1.get_calibratedValue().ToString()); if (input5.get_isPressed() == YAnButton.ISPRESSED_TRUE) { Console.Write("Button 5: pressed "); } else { Console.Write("Button 5: not pressed "); } Console.WriteLine("- analog value: " + input5.get_calibratedValue().ToString()); YAPI.Sleep(1000, ref errmsg); } YAPI.FreeAPI(); }