more G-Labs products

Author Topic: Help wanted setting up a virtual module  (Read 2398 times)

January 22, 2015, 01:45:49 PM
Read 2398 times

DutchHans

  • **
  • Information
  • Jr. Member
  • Posts: 39
Hello all,

I am not a programmer, but am trying to read code from others and change it sometimes to let it do what I wanted. I have read about virtual modules and that it is possible to put these on and/or off. I try to read the code from other programs where this has been used, but in no time its getting very complex. Is there a manual of how these virtual modules work. like
-how to set it up?
-how to address it if you want it on or off (for example with a sensor)
-how to use it (if the virtual module is on then put light A1 on)

the reference is giving very little information.

Does a virtual module also work in the wizard?

Thank you in advance.
Hans Willem


January 22, 2015, 05:29:18 PM
Reply #1

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I don't have a lot of experience with virtual modules.  I have only used them to make incoming signals that aren't associated with a module into a module.  For example, early on I used a virtual module set as a sensor to accept RF commands from my X10 wireless motion sensors.  Since a virtual module has a name, it can be used in C# code using that "WithName(..." nomenclature.  I don't know if it works with Wizard scripts, but I would assume so since you can find any defined module in the selections.  Also, I believe the Raspberry Pi GPIO code creates virtual modules for each GPIO defined.  That is also available in C# for sure and presumably Wizard scripts as well.

January 22, 2015, 09:25:18 PM
Reply #2

DutchHans

  • **
  • Information
  • Jr. Member
  • Posts: 39
Hi bkenobi,
First of all, thank you for your reply.
I've looked through other programs, but like I said.. its in no time pretty complex...
Isn't there a simple example? ..with only a few lines of code completely explained?...
First of all we have to create a virtualmodule
Then a line of code....then explained why and how.. then how to work with it...how to set the values.. how to read them...and then how to work with it in a short example with maybe a sensor..
Again.. thank you for your help

January 23, 2015, 01:27:54 AM
Reply #3

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I haven't coded with Virtual Modules, but looking at the helper document this is what I've found:

http://www.homegenie.it/docs/doxy/de/d1f/class_home_genie_1_1_automation_1_1_scripting_1_1_program_helper.html

Methods:
AddVirtualModule
AddVirtualModules
RemoveVirtualModule

Then, as an example of using it, I found a thread from last week:
http://www.homegenie.it/forum/index.php?topic=644.msg3832#msg3832

The specific code of use is:
Code: [Select]
  // create 9 virtual modules in the domain HomeAutomation.Arduino with address from 1 to 10
  Program.AddVirtualModules("HomeAutomation.XefilHomeArduino", "Sensor", "homegenie/generic/sensor", 1, 10);
 
  // create virtual modules in the domain HomeAutomation.Arduino with address from 100 to 112
  Program.AddVirtualModules("HomeAutomation.XefilHomeArduino", "Switch", "homegenie/generic/switch", 100, 112);

Once you have done this, you should be able to address the module with it's address.  But, if you want to use Wizard scripts, I can't help.

January 23, 2015, 10:11:04 AM
Reply #4

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
Hi Hans,

In this post is a discussion for virtual switches (I've also attached the code in this post):
http://www.homegenie.it/forum/index.php?topic=586.msg3508#msg3508

Here is some example code:

Code: [Select]
// Get the Switch by ID
var mySwitch = Modules.InDomain("HomeAutomation.SettingSwitch").WithAddres("1").Get();
// Alternatively get the switch by name (you'll need to add it as a module to a group for this)
var myOtherSwitch = Modules.WithName("MyOtherSwitch").Get();

// Turn Switch on
mySwitch.Command("Control.On").Set();
// or Off
mySwitch.Command("Control.Off").Set();
// or Toggle the switch
mySwitch.Command("Control.Toggle").Set();

// Get the value of the switch
if (mySwitch.Parameter("Status.Level").Value == "1")
{
  // Switch is On
}
else
{
  // Switch is Off
}


By looking at the code in the APP Contributions forums you can learn a lot as well.