예제 #1
0
파일: IRWrapper.cs 프로젝트: pipi1226/krpc
            private void BuildServoGroups(object irServoController)
            {
                LogFormatted("Getting ServoGroups Object");
                var servoGroupsField = IRServoControllerType.GetField("ServoGroups");

                if (servoGroupsField == null)
                {
                    LogFormatted("Failed Getting ServoGroups fieldinfo");
                }
                else
                {
                    actualServoGroups = servoGroupsField.GetValue(irServoController);
                    LogFormatted("Success: " + (actualServoGroups != null));
                }
            }
예제 #2
0
            internal IRAPI(Object IRServoController)
            {
                //store the actual object
                actualServoController = IRServoController;

                //these sections get and store the reflection info and actual objects where required. Later in the properties we then read the values from the actual objects
                //for events we also add a handler
                LogFormatted("Getting APIReady Object");
                APIReadyField = IRServoControllerType.GetField("APIReady", BindingFlags.Public | BindingFlags.Static);
                LogFormatted("Success: " + (APIReadyField != null).ToString());

                LogFormatted("Getting ServoGroups Object");
                ServoGroupsField  = IRServoControllerType.GetField("ServoGroups", BindingFlags.Public | BindingFlags.Static);
                actualServoGroups = ServoGroupsField.GetValue(actualServoController);
                LogFormatted("Success: " + (actualServoGroups != null).ToString());
            }
          private void BuildServoGroups()
          {
              var servoGroupsField = IRServoControllerType.GetField("ServoGroups");

              if (servoGroupsField == null)
              {
                  LogFormatted("Failed Getting ServoGroups fieldinfo");
              }
              else if (IRminWrapper.ActualServoController == null)
              {
                  LogFormatted("ServoController Instance not found");
              }
              else
              {
                  actualServoGroups = servoGroupsField.GetValue(IRminWrapper.ActualServoController);
              }
          }
      internal static bool InitWrapper()
      {
          isWrapped             = false;
          ActualServoController = null;
          IRController          = null;
          LogFormatted("Attempting to Grab IR Types...");

          IRServoControllerType = null;

          AssemblyLoader.loadedAssemblies.TypeOperation(t => {
                if (t.FullName == "InfernalRoboticsMinimal.Command.ServoController")
                {
                    IRServoControllerType = t;
                }
            });

          if (IRServoControllerType == null)
          {
              return(false);
          }

          LogFormatted("IR Version:{0}", IRServoControllerType.Assembly.GetName().Version.ToString());

          IRServoMechanismType = null;
          AssemblyLoader.loadedAssemblies.TypeOperation(t => {
                if (t.FullName == "InfernalRoboticsMinimal.Control.IMechanism")
                {
                    IRServoMechanismType = t;
                }
            });

          if (IRServoMechanismType == null)
          {
              LogFormatted("[IR Wrapper] Failed to grab Mechanism Type");
              return(false);
          }

          IRServoMotorType = null;
          AssemblyLoader.loadedAssemblies.TypeOperation(t => {
                if (t.FullName == "InfernalRoboticsMinimal.Control.IServoMotor")
                {
                    IRServoMotorType = t;
                }
            });

          if (IRServoMotorType == null)
          {
              LogFormatted("[IR Wrapper] Failed to grab ServoMotor Type");
              return(false);
          }

          IRServoType = null;
          AssemblyLoader.loadedAssemblies.TypeOperation(t => {
                if (t.FullName == "InfernalRoboticsMinimal.Control.IServo")
                {
                    IRServoType = t;
                }
            });

          if (IRServoType == null)
          {
              LogFormatted("[IR Wrapper] Failed to grab Servo Type");
              return(false);
          }

          IRServoPartType = null;
          AssemblyLoader.loadedAssemblies.TypeOperation(t => {
                if (t.FullName == "InfernalRoboticsMinimal.Control.IPart")
                {
                    IRServoPartType = t;
                }
            });

          if (IRServoType == null)
          {
              LogFormatted("[IR Wrapper] Failed to grab ServoPart Type");
              return(false);
          }

          IRControlGroupType = null;
          AssemblyLoader.loadedAssemblies.TypeOperation(t => {
                if (t.FullName == "InfernalRoboticsMinimal.Command.ServoController+ControlGroup")
                {
                    IRControlGroupType = t;
                }
            });

          if (IRControlGroupType == null)
          {
              var irassembly = AssemblyLoader.loadedAssemblies.FirstOrDefault(a => a.assembly.FullName.Contains("InfernalRoboticsMinimal"));
              if (irassembly == null)
              {
                  LogFormatted("[IR Wrapper] cannot find IRMin.dll");
                  return(false);
              }
              foreach (Type t in irassembly.assembly.GetExportedTypes())
              {
                  LogFormatted("[IR Wrapper] Exported type: " + t.FullName);
              }

              LogFormatted("[IR Wrapper] Failed to grab ControlGroup Type");
              return(false);
          }

          LogFormatted("Got Assembly Types, grabbing Instance");

          try {
              var propertyInfo = IRServoControllerType.GetProperty("Instance", BindingFlags.Public | BindingFlags.Static);

              if (propertyInfo == null)
              {
                  LogFormatted("[IR Wrapper] Cannot find Instance Property");
              }
              else
              {
                  ActualServoController = propertyInfo.GetValue(null, null);
              }
          } catch (Exception e) {
              LogFormatted("No Instance found, " + e.Message);
          }

          if (ActualServoController == null)
          {
              LogFormatted("Failed grabbing Instance");
              return(false);
          }

          LogFormatted("Got Instance, Creating Wrapper Objects");
          IRController = new InfernalRoboticsMinimalAPI();
          isWrapped    = true;
          return(true);
      }
 private void DetermineReady()
 {
     LogFormatted("Getting APIReady Object");
     apiReady = IRServoControllerType.GetProperty("APIReady", BindingFlags.Public | BindingFlags.Static);
     LogFormatted("Success: " + (apiReady != null));
 }
