Ejemplo n.º 1
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            if (!started)
            {
                string url = this.url.Text;
                try {
                    YAPI.RegisterLogFunction(yoctoLog);
                    await YAPI.RegisterHub(url);

                    YAPI.RegisterDeviceArrivalCallback(deviceArrival);
                    YAPI.RegisterDeviceRemovalCallback(deviceRemoval);
                } catch (YAPI_Exception ex) {
                    Output.Text = "Error:" + ex.Message + "\n";
                    return;
                }

                timer          = new DispatcherTimer();
                timer.Interval = new TimeSpan(0, 0, 0, 0, 100); // 100 Milliseconds
                timer.Tick    += new EventHandler <object>(Each_Tick);
                timer.Start();
                initButton.Content = "Stop";
                started            = true;
            }
            else
            {
                timer.Stop();
                YAPI.FreeAPI();
                initButton.Content = "Start";
                started            = false;
            }
        }
Ejemplo n.º 2
0
        public override async Task <int> Run()
        {
            try {
                YModule m;

                await YAPI.RegisterHub(HubURL);

                m = YModule.FindModule(Target); // use serial or logical name
                if (await m.isOnline())
                {
                    if (!YAPI.CheckLogicalName(LogicalName))
                    {
                        WriteLine("Invalid name (" + LogicalName + ")");
                        return(-1);
                    }

                    await m.set_logicalName(LogicalName);

                    await m.saveToFlash(); // do not forget this

                    Write("Module: serial= " + await m.get_serialNumber());
                    WriteLine(" / name= " + await m.get_logicalName());
                }
                else
                {
                    Write("not connected (check identification and USB cable");
                }
            } catch (YAPI_Exception ex) {
                WriteLine("RegisterHub error: " + ex.Message);
            }
            YAPI.FreeAPI();
            return(0);
        }
