Пример #1
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();
        }
Пример #2
0
        public static String GetAPIVersion()
        {
            string check = YoctoProxyManager.CheckDllVersion("");

            if (check != "")
            {
                return("ERROR: " + check);
            }
            return(YAPI.GetAPIVersion());
        }
    void YoctopuceInitialisation()
    {
        Debug.Log("Use Yoctopuce Lib " + YAPI.GetAPIVersion());
        string errmsg = "";
        int    res    = YAPI.RegisterHub("usb", ref errmsg);

        if (res != YAPI.SUCCESS)
        {
            Debug.Log("error with RegisterHub:" + errmsg);
            errorText.text = errmsg;
            return;
        }
        YModule module = YModule.FirstModule();

        while (module != null)
        {
            string product = module.get_productName();
            if (product == "Yocto-3D" || product == "Yocto-3D-V2")
            {
                Debug.Log("Use " + product + " " + module.get_serialNumber());
                break;
            }
            module = module.nextModule();
        }
        if (module == null)
        {
            errorText.text = "No Yocto-3D or Yocto-3D-V2 found";
            return;
        }
        string serial = module.get_serialNumber();

        tilt_x = YTilt.FindTilt(serial + ".tilt1");
        tilt_z = YTilt.FindTilt(serial + ".tilt2");

        tilt_x.registerValueCallback(TiltCallbackX);
        tilt_z.registerValueCallback(TiltCallbackZ);
    }
Пример #4
0
        public StartForm(bool debuggerAttached)
        {
            configWindow = new ConfigForm();
            configWindow.initCaptureParameters();
            rawDataWindow = new RawDataForm();
            propWindow2   = new PropertiesForm2();

            InitializeComponent();
            version.Text = constants.buildVersion;
            MaximizeBox  = false;
            LogManager.Log("Application start, Welcome to Yocto-Visualization.");

            if (debuggerAttached)
            {
                LogManager.Log("A debugger is attached.");
            }
            LogManager.LogNoTS("---------------------------------------------------------------------------------");
            LogManager.LogNoTS("Optional command line parameters:");
            LogManager.LogNoTS("-config xmlFilePath      Create/Use alternate \"xmlFilePath\" configuration file.");
            LogManager.LogNoTS("                         You can use configuration files from V1, but they will ");
            LogManager.LogNoTS("                         be overwritten in V2 format.");
            LogManager.LogNoTS("-log                     Automatically open log window");
            LogManager.LogNoTS("-check4updates           Re-enable automatic checks for updates");
            LogManager.LogNoTS("---------------------------------------------------------------------------------");
            LogManager.Log("Current configuration file is " + constants.configfile);
            LogManager.Log("Yocto-Visualization version is " + constants.buildVersion);
            LogManager.Log("Yoctopuce API version is " + YAPI.GetAPIVersion());
            LogManager.Log("Yoctopuce dynamic library path is " + YAPI.GetYAPIDllPath());

            LogManager.Log("Architecture is " + (IntPtr.Size * 8).ToString() + " bits (platform " + Environment.OSVersion.Platform.ToString() + ")");



            if (constants.MonoRunning)
            {
                if (constants.OSX_Running)
                {
                    LogManager.Log("Mono version is " + constants.MonoVersion + " (Mac OS X)");
                }
                else
                {
                    LogManager.Log("Mono version is " + constants.MonoVersion);
                }
            }
            else
            {
                LogManager.Log("Running on .NET");
#if NET35
                LogManager.Log("WARNING! this .EXE was specifically compiled for .NET 3.5 (Windows XP compatibility)");
#endif
            }
            string cfgFile = constants.configfile;

            if (!File.Exists(cfgFile) && !constants.configfileOveridden)
            {
                string alternateCfgFile = Path.GetDirectoryName(cfgFile) + "\\..\\..\\YoctoVisualization\\1.0.0.0\\config.xml";
                if (File.Exists(alternateCfgFile))
                {
                    if (MessageBox.Show("No Yocto-Visualization V2 configuration available, but a configuration file from version 1 was found, do you want to import it?", "Yocto-Visualization V2",
                                        MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                                        MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.Yes)
                    {
                        cfgFile = alternateCfgFile;
                    }
                }
            }



            if (File.Exists(cfgFile))
            {
                try
                {
                    XmlDocument doc = new XmlDocument();

                    doc.Load(cfgFile);

                    double     version = 1;
                    XmlElement root    = doc.DocumentElement;

                    if (root.Attributes != null &&
                        root.Attributes["version"] != null)
                    {
                        version = Double.Parse(root.Attributes["version"].Value, CultureInfo.InvariantCulture);
                    }

                    GenericProperties.XmlFileVersion = version;

                    if (version == 1.0)
                    {
                        string configdata = XMLConfigTranslator.TranslateFromV1(doc);
                        doc = new XmlDocument();
                        doc.LoadXml(configdata);
                    }



                    // sensor configuration must be loaded first
                    foreach (XmlNode node in doc.DocumentElement.ChildNodes)
                    {
                        if (node.Name == "Sensors")
                        {
                            sensorsManager.setKnownSensors(node);
                        }
                    }


                    foreach (XmlNode node in doc.DocumentElement.ChildNodes)
                    {
                        switch (node.Name)
                        {
                        case "GraphForm": NewGraphForm(node); MustHide = true; break;

                        case "GaugeForm": NewSolidGaugeForm(node); MustHide = true; break;

                        case "angularGaugeForm": NewAngularGaugeForm(node); MustHide = true; break;

                        case "digitalDisplayForm": NewDigitalDisplayForm(node); MustHide = true; break;

                        case "Config": configWindow.Init(node); break;

                        case "PropertiesForm": RestoreWindowPosition(propWindow2, node); break;
                        }
                    }
                }
                catch (Exception e) { LogManager.Log("Cannot load configuration file " + constants.configfile + ": " + e.Message); }
            }
            else
            {
                configWindow.DefaultInit();
            }



            sensorsManager.registerChangeCallback(sensorListHaschanged);

            configWindow.CheckInit();
            YoctoTimer.Interval = 100;
            YoctoTimer.Enabled  = true;
            if (constants.OpenLogWindowAtStartUp)
            {
                LogManager.Show();
            }

            HideTimer = new Timer();

            HideTimer.Tick += HideTimer_Tick;
        }
Пример #5
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);
            }
        }