Reserving pins

Under what circumstances should a custom module reserve pins?

For example, I assume that a module using UART on Socket 11 of the Spider should reserve pins 4 and 5 for TX/RX, right?

When I try that, I get this:

[quote]Using mainboard GHIElectronics-FEZSpider version 1.0
#### Exception Gadgeteer.Socket+PinConflictException - 0x00000000 (1) ####
#### Message:
Unable to configure the MidiModule module using socket 11 (pin 4). There is a conflict with the MidiModule module using socket 11 (pin 4). Please try using a different combination of sockets.
#### Gadgeteer.Socket::ReservePin [IP: 003a] ####
#### Gadgeteer.Interfaces.Serial::.ctor [IP: 00ec] ####
#### Gadgeteer.Modules.PeteBrown.MidiModule::.ctor [IP: 007a] ####
#### GadgeteerMidiTest.Program::.ctor [IP: 0006] ####
#### GadgeteerMidiTest.Program::Main [IP: 000b] ####
A first chance exception of type ‘Gadgeteer.Socket.PinConflictException’ occurred in Gadgeteer.dll
An unhandled exception of type ‘Gadgeteer.Socket.PinConflictException’ occurred in Gadgeteer.dll[/quote]

However, if I run without that check, it works. I’m not sure if another module I’m using could potentially conflict, or if I’m doing something wrong with the check.

public MidiModule(int socketNumber)
{
    Socket socket = Socket.GetSocket(socketNumber, true, this, null);

    // need a UART/USART socket.
    if (!socket.SupportsType('U'))
    {
        throw new GT.Socket.InvalidSocketException("Socket '" + socketNumber + "' does not support the MIDI module. Please plug the MIDI module into a socket labeled 'U'.");
    }



    // can't share the send/receive pins
    try
    {
        socket.ReservePin(Socket.Pin.Four, this);
        socket.ReservePin(Socket.Pin.Five, this);
    }
    catch (Exception e)
    {
        throw new GT.Socket.InvalidSocketException("Could not reserve required pins for MIDI serial communications on socket '" + socketNumber + "'.");
    }

    // initialize serial comms
    _serial = new GTI.Serial(
        socket,
        31250,
        GTI.Serial.SerialParity.None,
        GTI.Serial.SerialStopBits.One,
        8,
        GTI.Serial.HardwareFlowControl.NotRequired,
        this);


    // open ze port
    _serial.Open();

}

Awesome MSPaint artwork attached.

Pete

Actually, I see that’s not even my exception.

Ok, any idea what’s conflicting with serial comms here?

The message is strange. It appears to say the module is conflicting with itself.

Pete

I’m talking to myself here. :slight_smile:

If I remove the pin reservation, it all works.

So, if I understand correctly, the Serial code does the pin reservation for me? If so, under what circumstances should I reserve pins? Is it only when you’re using something like only two pins of a Y socket? Or does the Digital I/O automatically reserve pins for you?

Pete

The serial module code reservers pins 4 and 5


socket.ReservePin(Socket.Pin.Four, module);
socket.ReservePin(Socket.Pin.Five, module);

If you attempt to reserve a pin that is already reserved by the socket an exception will be raised by the following code in teh Socket class


   // Check to see if pin is already reserved
            foreach (PinReservation reservation in _reservedPins)
            {
                if (cpuPin == reservation.CpuPin)
                {
                    throw new PinConflictException(this, pin, module, reservation);
                }
            }

i don’t understand the reservers too.
maybe someone can explain the sense of this.
reserve a pin pin always throw a exception for my used socket.

cu
Andreas