Ejemplo n.º 3
0
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YLightSensor sensor;

                if (Target.ToLower() == "any")
                {
                    sensor = YLightSensor.FirstLightSensor();
                    if (sensor == null)
                    {
                        WriteLine("No module connected (check USB cable) ");
                        return(-1);
                    }
                }
                else
                {
                    sensor = YLightSensor.FindLightSensor(Target + ".lightSensor");
                }

                while (await sensor.isOnline())
                {
                    WriteLine("Ambient light: " + await sensor.get_currentValue() + " lx");
                    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);
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            string      errmsg = "";
            string      target;
            YSerialPort serialPort;

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

            if (args.Length > 0 && args[0] != "any")
            {
                target     = args[0];
                serialPort = YSerialPort.FindSerialPort(target + ".serialPort");
                if (!serialPort.isOnline())
                {
                    Console.WriteLine("No module connected (check cable)");
                    Environment.Exit(0);
                }
            }
            else
            {
                serialPort = YSerialPort.FirstSerialPort();
                if (serialPort == null)
                {
                    Console.WriteLine("No module connected (check USB cable)");
                    Environment.Exit(0);
                }
            }

            Console.WriteLine("****************************");
            Console.WriteLine("* make sure voltage levels *");
            Console.WriteLine("* are properly configured  *");
            Console.WriteLine("****************************");

            serialPort.set_serialMode("9600,8N1");
            serialPort.set_protocol("Line");
            serialPort.reset();

            string line;

            do
            {
                YAPI.Sleep(500, ref errmsg);
                do
                {
                    line = serialPort.readLine();
                    if (line != "")
                    {
                        Console.WriteLine("Received: " + line);
                    }
                } while (line != "");
                Console.WriteLine("Type line to send, or Ctrl-C to exit: ");
                line = Console.ReadLine();
                serialPort.writeLine(line);
            } while (line != "");
            YAPI.FreeAPI();
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            string errmsg = "";

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

            YSensor sensor;

            if (args.Length == 0 || args[0] == "any")
            {
                sensor = YSensor.FirstSensor();
                if (sensor == null)
                {
                    Console.WriteLine("No module connected (check USB cable)");
                    Environment.Exit(1);
                }
            }
            else
            {
                sensor = YSensor.FindSensor(args[0]);
                if (!sensor.isOnline())
                {
                    Console.WriteLine("Sensor " + sensor + " is not connected (check USB cable)");
                    Environment.Exit(1);
                }
            }
            dumpSensor(sensor);
            YAPI.FreeAPI();
            Console.WriteLine("Done. Have a nice day :)");
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            string             errmsg = "";
            string             target;
            YCurrentLoopOutput loop;
            double             value;

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

            if (args.Length < 2)
            {
                usage();
            }

            target = args[0].ToUpper();
            value  = Convert.ToDouble(args[1]);

            if (target == "ANY")
            {
                loop = YCurrentLoopOutput.FirstCurrentLoopOutput();
                if (loop == null)
                {
                    Console.WriteLine("No module connected (check USB cable) ");
                    Environment.Exit(0);
                }
            }
            else
            {
                loop = YCurrentLoopOutput.FindCurrentLoopOutput(target + ".currentLoopOutput");
            }

            if (loop.isOnline())
            {
                loop.set_current(value);
                int loopPower = loop.get_loopPower();
                if (loopPower == YCurrentLoopOutput.LOOPPOWER_NOPWR)
                {
                    Console.WriteLine("Current loop not powered");
                    Environment.Exit(0);
                }
                if (loopPower == YCurrentLoopOutput.LOOPPOWER_LOWPWR)
                {
                    Console.WriteLine("Insufficient voltage on current loop");
                    Environment.Exit(0);
                }

                Console.WriteLine("current loop set to " + value.ToString() + " mA");
            }
            else
            {
                Console.WriteLine("Module not connected");
                Console.WriteLine("check identification and USB cable");
            }
            YAPI.FreeAPI();
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            string errmsg = "";
            string target;

            YGenericSensor sensor;

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

            // Setup the API to use local USB devices
            if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS)
            {
                Console.WriteLine("RegisterHub error: " + errmsg);
                Environment.Exit(0);
            }

            if (target == "ANY")
            {
                sensor = YGenericSensor.FirstGenericSensor();

                if (sensor == null)
                {
                    Console.WriteLine("No module connected (check USB cable) ");
                    Environment.Exit(0);
                }
                Console.WriteLine("Using: " + sensor.get_module().get_serialNumber());
            }
            else
            {
                sensor = YGenericSensor.FindGenericSensor(target + ".genericSensor1");
            }

            // retreive module serial
            string serial = sensor.get_module().get_serialNumber();

            // retreive both channels
            YGenericSensor ch1 = YGenericSensor.FindGenericSensor(serial + ".genericSensor1");

            string unitSensor1 = "";

            if (ch1.isOnline())
            {
                unitSensor1 = ch1.get_unit();
            }

            while (ch1.isOnline())
            {
                Console.Write("Value: " + ch1.get_currentValue().ToString() + unitSensor1);
                Console.WriteLine("  (press Ctrl-C to exit)");
                YAPI.Sleep(1000, ref errmsg);
            }
            YAPI.FreeAPI();
            Console.WriteLine("Module not connected");
            Console.WriteLine("check identification and USB cable");
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            string errmsg = "";
            string target;

            YWeighScale sensor;

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

            // Setup the API to use local USB devices
            if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS)
            {
                Console.WriteLine("RegisterHub error: " + errmsg);
                Environment.Exit(0);
            }

            if (target == "ANY")
            {
                sensor = YWeighScale.FirstWeighScale();
                if (sensor == null)
                {
                    Console.WriteLine("No module connected (check USB cable) ");
                    Environment.Exit(0);
                }

                Console.WriteLine("Using: " + sensor.get_module().get_serialNumber());
            }
            else
            {
                sensor = YWeighScale.FindWeighScale(target + ".weighScale1");
            }

            if (sensor.isOnline())
            {
                string unit = "";
                // On startup, enable excitation and tare weigh scale
                Console.WriteLine("Resetting tare weight...");
                sensor.set_excitation(YWeighScale.EXCITATION_AC);
                YAPI.Sleep(3000, ref errmsg);
                sensor.tare();
                unit = sensor.get_unit();

                // Show measured weight continuously
                while (sensor.isOnline())
                {
                    Console.Write("Weight : " + sensor.get_currentValue().ToString() + unit);
                    Console.WriteLine("  (press Ctrl-C to exit)");
                    YAPI.Sleep(1000, ref errmsg);
                }
            }

            YAPI.FreeAPI();
            Console.WriteLine("Module not connected");
            Console.WriteLine("check identification and USB cable");
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            string   errmsg = "";
            string   target;
            YVoltage sensor;
            YVoltage sensorDC = null;
            YVoltage sensorAC = null;
            YModule  m        = null;

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

            // Setup the API to use local USB devices
            if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS)
            {
                Console.WriteLine("RegisterHub error: " + errmsg);
                Environment.Exit(0);
            }

            if (target == "ANY")
            {
                // retreive any voltage sensor (can be AC or DC)
                sensor = YVoltage.FirstVoltage();
                if (sensor == null)
                {
                    die("No module connected");
                }
            }
            else
            {
                sensor = YVoltage.FindVoltage(target + ".voltage1");
            }

            // we need to retreive both DC and AC voltage from the device.
            if (sensor.isOnline())
            {
                m        = sensor.get_module();
                sensorDC = YVoltage.FindVoltage(m.get_serialNumber() + ".voltage1");
                sensorAC = YVoltage.FindVoltage(m.get_serialNumber() + ".voltage2");
            }
            else
            {
                die("Module not connected");
            }

            while (m.isOnline())
            {
                Console.Write("DC: " + sensorDC.get_currentValue().ToString() + " v ");
                Console.Write("AC: " + sensorAC.get_currentValue().ToString() + " v ");

                Console.WriteLine("  (press Ctrl-C to exit)");

                YAPI.Sleep(1000, ref errmsg);
            }
            YAPI.FreeAPI();
        }