예제 #6
0
파일: IRWrapper.cs 프로젝트: pand5461/KOS-1
        internal static bool InitWrapper()
        {
            // Prevent the init function from continuing to initialize if InfernalRobotics is not installed.
            if (hasAssembly == null)
            {
                LogFormatted("Attempting to Grab IR Assembly...");
                hasAssembly = AssemblyLoader.loadedAssemblies.Any(a => a.dllName.Equals("InfernalRobotics"));
                if (hasAssembly.Value)
                {
                    LogFormatted("Found IR Assembly!");
                }
                else
                {
                    LogFormatted("Did not find IR Assembly.");
                }
            }
            if (!hasAssembly.Value)
            {
                isWrapped = false;
                return(isWrapped);
            }

            isWrapped             = false;
            ActualServoController = null;
            IRController          = null;
            LogFormatted("Attempting to Grab IR Types...");

            IRServoControllerType = GetType("InfernalRobotics.Command.ServoController");

            if (IRServoControllerType == null)
            {
                return(false);
            }

            LogFormatted("IR Version:{0}", IRServoControllerType.Assembly.GetName().Version.ToString());

            IRServoMechanismType = GetType("InfernalRobotics.Control.IMechanism");

            if (IRServoMechanismType == null)
            {
                LogFormatted("[IR Wrapper] Failed to grab Mechanism Type");
                return(false);
            }

            IRServoMotorType = GetType("InfernalRobotics.Control.IServoMotor");

            if (IRServoMotorType == null)
            {
                LogFormatted("[IR Wrapper] Failed to grab ServoMotor Type");
                return(false);
            }

            IRServoType = GetType("InfernalRobotics.Control.IServo");

            if (IRServoType == null)
            {
                LogFormatted("[IR Wrapper] Failed to grab Servo Type");
                return(false);
            }

            IRServoPartType = GetType("InfernalRobotics.Control.IPart");

            if (IRServoType == null)
            {
                LogFormatted("[IR Wrapper] Failed to grab ServoPart Type");
                return(false);
            }

            IRControlGroupType = GetType("InfernalRobotics.Command.ServoController+ControlGroup");

            if (IRControlGroupType == null)
            {
                var irassembly = AssemblyLoader.loadedAssemblies.FirstOrDefault(a => a.assembly.FullName.Contains("InfernalRobotics"));
                if (irassembly == null)
                {
                    LogFormatted("[IR Wrapper] cannot find InvernalRobotics.dll");
                    return(false);
                }
                foreach (Type t in irassembly.assembly.GetExportedTypes())
                {
                    LogFormatted("[IR Wrapper] Exported type: " + t.FullName);
                }

                LogFormatted("[IR Wrapper] Failed to grab ControlGroup Type");
                return(false);
            }

            LogFormatted("Got Assembly Types, grabbing Instance");

            try
            {
                var propertyInfo = IRServoControllerType.GetProperty("Instance", BindingFlags.Public | BindingFlags.Static);

                if (propertyInfo == null)
                {
                    LogFormatted("[IR Wrapper] Cannot find Instance Property");
                }
                else
                {
                    ActualServoController = propertyInfo.GetValue(null, null);
                }
            }
            catch (Exception e)
            {
                LogFormatted("No Instance found, " + e.Message);
            }

            if (ActualServoController == null)
            {
                LogFormatted("Failed grabbing Instance");
                return(false);
            }

            LogFormatted("Got Instance, Creating Wrapper Objects");
            IRController = new InfernalRoboticsAPI();
            isWrapped    = true;
            return(true);
        }