/**
         * <summary>
         *   Enumerates all functions of type ColorLed 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>YColorLed.FindColorLed</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>();
            YColorLed     it  = YColorLed.FirstColorLed();

            while (it != null)
            {
                res.Add(it.get_hardwareId());
                it = it.nextColorLed();
            }
            return(res.ToArray());
        }
예제 #2
0
        static int Main(string[] args)
        {
            string errmsg = "";
            int    i;
            int    nbled = 0;

            Console.WriteLine("Yoctopuce Library v" + YAPI.GetAPIVersion());
            Console.WriteLine("ColorMixer");
            if (args.Length < 1)
            {
                Console.WriteLine("usage: demo [usb | ip_address]");
                return(1);
            }

            for (i = 0; i < args.Length; i++)
            {
                // Setup the API to use local USB devices
                if (YAPI.RegisterHub(args[i], ref errmsg) != YAPI.SUCCESS)
                {
                    Console.WriteLine("Unable to get acces to devices on " + args[i]);
                    Console.WriteLine("error: " + errmsg);
                    return(1);
                }
            }

            // create our ColorMixer Object
            ColorMixer mixer = new ColorMixer();

            // get our pointer on our 3 knob
            // we use will reference the 3 knob by the logical name
            // that we have configured using the VirtualHub
            YAnButton knobRed   = YAnButton.FindAnButton("Red");
            YAnButton knobGreen = YAnButton.FindAnButton("Green");
            YAnButton knobBlue  = YAnButton.FindAnButton("Blue");

            // register these 3 knob to the mixer
            mixer.assignRedButton(knobRed);
            mixer.assignGreenButton(knobGreen);
            mixer.assignBlueButton(knobBlue);

            // display a warning if we miss a knob
            if (!knobRed.isOnline())
            {
                Console.WriteLine("Warning: knob \"" + knobRed + "\" is not connected");
            }
            if (!knobGreen.isOnline())
            {
                Console.WriteLine("Warning: knob \"" + knobGreen + "\" is not connected");
            }
            if (!knobBlue.isOnline())
            {
                Console.WriteLine("Warning: knob \"" + knobBlue + "\" is not connected");
            }

            // register all led that is connected to our "network"
            YColorLed led = YColorLed.FirstColorLed();

            while (led != null)
            {
                mixer.addLED(led);
                nbled++;
                led = led.nextColorLed();
            }
            Console.WriteLine(nbled + " Color Led detected", nbled);
            // never hanling loop that will..
            while (true)
            {
                // ... handle all event durring 5000ms without using lots of CPU ...
                YAPI.Sleep(1000, ref errmsg);
                // ... and check for device plug/unplug
                YAPI.UpdateDeviceList(ref errmsg);
            }
        }