Ejemplo n.º 10
0
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YSerialPort serialPort;

                if (Target.ToLower() == "any")
                {
                    serialPort = YSerialPort.FirstSerialPort();
                    if (serialPort == null)
                    {
                        WriteLine("No module connected (check USB cable) ");
                        return(-1);
                    }
                    YModule ymod = await serialPort.get_module();

                    WriteLine("Using: " + await ymod.get_serialNumber());
                }
                else
                {
                    serialPort = YSerialPort.FindSerialPort(Target + ".serialPort");
                }

                await serialPort.set_serialMode("9600,8N1");

                await serialPort.set_protocol("Line");

                await serialPort.reset();

                string line;
                do
                {
                    if (ToSend != "")
                    {
                        await serialPort.writeLine(ToSend);

                        ToSend = "";
                    }
                    await YAPI.Sleep(500);

                    do
                    {
                        line = await serialPort.readLine();

                        if (line != "")
                        {
                            WriteLine("Received: " + line);
                        }
                    } while (line != "");
                } while (line != "");
            } catch (YAPI_Exception ex) {
                WriteLine("error: " + ex.Message);
            }

            YAPI.FreeAPI();
            return(0);
        }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            string errmsg = "";
            string target;

            YTemperature tsensor;

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

            // Setup the API to use local USB devices
            if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS)
            {
                Console.WriteLine("RegisterHub error: " + errmsg);
                Environment.Exit(0);
            }

            if (target == "ANY")
            {
                tsensor = YTemperature.FirstTemperature();

                if (tsensor == null)
                {
                    Console.WriteLine("No module connected (check USB cable) ");
                    Environment.Exit(0);
                }
                Console.WriteLine("Using: " + tsensor.get_module().get_serialNumber());
            }
            else
            {
                tsensor = YTemperature.FindTemperature(target + ".temperature1");
            }

            // retreive module serial
            string serial = tsensor.get_module().get_serialNumber();

            // retreive both channels
            YTemperature ch1 = YTemperature.FindTemperature(serial + ".temperature1");
            YTemperature ch2 = YTemperature.FindTemperature(serial + ".temperature2");

            if (!ch2.isOnline())
            {
                Console.WriteLine("Module not connected");
                Console.WriteLine("check identification and USB cable");
                Environment.Exit(0);
            }
            while (ch2.isOnline())
            {
                Console.Write("Ambiant: " + ch1.get_currentValue().ToString() + " °C  ");
                Console.Write("Infrared: " + ch2.get_currentValue().ToString() + " °C  ");
                Console.WriteLine("  (press Ctrl-C to exit)");
                YAPI.Sleep(1000, ref errmsg);
            }
            YAPI.FreeAPI();
        }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            Console.WriteLine("Console dotNET Application 0.1.0");
            Console.WriteLine("--------------------------------");
            Console.WriteLine("");

            Console.WriteLine("Using Yoctopuce lib " + YAPI.GetAPIVersion());
            string errsmg = "";

            if (YAPI.RegisterHub("usb", ref errsmg) != YAPI.SUCCESS)
            {
                Console.WriteLine("Unable to register the USB port :" + errsmg);
                return;
            }

            YSensor sensor = YSensor.FirstSensor();

            if (sensor == null)
            {
                Console.WriteLine("No Yoctopuce sensor find on USB.");
                return;
            }

            YDisplay display = YDisplay.FirstDisplay();

            if (display == null)
            {
                Console.WriteLine("No Yoctopuce display find on USB.");
                return;
            }

            // display clean up
            display.resetAll();

            YDisplayLayer l1 = display.get_displayLayer(1);

            l1.hide();    // L1 is hidden, l2 stay visible
            int w = display.get_displayWidth();
            int h = display.get_displayHeight();


            while (sensor.isOnline() && display.isOnline())
            {
                string value = sensor.get_currentValue() + " " + sensor.get_unit();
                string name  = sensor.get_friendlyName();
                // display a text in the middle of the screen
                l1.clear();
                l1.selectFont("Large.yfm");
                l1.drawText(w / 2, h / 2, YDisplayLayer.ALIGN.CENTER, value);
                l1.selectFont("Small.yfm");
                l1.drawText(w - 1, h - 1, YDisplayLayer.ALIGN.BOTTOM_RIGHT, name);
                display.swapLayerContent(0, 1);
                Console.WriteLine(name + " ->" + value);
                YAPI.Sleep(500, ref errsmg);
            }
            YAPI.FreeAPI();
        }
