Main Site Documentation

Initiliazing Modules outside of ProgramStarted()


#1

Hello guys,
i was wondering if any of you guys would the trick to initialize the modules outside of the ProgramStarted Dispatcher.

for example i want to be able to do this:


void myMethod()
{
Gadgeteer.Modules.GHIElectronics.Button button;
button = new GTM.GHIElectronics.Button(14);
button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed);
}

from an event i would call myMethod().

right now i get this error:


modules must be created on the Program's Dispatcher thread

and if you are wondering why i want to do that . well it is simple really…
the above if possible and i hope it is, will allow me to load the application on the spider for example once and be able to turn it off and change the socket, plug the module to another socket and be able to use it… hope this makes sense. and of course it would also allow me to remove the socket without getting an exception.

thanks.

Jay.


#2

Try using Program.Dispatcher to invoke your method that creates the module.


#3

Awesome Architect …
thanks for the tip.
here is the code in case someone else want to do the same thing.


void myMethod()
{
        Dispatcher.BeginInvoke(
                new DispatcherOperationCallback(
                    delegate(object o)
                    {
                       
                        Debug.Print("Dispatch Called");
                        Gadgeteer.Modules.GHIElectronics.Button button;
                        button = new GTM.GHIElectronics.Button(14);
                        button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed);
             
                        return null;
                    }
                    ), null
                );
}

another question… now how to do i dispose of the button object and release the Socket… for later use again?

thanks.


#4

Make it a class member.


#5

Hi Architect,
i’m not sure i get what you are saying… it’s kind of late here so maybe that has something to do with it…
anyway are you talking about modifying the source code of the module? and make it static? what if i don’t have access to the source? or is this something that can be done on my Program…

a sample code if possible would be great…

thanks.


#6

Releasing sockets and mainboard resources (such as pins, serial ports, etc.) for reuse at runtime would require some changes to the mainboard software implementation. The existing implementation assumes that modules don’t change after startup, so mainboard reservations are non-reversable.

The GadgeteerCore and Fez Spider Mainboard source is published on Codeplex at http://gadgeteer.codeplex.com, so you could experiment with making these changes yourself.


#7

Yep, Module class has static list of all initialized modules and Socket has static list of reserved pins. There are no methods that remove items from these lists for now.


#8

kind of pity it was designed that way…

so a reboot is the only way for now…

i guess that is expected since one would have to turn off the Main board to plug and unplug modules, but still it would have made configuration easier if one could release those pin…

now where is that reboot command ?

thanks guys…