more G-Labs products

Author Topic: RemoveVirtualModule seems not to work  (Read 753 times)

March 22, 2015, 12:53:06 PM
Read 753 times

wolfgang928

  • *
  • Information
  • Newbie
  • Posts: 10
In a new developed hgx program in version 480 i would like to use

Program.RemoveVirtualModule(MODULES_DOMAIN, address) but this doesn't work.
Currently i have to stop program, goto to maintenance and remove the too much virtual modules by hand.
After changing the property inside options dialog and restarting program adding of a virtual module works perfect, but the removing doesn't.

Enclosed my code snippet:

Func<int, bool> InitVirtualModules = (int number_modules) => {
  int curr_modules = 0;
  var switchModules = Modules.InDomain(MODULES_DOMAIN).OfDeviceType("Switch");
  switchModules.Each((x) => { ++curr_modules; return false;});  // Is there a better way to count?
 
  if (curr_modules == number_modules) return true;
 
  if (curr_modules < number_modules) { // Add some modules more
    for (int nextnumber = curr_modules + 1; nextnumber <= number_modules; nextnumber++) {
       Program.AddVirtualModule(MODULES_DOMAIN, nextnumber.ToString(), "Switch", "rfm/arduino/switch");
         var newmodule = switchModules.WithAddress(nextnumber.ToString()).Get();
         if (newmodule != null) {
            newmodule.Parameter("Rfm.Node").Value = "1";
        ...
        }
    }
  }
 
  Program.RemoveVirtualModule(MODULES_DOMAIN, "7"); //  For testing, if following for loop does not work correctly.
 
  if (curr_modules > number_modules) { // Remove the too much modules in reverse order
    for (int n_remove = curr_modules; n_remove > number_modules; n_remove--) {
      var mod = switchModules.WithAddress(n_remove.ToString()).Get();
      if (mod != null) Program.RemoveVirtualModule(MODULES_DOMAIN, n_remove.ToString());
      }
  }
  return true;
};

Is this my mistake or a bug?
Thanks for a helping idea.
« Last Edit: March 22, 2015, 02:12:32 PM by wolfgang928 »


There are no comments for this topic. Do you want to be the first?