Ejemplo n.º 13
0
        static void Main(string[] args)
        {
            string errmsg = "";
            string target;

            YGps gps;

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

            // Setup the API to use local USB devices
            if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS)
            {
                Console.WriteLine("RegisterHub error: " + errmsg);
                Environment.Exit(0);
            }

            if (target == "ANY")
            {
                gps = YGps.FirstGps();

                if (gps == null)
                {
                    Console.WriteLine("No module connected (check USB cable) ");
                    Environment.Exit(0);
                }
            }
            else
            {
                gps = YGps.FindGps(target + ".gps");
            }

            if (!gps.isOnline())
            {
                Console.WriteLine("Module not connected");
                Console.WriteLine("check identification and USB cable");
                Environment.Exit(0);
            }
            while (gps.isOnline())
            {
                if (gps.get_isFixed() != YGps.ISFIXED_TRUE)
                {
                    Console.WriteLine("fixing... ");
                }
                else
                {
                    Console.WriteLine(gps.get_latitude() + "  " + gps.get_longitude());
                }
                Console.WriteLine("  (press Ctrl-C to exit)");

                YAPI.Sleep(1000, ref errmsg);
            }
            YAPI.FreeAPI();
        }
Ejemplo n.º 14
0
 private void btnDeco_Click(object sender, EventArgs e)
 {
     btnConnexion.Enabled = true;
     btnDeco.Enabled      = false;
     YAPI.UnregisterHub("usb");
     YAPI.FreeAPI();
     timer1.Enabled             = false;
     toolStripStatusLabel1.Text = "Connecté : Non";
 }
