// link the instance to a real YoctoAPI object internal override void linkToHardware(string hwdName) { YDigitalIO hwd = YDigitalIO.FindDigitalIO(hwdName); // first redo base_init to update all _func pointers base_init(hwd, hwdName); // then setup Yocto-API pointers and callbacks init(hwd); }
// perform the 2nd stage setup that requires YoctoAPI object protected void init(YDigitalIO hwd) { if (hwd == null) { return; } base.init(hwd); InternalStuff.log("registering DigitalIO callback"); _func.registerValueCallback(valueChangeCallback); }
public static YDigitalIOProxy FindDigitalIO(string name) { // cases to handle: // name ="" no matching unknwn // name ="" unknown exists // name != "" no matching unknown // name !="" unknown exists YDigitalIO func = null; YDigitalIOProxy res = (YDigitalIOProxy)YFunctionProxy.FindSimilarUnknownFunction("YDigitalIOProxy"); if (name == "") { if (res != null) { return(res); } res = (YDigitalIOProxy)YFunctionProxy.FindSimilarKnownFunction("YDigitalIOProxy"); if (res != null) { return(res); } func = YDigitalIO.FirstDigitalIO(); if (func != null) { name = func.get_hardwareId(); if (func.get_userData() != null) { return((YDigitalIOProxy)func.get_userData()); } } } else { func = YDigitalIO.FindDigitalIO(name); if (func.get_userData() != null) { return((YDigitalIOProxy)func.get_userData()); } } if (res == null) { res = new YDigitalIOProxy(func, name); } if (func != null) { res.linkToHardware(name); if (func.isOnline()) { res.arrival(); } } return(res); }
/** * <summary> * Enumerates all functions of type DigitalIO 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>YDigitalIO.FindDigitalIO</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>(); YDigitalIO it = YDigitalIO.FirstDigitalIO(); while (it != null) { res.Add(it.get_hardwareId()); it = it.nextDigitalIO(); } return(res.ToArray()); }
/** * <summary> * Retrieves a digital IO port for a given identifier. * <para> * The identifier can be specified using several formats: * </para> * <para> * </para> * <para> * - FunctionLogicalName * </para> * <para> * - ModuleSerialNumber.FunctionIdentifier * </para> * <para> * - ModuleSerialNumber.FunctionLogicalName * </para> * <para> * - ModuleLogicalName.FunctionIdentifier * </para> * <para> * - ModuleLogicalName.FunctionLogicalName * </para> * <para> * </para> * <para> * This function does not require that the digital IO port is online at the time * it is invoked. The returned object is nevertheless valid. * Use the method <c>YDigitalIO.isOnline()</c> to test if the digital IO port is * indeed online at a given time. In case of ambiguity when looking for * a digital IO port by logical name, no error is notified: the first instance * found is returned. The search is performed first by hardware name, * then by logical name. * </para> * </summary> * <param name="func"> * a string that uniquely characterizes the digital IO port * </param> * <returns> * a <c>YDigitalIO</c> object allowing you to drive the digital IO port. * </returns> */ public static YDigitalIO FindDigitalIO(string func) { YDigitalIO obj; obj = (YDigitalIO)YFunction._FindFromCache("DigitalIO", func); if (obj == null) { obj = new YDigitalIO(func); YFunction._AddToCache("DigitalIO", func, obj); } return(obj); }
/** * <summary> * Retrieves a digital IO port for a given identifier. * <para> * The identifier can be specified using several formats: * </para> * <para> * </para> * <para> * - FunctionLogicalName * </para> * <para> * - ModuleSerialNumber.FunctionIdentifier * </para> * <para> * - ModuleSerialNumber.FunctionLogicalName * </para> * <para> * - ModuleLogicalName.FunctionIdentifier * </para> * <para> * - ModuleLogicalName.FunctionLogicalName * </para> * <para> * </para> * <para> * This function does not require that the digital IO port is online at the time * it is invoked. The returned object is nevertheless valid. * Use the method <c>YDigitalIO.isOnline()</c> to test if the digital IO port is * indeed online at a given time. In case of ambiguity when looking for * a digital IO port by logical name, no error is notified: the first instance * found is returned. The search is performed first by hardware name, * then by logical name. * </para> * </summary> * <param name="func"> * a string that uniquely characterizes the digital IO port * </param> * <returns> * a <c>YDigitalIO</c> object allowing you to drive the digital IO port. * </returns> */ public static YDigitalIO FindDigitalIO(string func) { YDigitalIO obj; obj = (YDigitalIO) YFunction._FindFromCache("DigitalIO", func); if (obj == null) { obj = new YDigitalIO(func); YFunction._AddToCache("DigitalIO", func, obj); } return obj; }
static void Main(string[] args) { string errmsg = ""; string target; YDigitalIO io; 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") { io = YDigitalIO.FirstDigitalIO(); if (io == null) { Console.WriteLine("No module connected (check USB cable) "); Environment.Exit(0); } } else { io = YDigitalIO.FindDigitalIO(target + ".digitalIO"); } // lets configure the channels direction // bits 0 and 1 as output // bits 2 and 3 as input io.set_portDirection(0x03); io.set_portPolarity(0); // polarity set to regular io.set_portOpenDrain(0); // No open drain Console.WriteLine("Channels 0..1 are configured as outputs and channels 2..3"); Console.WriteLine("are configred as inputs, you can connect some inputs to"); Console.WriteLine("ouputs and see what happens"); int outputdata = 0; while (io.isOnline()) { int inputdata = io.get_portState(); // read port values string line = ""; // display port value as binary for (int i = 0; i < 4; i++) { if ((inputdata & (8 >> i)) > 0) { line = line + '1'; } else { line = line + '0'; } } Console.WriteLine("port value = " + line); outputdata = (outputdata + 1) % 4; // cycle ouput 0..3 io.set_portState(outputdata); // We could have used set_bitState as well YAPI.Sleep(1000, ref errmsg); } YAPI.FreeAPI(); }
// perform the initial setup that may be done without a YoctoAPI object (hwd can be null) internal override void base_init(YFunction hwd, string instantiationName) { _func = (YDigitalIO)hwd; base.base_init(hwd, instantiationName); }
//--- (end of YDigitalIO definitions) //--- (YDigitalIO implementation) internal YDigitalIOProxy(YDigitalIO hwd, string instantiationName) : base(hwd, instantiationName) { InternalStuff.log("DigitalIO " + instantiationName + " instantiation"); base_init(hwd, instantiationName); }
public override async Task <int> Run() { try { await YAPI.RegisterHub(HubURL); YDigitalIO io; if (Target.ToLower() == "any") { io = YDigitalIO.FirstDigitalIO(); if (io == null) { WriteLine("No module connected (check USB cable) "); return(-1); } } else { io = YDigitalIO.FindDigitalIO(Target + ".digitalIO"); } // lets configure the channels direction // bits 0..3 as output // bits 4..7 as input await io.set_portDirection(0x0F); await io.set_portPolarity(0); // polarity set to regular await io.set_portOpenDrain(0); // No open drain WriteLine("Channels 0..3 are configured as outputs and channels 4..7"); WriteLine("are configred as inputs, you can connect some inputs to"); WriteLine("ouputs and see what happens"); int outputdata = 0; while (await io.isOnline()) { int inputdata = await io.get_portState(); // read port values string line = ""; // display port value as binary for (int i = 0; i < 8; i++) { if ((inputdata & (128 >> i)) > 0) { line = line + '1'; } else { line = line + '0'; } } WriteLine("port value = " + line); // cycle ouput 0..15 outputdata = (outputdata + 1) % 16; // We could have used set_bitState as well await io.set_portState(outputdata); await YAPI.Sleep(1000); } } catch (YAPI_Exception ex) { WriteLine("error: " + ex.Message); } YAPI.FreeAPI(); return(0); }