The Abiltiy to release socket reseved pins !!! Solution included.


Hello guys,
i wanted to ask if it would possibility to include a method in the Socket.cs to allow for the release of reserved cpu pins. you may ask why... here is a scenario and the proposed solution.
As of now Gadgeteer loads, assigns and reserves the Sockets and pins upon initialization and assumes that the class will be alive until reboot... which works great...
now what if i don't load my Module drivers at Design time but rather i load the Drivers Dynamically using Assembly.Load function??? the system would fail and throw a pin conflict exception if i tried to load the driver twice, meaning load the assembly call a function, unload the Assembly (through AppDomain) and later on load the assembly again to control something on the module and that's when i get the exception. since the socket.cs has reserved the socket and pins for the already unloaded Class. ... which I'll have to do if i want to keep the system running the minimum possible to of assemblies..
So my idea would probably be. the socket.cs should implement an IDispose to release the the socket and pin if the class the created the socket is dead. or to simply try to fix the is remove the pins from the list and cpu instead of throwing the exception.. and here is how:
in Socket.cs go to this method here:
public Cpu.Pin ReservePin(Socket.Pin pin, Module module)
and replace that function with:
public Cpu.Pin ReservePin(Socket.Pin pin, Module module)
        PinReservation myReservedPin = null;
        Cpu.Pin cpuPin = CpuPins[(int)pin];
        if (cpuPin == UnspecifiedPin)
            throw new PinMissingException(this, pin);
        if (cpuPin == UnnumberedPin)
            // bypass checks, return no pin
            return Cpu.Pin.GPIO_NONE;
        // Check to see if pin is already reserved
        foreach (PinReservation reservation in _reservedPins)
            if (cpuPin == reservation.CpuPin)
try {
                Debug.Print("about to remove the pin");
                Port.ReservePin(cpuPin, false);
                myReservedPin = reservation;
                Debug.Print("pin removed");
                 throw new PinConflictException(this, pin, module, reservation);
        // see if this is a display socket and reboot if we need to disable the LCD controller
        if (!(module is Module.DisplayModule) && (SupportsType('R') || SupportsType('G') || SupportsType('B')))
        if (myReservedPin != null)
            Debug.Print("Removing my Reserved Pin");
            _reservedPins.Remove(my Reserved Pin);
            Debug.Print("my Reserved Pin was removed");
//add the reserved pin again.
        _reservedPins.Add(new PinReservation(this, pin, cpuPin, module));
        return cpuPin;
I hope to see this added to the official release...
thank you.
Closed Jul 26, 2013 at 10:59 AM by JanKuceraMSFT
Resolved in 2.43.800. Also, interfaces are now disposable.


jamesscott wrote May 11, 2012 at 9:40 AM


Thanks for the input. Unfortuantely we did not get round to including this feature in the (shortly to be released) 2.42.600, since we focussed on NETMF 4.2 support with only bugfixes otherwise.


jcherrabi wrote May 12, 2012 at 7:09 PM

Thank you James...

I'm hoping to see it in the next release non the less, quiet few developers would like to see this added...

wrote Aug 22, 2012 at 6:19 PM

wrote Nov 27, 2012 at 10:45 AM

wrote Nov 27, 2012 at 1:48 PM

wrote Nov 27, 2012 at 3:28 PM

wrote Nov 27, 2012 at 8:30 PM

wrote Nov 27, 2012 at 9:53 PM

wrote Feb 22, 2013 at 12:45 AM

wrote Feb 22, 2013 at 4:39 PM

wrote Apr 19, 2013 at 11:40 PM

wrote Apr 22, 2013 at 2:24 PM

JanKuceraMSFT wrote Apr 22, 2013 at 6:28 PM

Fixed in the upcoming version.

** Closed by JanKuceraMSFT 22/04/2013 06:24

wrote Apr 22, 2013 at 6:28 PM

wrote Jul 26, 2013 at 10:59 AM