Ejemplo n.º 15
0
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YPwmOutput pwmoutput1;
                YPwmOutput pwmoutput2;
                int        frequency;
                double     dutyCycle;

                frequency = Convert.ToInt32(RequestedFrequency);
                dutyCycle = Convert.ToDouble(RequestedDutyCycle);

                if (Target.ToLower() == "any")
                {
                    pwmoutput1 = YPwmOutput.FirstPwmOutput();
                    if (pwmoutput1 == null)
                    {
                        WriteLine("No module connected (check USB cable) ");
                        return(-1);
                    }

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

                pwmoutput1 = YPwmOutput.FindPwmOutput(Target + ".pwmOutput1");
                pwmoutput2 = YPwmOutput.FindPwmOutput(Target + ".pwmOutput2");

                if (await pwmoutput1.isOnline())
                {
                    // output 1 : immediate change
                    await pwmoutput1.set_frequency(frequency);

                    await pwmoutput1.set_enabled(YPwmOutput.ENABLED_TRUE);

                    await pwmoutput1.set_dutyCycle(dutyCycle);

                    // output 2 : smooth change
                    await pwmoutput2.set_frequency(frequency);

                    await pwmoutput2.set_enabled(YPwmOutput.ENABLED_TRUE);

                    await pwmoutput2.dutyCycleMove(dutyCycle, 3000);

                    WriteLine("done");
                }
                else
                {
                    WriteLine("Module not connected (check identification and USB cable)");
                }
            } catch (YAPI_Exception ex) {
                WriteLine("error: " + ex.Message);
            }

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

                YMotor       motor;
                YCurrent     current;
                YVoltage     voltage;
                YTemperature temperature;

                if (Target.ToLower() == "any")
                {
                    // find the serial# of the first available motor
                    motor = YMotor.FirstMotor();
                    if (motor == null)
                    {
                        WriteLine("No module connected (check USB cable) ");
                        return(-1);
                    }

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

                int power = Convert.ToInt32(Power);
                motor       = YMotor.FindMotor(Target + ".motor");
                current     = YCurrent.FindCurrent(Target + ".current");
                voltage     = YVoltage.FindVoltage(Target + ".voltage");
                temperature = YTemperature.FindTemperature(Target + ".temperature");

                // lets start the motor
                if (await motor.isOnline())
                {
                    // if motor is in error state, reset it.
                    if (await motor.get_motorStatus() >= YMotor.MOTORSTATUS_LOVOLT)
                    {
                        await motor.resetStatus();
                    }

                    await motor.drivingForceMove(power, 2000); // ramp up to power in 2 seconds

                    while (await motor.isOnline())
                    {
                        // display motor status
                        WriteLine("Status=" + await motor.get_advertisedValue() + "  "
                                  + "Voltage=" + await voltage.get_currentValue() + "V  "
                                  + "Current=" + await current.get_currentValue() / 1000 + "A  "
                                  + "Temp=" + await temperature.get_currentValue() + "deg C");
                        await YAPI.Sleep(1000); // wait for one second
                    }
                }
            } catch (YAPI_Exception ex) {
                WriteLine("error: " + ex.Message);
            }

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

                YGenericSensor tsensor;

                if (Target.ToLower() == "any")
                {
                    tsensor = YGenericSensor.FirstGenericSensor();
                    if (tsensor == null)
                    {
                        WriteLine("No module connected (check USB cable) ");
                        return(-1);
                    }

                    YModule m = await tsensor.get_module();

                    Target = await m.get_serialNumber();
                }

                // retreive module serial
                WriteLine("Using: " + Target);

                // retreive both channels
                YGenericSensor ch1, ch2;
                ch1 = YGenericSensor.FindGenericSensor(Target + ".genericSensor1");
                ch2 = YGenericSensor.FindGenericSensor(Target + ".genericSensor2");

                string unitSensor1 = "", unitSensor2 = "";
                if (await ch1.isOnline())
                {
                    unitSensor1 = await ch1.get_unit();
                }

                if (await ch2.isOnline())
                {
                    unitSensor2 = await ch2.get_unit();
                }

                while (await ch1.isOnline() && await ch2.isOnline())
                {
                    Write("Channel 1 : " + await ch1.get_currentValue() + unitSensor1);
                    Write("  Channel 2 : " + await ch2.get_currentValue() + unitSensor2);
                    WriteLine("  (press Ctrl-C to exit)");
                    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);
        }
Ejemplo n.º 18
0
        static void Main(string[] args)
        {
            string    errmsg = "";
            string    target;
            YWatchdog watchdog;
            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")
            {
                watchdog = YWatchdog.FirstWatchdog();
                if (watchdog == null)
                {
                    Console.WriteLine("No module connected (check USB cable) ");
                    Environment.Exit(0);
                }
            }
            else
            {
                watchdog = YWatchdog.FindWatchdog(target + ".watchdog1");
            }

            if (watchdog.isOnline())
            {
                if (state == "ON")
                {
                    watchdog.set_running(YWatchdog.RUNNING_ON);
                }
                if (state == "OFF")
                {
                    watchdog.set_running(YWatchdog.RUNNING_OFF);
                }
                if (state == "RESET")
                {
                    watchdog.resetWatchdog();
                }
            }
            else
            {
                Console.WriteLine("Module not connected");
                Console.WriteLine("check identification and USB cable");
            }
            YAPI.FreeAPI();
        }
        public void formClosing(FormClosingEventArgs e)
        {
            if ((e.CloseReason == CloseReason.UserClosing) && (!mainForm.isClosing) && (!Closing))
            {
                mainForm.Terminate();
                e.Cancel = true;

                YAPI.FreeAPI();
            }
        }
