Exemplo n.º 1
0
        // link the instance to a real YoctoAPI object
        internal override void linkToHardware(string hwdName)
        {
            YRelay hwd = YRelay.FindRelay(hwdName);

            // first redo base_init to update all _func pointers
            base_init(hwd, hwdName);
            // then setup Yocto-API pointers and callbacks
            init(hwd);
        }
Exemplo n.º 2
0
 // perform the 2nd stage setup that requires YoctoAPI object
 protected void init(YRelay hwd)
 {
     if (hwd == null)
     {
         return;
     }
     base.init(hwd);
     InternalStuff.log("registering Relay callback");
     _func.registerValueCallback(valueChangeCallback);
 }
Exemplo n.º 3
0
        /// <summary>Enumerates connected relays.  RegisterYocto must have been called first</summary>
        public static IEnumerable <YRelay> IterateRelays()
        {
            YRelay relay = YRelay.FirstRelay();

            while (relay != null)
            {
                yield return(relay);

                relay = relay.nextRelay();
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            string errmsg = "";
            string target;
            YRelay relay;
            string state;
            string channel;

            if (args.Length < 3)
            {
                usage();
            }
            target  = args[0].ToUpper();
            channel = args[1];
            state   = args[2].ToUpper();

            if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS)
            {
                Console.WriteLine("RegisterHub error: " + errmsg);
                Environment.Exit(0);
            }

            if (target == "ANY")
            {
                relay = YRelay.FirstRelay();
                if (relay == null)
                {
                    Console.WriteLine("No module connected (check USB cable) ");
                    Environment.Exit(0);
                }
                target = relay.get_module().get_serialNumber();
            }

            Console.WriteLine("using " + target);
            relay = YRelay.FindRelay(target + ".relay" + channel);

            if (relay.isOnline())
            {
                if (state == "ON")
                {
                    relay.set_output(YRelay.OUTPUT_ON);
                }
                else
                {
                    relay.set_output(YRelay.OUTPUT_OFF);
                }
            }
            else
            {
                Console.WriteLine("Module not connected");
                Console.WriteLine("check identification and USB cable");
            }
            YAPI.FreeAPI();
        }
Exemplo n.º 5
0
        public static YRelayProxy FindRelay(string name)
        {
            // cases to handle:
            // name =""  no matching unknwn
            // name =""  unknown exists
            // name != "" no  matching unknown
            // name !="" unknown exists
            YRelay      func = null;
            YRelayProxy res  = (YRelayProxy)YFunctionProxy.FindSimilarUnknownFunction("YRelayProxy");

            if (name == "")
            {
                if (res != null)
                {
                    return(res);
                }
                res = (YRelayProxy)YFunctionProxy.FindSimilarKnownFunction("YRelayProxy");
                if (res != null)
                {
                    return(res);
                }
                func = YRelay.FirstRelay();
                if (func != null)
                {
                    name = func.get_hardwareId();
                    if (func.get_userData() != null)
                    {
                        return((YRelayProxy)func.get_userData());
                    }
                }
            }
            else
            {
                func = YRelay.FindRelay(name);
                if (func.get_userData() != null)
                {
                    return((YRelayProxy)func.get_userData());
                }
            }
            if (res == null)
            {
                res = new YRelayProxy(func, name);
            }
            if (func != null)
            {
                res.linkToHardware(name);
                if (func.isOnline())
                {
                    res.arrival();
                }
            }
            return(res);
        }
