Esempio n. 1
0
        public static void InitializeImpl()
        {
            if (!s_libraryLoaded)
            {
                try
                {
                    //Force OS, since we know we are on Linux and the RIO if this is getting called
                    ILibraryLoader loader = new RoboRioLibraryLoader();

                    //Extract our s_library
                    string loadedPath = ExtractLibrary();
                    if (string.IsNullOrEmpty(loadedPath))
                    {
                        //If fail to load, throw exception
                        throw new FileNotFoundException("Library file could not be found in the resorces. Please contact RobotDotNet for support for this issue");
                    }
                    s_library = loader.LoadLibrary(loadedPath);
                    if (s_library == IntPtr.Zero)
                    {
                        //If s_library could not be loaded
                        throw new BadImageFormatException($"Library file {loadedPath} could not be loaded successfully.");
                    }
                    Initialize(s_library, loader);
                    HALAccelerometer.Initialize(s_library, loader);
                    HALAnalog.Initialize(s_library, loader);
                    HALCAN.Initialize(s_library, loader);
                    HALCanTalonSRX.Initialize(s_library, loader);
                    HALCompressor.Initialize(s_library, loader);
                    HALDigital.Initialize(s_library, loader);
                    HALInterrupts.Initialize(s_library, loader);
                    HALNotifier.Initialize(s_library, loader);
                    HALPDP.Initialize(s_library, loader);
                    HALPower.Initialize(s_library, loader);
                    HALSemaphore.Initialize(s_library, loader);
                    HALSerialPort.Initialize(s_library, loader);
                    HALSolenoid.Initialize(s_library, loader);
                    HALUtilities.Initialize(s_library, loader);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.StackTrace);
                    Environment.Exit(1);
                }
                s_libraryLoaded = true;
            }
        }
Esempio n. 2
0
 internal static IntPtr LoadLibrary(string dllLoc, OsType type, out ILibraryLoader loader)
 {
     switch (type)
     {
         case OsType.Windows32:
         case OsType.Windows64:
             loader = new WindowsLibraryLoader();
             return loader.LoadLibrary(dllLoc);
         case OsType.Linux32:
         case OsType.Linux64:
             loader = new LinuxLibraryLoader();
             return loader.LoadLibrary(dllLoc);
         case OsType.RoboRio:
             loader = new RoboRioLibraryLoader();
             return loader.LoadLibrary(dllLoc);
         default:
             loader = null;
             return IntPtr.Zero;
     }
 }