Ejemplo n.º 20
0
        static void Main(string[] args)
        {
            string       errmsg = "";
            string       target;
            YRangeFinder rf;
            YLightSensor ir;
            YTemperature tmp;

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

            // Setup the API to use local USB devices
            if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS)
            {
                Console.WriteLine("RegisterHub error: " + errmsg);
                Environment.Exit(0);
            }

            if (target == "ANY")
            {
                rf = YRangeFinder.FirstRangeFinder();
                if (rf == null)
                {
                    Console.WriteLine("No module connected (check USB cable) ");
                    Environment.Exit(0);
                }
                target = rf.get_module().get_serialNumber();
            }
            else
            {
                rf = YRangeFinder.FindRangeFinder(target + ".rangefinder1");
            }

            if (!rf.isOnline())
            {
                Console.WriteLine("Module not connected");
                Console.WriteLine("check identification and USB cable");
                Environment.Exit(0);
            }
            ir  = YLightSensor.FindLightSensor(target + ".lightSensor1");
            tmp = YTemperature.FindTemperature(target + ".temperature1");

            while (rf.isOnline())
            {
                Console.WriteLine("Distance    : " + rf.get_currentValue().ToString());
                Console.WriteLine("Ambiant IR  : " + ir.get_currentValue().ToString());
                Console.WriteLine("Temperature : " + tmp.get_currentValue().ToString());
                Console.WriteLine("  (press Ctrl-C to exit)");
                YAPI.Sleep(1000, ref errmsg);
            }
            YAPI.FreeAPI();
        }
Ejemplo n.º 21
0
        static void Main(string[] args)
        {
            string     errmsg = "";
            string     target;
            YPwmOutput pwmoutput1;
            YPwmOutput pwmoutput2;
            int        frequency;
            double     dutyCycle;

            if (args.Length < 3)
            {
                usage();
            }
            target    = args[0].ToUpper();
            frequency = Convert.ToInt32(args[1]);
            dutyCycle = Convert.ToDouble(args[2]);

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

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

            pwmoutput1 = YPwmOutput.FindPwmOutput(target + ".pwmOutput1");
            pwmoutput2 = YPwmOutput.FindPwmOutput(target + ".pwmOutput2");

            if (pwmoutput1.isOnline())
            {
                // output 1 : immediate change
                pwmoutput1.set_frequency(frequency);
                pwmoutput1.set_enabled(YPwmOutput.ENABLED_TRUE);
                pwmoutput1.set_dutyCycle(dutyCycle);
                // output 2 : smooth change
                pwmoutput2.set_frequency(frequency);
                pwmoutput2.set_enabled(YPwmOutput.ENABLED_TRUE);
                pwmoutput2.dutyCycleMove(dutyCycle, 3000);
            }
            else
            {
                Console.WriteLine("Module not connected");
                Console.WriteLine("check identification and USB cable");
            }
            YAPI.FreeAPI();
        }
Ejemplo n.º 22
0
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YColorLed led1;
                int       color;
                ColorStr = ColorStr.ToUpper();

                if (ColorStr == "RED")
                {
                    color = 0xFF0000;
                }
                else if (ColorStr == "GREEN")
                {
                    color = 0x00FF00;
                }
                else if (ColorStr == "BLUE")
                {
                    color = 0x0000FF;
                }
                else
                {
                    color = Convert.ToInt32("0x" + ColorStr, 16);
                }

                if (Target.ToLower() == "any")
                {
                    led1 = YColorLed.FirstColorLed();
                    if (led1 == null)
                    {
                        WriteLine("No module connected (check USB cable) ");
                        return(-1);
                    }
                }
                else
                {
                    led1 = YColorLed.FindColorLed(Target + ".colorLed1");
                }

                if (await led1.isOnline())
                {
                    WriteLine("smooth transition to " + color.ToString("x"));
                    await led1.rgbMove(color, 1000);
                }
                else
                {
                    WriteLine("Module not connected (check identification and USB cable)");
                }
            } catch (YAPI_Exception ex) {
                WriteLine("error: " + ex.Message);
            }
            YAPI.FreeAPI();
            return(0);
        }
