예제 #1
0
        public static string CheckDllVersion(string expectedVersion)
        {
            string DNPPath    = System.Reflection.Assembly.GetExecutingAssembly().Location;
            string DNPVersion = "PATCH_WITH_BUILD";
            string joker      = "PATCH" + "_WITH_" + "BUILD"; // split to avoid auto-replacement
            string msg;

            // Disable all checks if DotNetProxy is a debug version
            if (DNPVersion == joker || DNPVersion == "")
            {
                return("");
            }

            // Check compatibility with applicative layer
            if (DNPVersion != expectedVersion && expectedVersion != joker && expectedVersion != "")
            {
                msg = "DotNetProxy library version mismatch (expected " + expectedVersion + ", found " + DNPVersion + " in " + DNPPath + ")";
                return(msg);
            }

            // Check compatibility with YAPI layer
            string YAPIVersion = default(string);
            string YAPIDate    = default(string);

            try
            {
                YAPI.apiGetAPIVersion(ref YAPIVersion, ref YAPIDate);
            }
            catch (System.DllNotFoundException ex)
            {
                msg = "Unable to load YAPI library (" + ex.Message + ")";
                return(msg);
            }
            catch (System.BadImageFormatException)
            {
                if (IntPtr.Size == 4)
                {
                    msg = "YAPI library version mismatch (using 64 bits yapi.dll with 32 bit application)";
                }
                else
                {
                    msg = "YAPI library version mismatch (using 32 bits yapi.dll with 64 bit application)";
                }
                return(msg);
            }
            if (DNPVersion != YAPIVersion && YAPIVersion != joker && YAPIVersion != "")
            {
                string YAPIPath = YAPI.GetYAPIDllPath();
                msg = "YAPI library version mismatch (expected " + DNPVersion + ", found " + YAPIVersion + " in " + YAPIPath + ")";
                return(msg);
            }

            return("");
        }
예제 #2
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;
        }
        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();