Exemplo n.º 6
0
        /**
         * <summary>
         *   Enumerates all functions of type Relay 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>YRelay.FindRelay</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>();
            YRelay        it  = YRelay.FirstRelay();

            while (it != null)
            {
                res.Add(it.get_hardwareId());
                it = it.nextRelay();
            }
            return(res.ToArray());
        }
    /**
     * <summary>
     *   Retrieves a relay 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 relay is online at the time
     *   it is invoked. The returned object is nevertheless valid.
     *   Use the method <c>YRelay.isOnline()</c> to test if the relay is
     *   indeed online at a given time. In case of ambiguity when looking for
     *   a relay 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 relay
     * </param>
     * <returns>
     *   a <c>YRelay</c> object allowing you to drive the relay.
     * </returns>
     */
    public static YRelay FindRelay(string func)
    {
        YRelay obj;

        obj = (YRelay)YFunction._FindFromCache("Relay", func);
        if (obj == null)
        {
            obj = new YRelay(func);
            YFunction._AddToCache("Relay", func, obj);
        }
        return(obj);
    }
Exemplo n.º 8
0
    // --- (end of YRelay implementation)

    // --- (Relay functions)

    /**
     * <summary>
     *   Retrieves a relay 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 relay is online at the time
     *   it is invoked. The returned object is nevertheless valid.
     *   Use the method <c>YRelay.isOnline()</c> to test if the relay is
     *   indeed online at a given time. In case of ambiguity when looking for
     *   a relay 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 relay
     * </param>
     * <returns>
     *   a <c>YRelay</c> object allowing you to drive the relay.
     * </returns>
     */
    public static YRelay FindRelay(string func)
    {
        YRelay res;

        if (_RelayCache.ContainsKey(func))
        {
            return((YRelay)_RelayCache[func]);
        }
        res = new YRelay(func);
        _RelayCache.Add(func, res);
        return(res);
    }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            string errmsg = "";
            string target;
            YRelay relay;
            string state;

            if (args.Length < 2)
            {
                usage();
            }
            target = args[0].ToUpper();
            state  = args[1].ToUpper();

            if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS)
            {
                Console.WriteLine("RegisterHub error: " + errmsg);
                Environment.Exit(0);
            }

            if (target == "ANY")
            {
                relay = YRelay.FirstRelay();
                if (relay == null)
                {
                    Console.WriteLine("No module connected (check USB cable) ");
                    Environment.Exit(0);
                }
            }
            else
            {
                relay = YRelay.FindRelay(target + ".relay1");
            }

            if (relay.isOnline())
            {
                if (state == "A")
                {
                    relay.set_state(YRelay.STATE_A);
                }
                else
                {
                    relay.set_state(YRelay.STATE_B);
                }
            }
            else
            {
                Console.WriteLine("Module not connected");
                Console.WriteLine("check identification and USB cable");
            }
            YAPI.FreeAPI();
        }
Exemplo n.º 10
0
        private void refreshTimer_Tick(object sender, EventArgs e)
        {
            int     index;
            YModule m;
            YRelay  r;
            int     state, beacon;

            m          = null;
            index      = 4;
            beacon     = 0;
            state      = 0;
            timerindex = (timerindex + 1) % 3;

            if (!comboBox1.Enabled)
            {
                setImage(4);
                return;
            }

            m = (YModule)comboBox1.Items[comboBox1.SelectedIndex];
            r = YRelay.FindRelay(m.get_serialNumber() + ".relay1");
            if (r.isOnline())
            {
                state  = r.get_state();
                beacon = m.get_beacon();
            }
            else
            {
                setImage(4);
                return;
            }

            if ((beacon == YModule.BEACON_ON) && (timerindex > 0))
            {
                beacon = YModule.BEACON_OFF;
            }

            if (state == YRelay.STATE_A)
            {
                index = (beacon == YModule.BEACON_ON ? 1 : 0);
            }
            else
            {
                index = (beacon == YModule.BEACON_ON ? 3 : 2);
            }

            setImage(index);
        }
Exemplo n.º 11
0
        private void switchRelayOutput(int state)
        {
            YModule m;
            YRelay  r;

            if (!comboBox1.Enabled)
            {
                return;
            }
            m = (YModule)comboBox1.Items[comboBox1.SelectedIndex];
            r = YRelay.FindRelay(m.get_serialNumber() + ".relay1");
            if (r.isOnline())
            {
                r.set_state(state);
            }
        }