Ejemplo n.º 23
0
        static void Main(string[] args)
        {
            string       errmsg = "";
            string       target;
            YLightSensor ir, al;
            YProximity   p;

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

            // Setup the API to use local USB devices
            if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS)
            {
                Console.WriteLine("RegisterHub error: " + errmsg);
                Environment.Exit(0);
            }

            if (target == "ANY")
            {
                p = YProximity.FirstProximity();
                if (p == null)
                {
                    Console.WriteLine("No module connected (check USB cable) ");
                    Environment.Exit(0);
                }
                target = p.get_module().get_serialNumber();
            }
            else
            {
                p = YProximity.FindProximity(target + ".proximity1");
            }

            if (!p.isOnline())
            {
                Console.WriteLine("Module not connected");
                Console.WriteLine("check identification and USB cable");
                Environment.Exit(0);
            }
            al = YLightSensor.FindLightSensor(target + ".lightSensor1");
            ir = YLightSensor.FindLightSensor(target + ".lightSensor2");

            while (p.isOnline())
            {
                Console.Write(" Proximity: " + p.get_currentValue().ToString());
                Console.Write(" Ambiant: " + al.get_currentValue().ToString());
                Console.Write(" IR: " + ir.get_currentValue().ToString());

                Console.WriteLine("  (press Ctrl-C to exit)");
                YAPI.Sleep(1000, ref errmsg);
            }
            YAPI.FreeAPI();
        }
Ejemplo n.º 24
0
        static void Main(string[] args)
        {
            int           i;
            List <string> hubs    = new List <string>();
            List <string> shield  = new List <string>();
            List <string> devices = new List <string>();

            string errmsg = "";


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

            for (i = 0; i < args.Length; i++)
            {
                Console.WriteLine("Update module connected to hub " + args[i]);
                if (YAPI.RegisterHub(args[i], ref errmsg) != YAPI.SUCCESS)
                {
                    Console.WriteLine("RegisterHub error: " + errmsg);
                    Environment.Exit(1);
                }
            }
            //fist step construct the list of all hub /shield and devices connected
            YModule module = YModule.FirstModule();

            while (module != null)
            {
                string product = module.get_productName();
                string serial  = module.get_serialNumber();
                if (product == "YoctoHub-Shield")
                {
                    shield.Add(serial);
                }
                else if (product.StartsWith("YoctoHub"))
                {
                    hubs.Add(serial);
                }
                else if (product != "VirtualHub")
                {
                    devices.Add(serial);
                }
                module = module.nextModule();
            }
            // fist upgrades all Hubs...
            upgradeSerialList(hubs);
            // ... then all shield..
            upgradeSerialList(shield);
            // ... and finaly all devices
            upgradeSerialList(devices);
            Console.WriteLine("All devices are now up to date");
            YAPI.FreeAPI();
        }
Ejemplo n.º 25
0
        static void Main(string[] args)
        {
            YModule m;
            string  errmsg = "";

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


            if (args.Length < 1)
            {
                usage();
            }

            m = YModule.FindModule(args[0]); // use serial or logical name

            if (m.isOnline())
            {
                if (args.Length >= 2)
                {
                    if (args[1].ToUpper() == "ON")
                    {
                        m.set_beacon(YModule.BEACON_ON);
                    }
                    if (args[1].ToUpper() == "OFF")
                    {
                        m.set_beacon(YModule.BEACON_OFF);
                    }
                }

                Console.WriteLine("serial:       " + m.get_serialNumber());
                Console.WriteLine("logical name: " + m.get_logicalName());
                Console.WriteLine("luminosity:   " + m.get_luminosity().ToString());
                Console.Write("beacon:       ");
                if (m.get_beacon() == YModule.BEACON_ON)
                {
                    Console.WriteLine("ON");
                }
                else
                {
                    Console.WriteLine("OFF");
                }
                Console.WriteLine("upTime:       " + (m.get_upTime() / 1000).ToString() + " sec");
                Console.WriteLine("USB current:  " + m.get_usbCurrent().ToString() + " mA");
                Console.WriteLine("Logs:\r\n" + m.get_lastLogs());
            }
            else
            {
                Console.WriteLine(args[0] + " not connected (check identification and USB cable)");
            }
            YAPI.FreeAPI();
        }
Ejemplo n.º 26
0
        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);
        }
