Example #1
0
        static void Main(String[] args)
        {
            string errmsg = "";

            constants.init(args);



            if (constants.CheckMonoVersion(out errmsg))
            {
                int res = YAPI.FILE_NOT_FOUND;

                res = YAPI.InitAPI(0, ref errmsg);
                YAPI.RegisterLogFunction(LogManager.APIlog);

                if (res == YAPI.SUCCESS)
                {
                    YAPI.SetDeviceListValidity(3600);
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    if (Debugger.IsAttached)
                    {
                        Application.Run(new StartForm(true));
                    }
                    else
                    {
                        try  { Application.Run(new StartForm(false)); }
                        catch (OutOfMemoryException)
                        {
                            string msg = ("Yocto-Visualization ran out of memory");
                            Console.Write(msg, "Oops", MessageBoxButtons.OK,
                                          MessageBoxIcon.Exclamation);
                            MessageBox.Show(msg);
                        }
                    }
Example #2
0
        static void Main(String[] args)
        {
            constants.init(args);
            string errsmg = "";

            YAPI.RegisterLogFunction(LogManager.APIlog);
            if (YAPI.InitAPI(YAPI.DETECT_NONE, ref errsmg) == YAPI.SUCCESS)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
            }
            else
            {
                MessageBox.Show("Yoctopuce API init error:" + errsmg);
            }
        }
Example #3
0
        public static bool initYoctopuceLibrary(ref string errmsg, bool silent)
        {
            if (LibraryAPIInitialized)
            {
                return(true);
            }
            log(".NET Proxy library initialization");
            apiMutex.WaitOne();

            LibraryAPIInitialized = YAPI.InitAPI(YAPI.DETECT_NONE, ref errmsg) == YAPI.SUCCESS;
            YAPI.RegisterLogFunction(apilog);
            apiMutex.ReleaseMutex();
            if (!silent)
            {
                string msg = "Yoctopuce low-level API initialization failed (" + errmsg + ")";
                throw new YoctoApiProxyException(msg);
            }
            if (LibraryAPIInitialized)
            {
                //InternalStuff.log("registering arrival/removal");
                YAPI.RegisterDeviceArrivalCallback(YFunctionProxy.deviceArrival);
                YAPI.RegisterDeviceRemovalCallback(YFunctionProxy.deviceRemoval);
            }

            new Thread(() =>
            {
                Thread.CurrentThread.IsBackground = true;
                InternalStuff.log("Starting inner processing thread...");
                string err = "";
                while (!InnerThreadMustStop)
                {
                    //InternalStuff.log("YAPI processing...");
                    try
                    {
                        if (LibraryAPIInitialized)
                        {
                            YAPI.UpdateDeviceList(ref err);
                        }
                    }
                    catch (Exception e) {
                        InternalStuff.log("YUpdateDeviceList error !!(" + e.Message + ")");
                    }
                    for (int i = 0; i < 20 & !InnerThreadMustStop; i++)
                    {
                        try
                        {
                            if (LibraryAPIInitialized)
                            {
                                YAPI.Sleep(100, ref err);
                            }
                        }
                        catch (Exception e) { InternalStuff.log("YSleep error (" + e.Message + ")"); }
                    }
                }
                InternalStuff.log("Stopping inner processing thread...");
                InnerThreadMustStop = false;
            }).Start();


            return(LibraryAPIInitialized);
        }
        public static bool initYoctopuceLibrary(ref string errmsg, bool silent)
        {
            if (LibraryAPIInitialized)
            {
                return(true);
            }
            log(".NET Proxy library initialization");
            apiMutex.WaitOne();
            YAPI.RegisterLogFunction(apilog);
            LibraryAPIInitialized = YAPI.InitAPI(YAPI.DETECT_NONE, ref errmsg) == YAPI.SUCCESS;

            apiMutex.ReleaseMutex();
            if (LibraryAPIInitialized)
            {
                InternalStuff.log("yapi.dll version is " + YoctoProxyManager.DllVersion);
                InternalStuff.log("yapi.dll file is " + YAPI.GetYAPIDllPath());
                InternalStuff.log("yapi.dll architecture is " + YoctoProxyManager.DllArchitecture);
            }



            if (!silent)
            {
                string msg = "Yoctopuce low-level API initialization failed (" + errmsg + ")";
                throw new YoctoApiProxyException(msg);
            }
            if (LibraryAPIInitialized)
            {
                //InternalStuff.log("registering arrival/removal");
                YAPI.RegisterDeviceArrivalCallback(YFunctionProxy.deviceArrival);
                YAPI.RegisterDeviceRemovalCallback(YFunctionProxy.deviceRemoval);


                new Thread(() =>
                {
                    Thread.CurrentThread.IsBackground = true;
                    InternalStuff.log("Starting inner processing thread...");
                    bool aborting = false;
                    string err    = "";
                    while (!InnerThreadMustStop && !aborting)
                    {
                        //InternalStuff.log("YAPI processing...");
                        try { if (LibraryAPIInitialized)
                              {
                                  YAPI.UpdateDeviceList(ref err);
                              }
                        }
                        catch (System.Threading.ThreadAbortException)
                        {
                            InternalStuff.log("Inner processing thead is aborting during UpdateDeviceList!");
                            aborting = true;
                            YAPI.FreeAPI();
                            LibraryAPIInitialized = false;
                            InternalStuff.log("API has been freed in a hurry");
                        }
                        catch (Exception e) { InternalStuff.log("YUpdateDeviceList error !!(" + e.Message + ")"); }
                        for (int i = 0; i < 20 & !InnerThreadMustStop & !aborting; i++)
                        {
                            try
                            {
                                if (LibraryAPIInitialized)
                                {
                                    YAPI.Sleep(100, ref err);
                                }
                            }
                            catch (System.Threading.ThreadAbortException)
                            {
                                InternalStuff.log("Inner processing thead is aborting during ysleep!");
                                aborting = true;
                                YAPI.FreeAPI();
                                LibraryAPIInitialized = false;
                                InternalStuff.log("API has been freed in a hurry");
                            }
                        }
                        catch (Exception e) { InternalStuff.log("YSleep error (" + e.GetType().ToString() + " " + e.Message + ")! "); }
                    }

                    InternalStuff.log("Stopping inner processing thread...");


                    InnerThreadMustStop = false;
                }).Start();