Exemplo n.º 12
0
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YRelay relay;
                if (Target.ToLower() == "any")
                {
                    relay = YRelay.FirstRelay();
                    if (relay == null)
                    {
                        WriteLine("No module connected (check USB cable) ");
                        return(-1);
                    }

                    Target = await(await relay.get_module()).get_serialNumber();
                }

                WriteLine("using " + Target + ".relay" + Channel);
                relay = YRelay.FindRelay(Target + ".relay" + Channel);

                if (await relay.isOnline())
                {
                    if (RequestedState.ToUpper() == "ON")
                    {
                        await relay.set_output(YRelay.OUTPUT_ON);
                    }
                    else
                    {
                        await relay.set_output(YRelay.OUTPUT_OFF);
                    }
                }
                else
                {
                    WriteLine("Module not connected (check identification and USB cable)");
                }
            } catch (YAPI_Exception ex) {
                WriteLine("error: " + ex.Message);
            }

            YAPI.FreeAPI();
            return(0);
        }
Exemplo n.º 13
0
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YRelay relay;

                if (Target.ToLower() == "any")
                {
                    relay = YRelay.FirstRelay();
                    if (relay == null)
                    {
                        WriteLine("No module connected (check USB cable) ");
                        return(-1);
                    }
                }
                else
                {
                    relay = YRelay.FindRelay(Target + ".relay1");
                }

                if (await relay.isOnline())
                {
                    if (RequestedState.ToUpper() == "A")
                    {
                        await relay.set_state(YRelay.STATE_A);
                    }
                    else
                    {
                        await relay.set_state(YRelay.STATE_B);
                    }
                }
                else
                {
                    WriteLine("Module not connected (check identification and USB cable)");
                }
            } catch (YAPI_Exception ex) {
                WriteLine("error: " + ex.Message);
            }

            YAPI.FreeAPI();
            return(0);
        }
Exemplo n.º 14
0
 /**
  * <summary>
  *   Retrieves a relay 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 relay is online at the time
  *   it is invoked. The returned object is nevertheless valid.
  *   Use the method <c>YRelay.isOnline()</c> to test if the relay is
  *   indeed online at a given time. In case of ambiguity when looking for
  *   a relay 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 relay
  * </param>
  * <returns>
  *   a <c>YRelay</c> object allowing you to drive the relay.
  * </returns>
  */
 public static YRelay FindRelay(string func)
 {
     YRelay obj;
     obj = (YRelay) YFunction._FindFromCache("Relay", func);
     if (obj == null) {
         obj = new YRelay(func);
         YFunction._AddToCache("Relay", func, obj);
     }
     return obj;
 }
