Beispiel #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);
        }
Beispiel #2
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();
        }
Beispiel #3
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);
        }
Beispiel #4
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();
        }
Beispiel #5
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);
        }
Beispiel #6
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);
            }
        }
Beispiel #7
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);
        }
Beispiel #8
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);
        }
Beispiel #9
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);
            }
        }