Ejemplo n.º 27
0
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YTilt          anytilt, tilt1, tilt2;
                YCompass       compass;
                YAccelerometer accel;
                YGyro          gyro;

                if (Target.ToLower() == "any")
                {
                    anytilt = YTilt.FirstTilt();
                    if (anytilt == null)
                    {
                        WriteLine("No module connected (check USB cable)");
                        return(-1);
                    }
                }
                else
                {
                    anytilt = YTilt.FindTilt(Target + ".tilt1");
                }

                string serial = await(await anytilt.get_module()).get_serialNumber();
                tilt1   = YTilt.FindTilt(serial + ".tilt1");
                tilt2   = YTilt.FindTilt(serial + ".tilt2");
                compass = YCompass.FindCompass(serial + ".compass");
                accel   = YAccelerometer.FindAccelerometer(serial + ".accelerometer");
                gyro    = YGyro.FindGyro(serial + ".gyro");
                int count = 0;

                while (await tilt1.isOnline())
                {
                    if (count++ % 10 == 0)
                    {
                        WriteLine("tilt1   tilt2   compass   acc   gyro");
                    }
                    Write(await tilt1.get_currentValue() + "\t");
                    Write(await tilt2.get_currentValue() + "\t");
                    Write(await compass.get_currentValue() + "\t");
                    Write(await accel.get_currentValue() + "\t");
                    WriteLine("" + await gyro.get_currentValue());
                    await YAPI.Sleep(250);
                }

                WriteLine("Module not connected (check identification and USB cable)");
            } catch (YAPI_Exception ex) {
                WriteLine("error: " + ex.Message);
            }

            YAPI.FreeAPI();
            return(0);
        }
Ejemplo n.º 28
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();
        }
Ejemplo n.º 29
0
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YPwmInput pwm;
                YPwmInput pwm1 = null;
                YPwmInput pwm2 = null;
                YModule   m    = null;
                if (Target.ToLower() == "any")
                {
                    // retreive any pwm input available
                    pwm = YPwmInput.FirstPwmInput();
                    if (pwm == null)
                    {
                        WriteLine("No module connected");
                        return(-1);
                    }
                }
                else
                {
                    // retreive the first pwm input from the device given on command line
                    pwm = YPwmInput.FindPwmInput(Target + ".pwmInput1");
                }

                // we need to retreive both channels from the device.
                if (await pwm.isOnline())
                {
                    m = await pwm.get_module();

                    pwm1 = YPwmInput.FindPwmInput(await m.get_serialNumber() + ".pwmInput1");
                    pwm2 = YPwmInput.FindPwmInput(await m.get_serialNumber() + ".pwmInput2");
                }

                while (await m.isOnline())
                {
                    WriteLine("PWM1: " + await pwm1.get_frequency() + " Hz " + await
                              pwm1.get_dutyCycle() +
                              " % " + await pwm1.get_pulseCounter() + " pulse edges ");
                    WriteLine("PWM2: " + await pwm2.get_frequency() + " Hz " + await
                              pwm2.get_dutyCycle() +
                              " % " + await pwm2.get_pulseCounter() + " pulse edges ");
                    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);
        }
Ejemplo n.º 30
0
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YCurrentLoopOutput loop;
                double             value = Convert.ToDouble(LoopCurrent);

                if (Target.ToLower() == "any")
                {
                    loop = YCurrentLoopOutput.FirstCurrentLoopOutput();
                    if (loop == null)
                    {
                        WriteLine("No module connected (check USB cable) ");
                        return(-1);
                    }
                }
                else
                {
                    loop = YCurrentLoopOutput.FindCurrentLoopOutput(
                        Target + ".currentLoopOutput");
                }

                if (await loop.isOnline())
                {
                    await loop.set_current(value);

                    int loopPower = await loop.get_loopPower();

                    if (loopPower == YCurrentLoopOutput.LOOPPOWER_NOPWR)
                    {
                        WriteLine("Current loop not powered");
                    }
                    else if (loopPower == YCurrentLoopOutput.LOOPPOWER_LOWPWR)
                    {
                        WriteLine("Insufficient voltage on current loop");
                    }
                    else
                    {
                        WriteLine("current loop set to " + value + " mA");
                    }
                }
                else
                {
                    WriteLine("Module not connected (check identification and USB cable)");
                }
            } catch (YAPI_Exception ex) {
                WriteLine("error: " + ex.Message);
            }

            YAPI.FreeAPI();
            return(0);
        }