Exemplo n.º 15
0
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            this.socket = IO.Socket("http://192.168.0.182:2000");

            timer          = new DispatcherTimer();
            timer.Interval = TimeSpan.FromMilliseconds(800); // 2 sec
            timer.Tick    += new EventHandler(timer_Tick);

            if (Window.GetWindow(this) != null)
            {
                WindowInteropHelper helper = new WindowInteropHelper(Window.GetWindow(this));
                HwndSource.FromHwnd(helper.Handle).AddHook(new HwndSourceHook(this.WndProc));
            }

            this.socket.On(Socket.EVENT_CONNECT_ERROR, () =>
            {
                Console.WriteLine("EVT_CON_ERR");
            });

            this.socket.On(Socket.EVENT_CONNECT_TIMEOUT, () =>
            {
                Console.WriteLine("EVT_CON_TOUT");
            });

            this.socket.On(Socket.EVENT_CONNECT, () =>
            {
                Console.WriteLine("EVT_CON");
            });

            this.socket.On(Socket.EVENT_DISCONNECT, () =>
            {
                Console.WriteLine("EVT_DISCON");
            });

            this.socket.On("attack-app-cs", () =>
            {
                timer.Start();
            });

            this.socket.On("attack-obd-cs", () =>
            {
                timer.Start();
            });

            this.socket.On("attack-auto-cs", () =>
            {
                timer.Start();
            });

            this.socket.On("attack-usb-cs", () =>
            {
                timer.Start();
            });

            this.socket.On("attack-rans-cs", () =>
            {
                timer.Start();
            });

            this.socket.On("check-usb", (v) =>
            {
                String command = v.ToString();
                Boolean found  = false;
                foreach (DriveInfo drive in DriveInfo.GetDrives())
                {
                    if (drive.DriveType == DriveType.Removable)
                    {
                        Console.WriteLine(string.Format("({0}) {1}", drive.Name.Replace("\\", ""), drive.VolumeLabel));
                        found = true;
                    }
                }

                if (found == true)
                {
                    if (command.Equals("check-usb-usb"))
                    {
                        this.socket.Emit("usb-status", "usb-on");
                    }
                    else if (command.Equals("check-rans-usb"))
                    {
                        this.socket.Emit("usb-status", "rans-on");
                    }
                }
                else
                {
                    this.socket.Emit("usb-status", "off");
                }
            });

            this.socket.On("reset", () =>
            {
                timer.Stop();
                ResetRelay();
            });

            this.socket.On("red", () =>
            {
                PR1(true);
                PR2(false);
                PR3(false);
                print_PR();
            });

            this.socket.On("yellow", () =>
            {
                PR1(false);
                PR2(true);
                PR3(false);
                print_PR();
            });

            this.socket.On("green", () =>
            {
                PR1(false);
                PR2(false);
                PR3(true);
                print_PR();
            });

            string errmsg = "";

            if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS)
            {
                MessageBox.Show("RegisterHub error: " + errmsg);
                Environment.Exit(0);
            }

            relay1 = YRelay.FindRelay("RELAYLO1-CD6A7.relay1");
            relay2 = YRelay.FindRelay("RELAYLO1-CD6A7.relay2");

            digout1 = new DigitalOutput();
            digout2 = new DigitalOutput();
            digout3 = new DigitalOutput();
            digout4 = new DigitalOutput();

            digout1.Channel = 0;
            digout2.Channel = 1;
            digout3.Channel = 2;
            digout4.Channel = 3;

            try
            {
                digout1.IsLocal = true;
                digout2.IsLocal = true;
                digout3.IsLocal = true;
                digout4.IsLocal = true;

                digout1.Open();
                digout2.Open();
                digout3.Open();
                digout4.Open();
            }
            catch (PhidgetException ex)
            {
                Console.WriteLine(ex);
            }
        }
Exemplo n.º 16
0
        //--- (end of YRelay definitions)

        //--- (YRelay implementation)
        internal YRelayProxy(YRelay hwd, string instantiationName) : base(hwd, instantiationName)
        {
            InternalStuff.log("Relay " + instantiationName + " instantiation");
            base_init(hwd, instantiationName);
        }
Exemplo n.º 17
0
 // 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 = (YRelay)hwd;
     base.base_init(hwd, instantiationName);
 }
Exemplo n.º 18
0
 // --- (end of YRelay implementation)
 // --- (Relay functions)
 /**
    * <summary>
    *   Retrieves a relay 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 relay is online at the time
    *   it is invoked. The returned object is nevertheless valid.
    *   Use the method <c>YRelay.isOnline()</c> to test if the relay is
    *   indeed online at a given time. In case of ambiguity when looking for
    *   a relay 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 relay
    * </param>
    * <returns>
    *   a <c>YRelay</c> object allowing you to drive the relay.
    * </returns>
    */
 public static YRelay FindRelay(string func)
 {
     YRelay res;
     if (_RelayCache.ContainsKey(func))
       return (YRelay)_RelayCache[func];
     res = new YRelay(func);
     _RelayCache.Add(func, res);
     return res;
 }