/// <summary> /// Creates a new <see cref="Socket"/> object specifying the socket name. /// </summary> /// <remarks> /// This should be used by module constructors to create socket instances if they provide sockets to other modules. /// The module constructor should then configure the socket properties as appropriate, and then call <see cref="RegisterSocket"/> /// A socketNumber is auto-assigned. /// </remarks> /// <param name="name">The socket's name</param> public static Socket CreateUnnumberedSocket(String name) { int socketNumber; lock (Socket._sockets) { while (Socket.GetSocket(autoSocketNumber, false, null, null) != null) { autoSocketNumber--; } socketNumber = autoSocketNumber; autoSocketNumber--; } return(new Socket(socketNumber, name)); }
// Note: A constructor summary is auto-generated by the doc builder. /// <summary></summary> /// <param name="socketNumber">The socket that this module is plugged in to.</param> public Bluetooth(int socketNumber) { // This finds the Socket instance from the user-specified socket number. // This will generate user-friendly error messages if the socket is invalid. // If there is more than one socket on this module, then instead of "null" for the last parameter, // put text that identifies the socket to the user (e.g. "S" if there is a socket type S) Socket socket = Socket.GetSocket(socketNumber, true, this, null); this.reset = new GTI.DigitalOutput(socket, Socket.Pin.Six, false, this); this.statusInt = new GTI.InterruptInput(socket, Socket.Pin.Three, GTI.GlitchFilterMode.Off, GTI.ResistorMode.Disabled, GTI.InterruptMode.RisingAndFallingEdge, this); this.serialPort = new Serial(socket, 38400, GTI.Serial.SerialParity.None, GTI.Serial.SerialStopBits.One, 8, GTI.Serial.HardwareFlowControl.NotRequired, this); //this.statusInt.Interrupt += new GTI.InterruptInput.InterruptEventHandler(statusInt_Interrupt); this.serialPort.ReadTimeout = Timeout.Infinite; this.serialPort.Open(); Thread.Sleep(5); this.reset.Write(true); readerThread = new Thread(new ThreadStart(runReaderThread)); readerThread.Start(); Thread.Sleep(500); }
/// <summary> /// Registers a socket. Should be used by mainboards and socket-providing modules during initialization. /// </summary> /// <param name="socket">The socket to register</param> public static void RegisterSocket(Socket socket) { if (DoRegistrationChecks) { if (socket.CpuPins == null || socket.CpuPins.Length != 11) { SocketRegistrationError(socket, "CpuPins array must be of length 11"); } if (socket.SupportedTypes == null || socket.SupportedTypes.Length == 0) { SocketRegistrationError(socket, "SupportedTypes list is null/empty"); } foreach (char type in socket.SupportedTypes) { switch (type) { case 'A': TestPinsPresent(socket, new int[] { 3, 4, 5, 6 }, type); if (socket.AnalogInput3 == null || socket.AnalogInput4 == null || socket.AnalogInput5 == null) { SocketRegistrationError(socket, "Socket of type A must support analog input functionality on pins 3, 4 and 5"); } break; case 'C': TestPinsPresent(socket, new int[] { 3, 4, 5, 6 }, type); break; case 'D': TestPinsPresent(socket, new int[] { 3, 6, 7 }, type); break; case 'E': TestPinsPresent(socket, new int[] { 6, 7, 8, 9 }, type); break; case 'F': TestPinsPresent(socket, new int[] { 3, 4, 5, 6, 7, 8, 9 }, type); break; case 'H': TestPinsPresent(socket, new int[] { 3 }, type); break; case 'I': TestPinsPresent(socket, new int[] { 3, 6, 8, 9 }, type); break; case 'K': TestPinsPresent(socket, new int[] { 3, 4, 5, 6, 7 }, type); if (socket.SerialPortName == null) { SocketRegistrationError(socket, "Socket of type K must specify serial port name"); } break; case 'O': TestPinsPresent(socket, new int[] { 3, 4, 5 }, type); if (socket.AnalogOutput == null) { SocketRegistrationError(socket, "Socket of type O must support analog output functionality"); } break; case 'P': TestPinsPresent(socket, new int[] { 3, 6, 7, 8, 9 }, type); if (socket.PWM7 == null || socket.PWM8 == null || socket.PWM9 == null) { SocketRegistrationError(socket, "Socket of type P must support PWM functionality"); } break; case 'S': TestPinsPresent(socket, new int[] { 3, 4, 5, 6, 7, 8, 9 }, type); if (socket.SPIModule == Socket.SPIMissing) { SocketRegistrationError(socket, "Socket of type S must specify SPI module number"); } break; case 'T': TestPinsPresent(socket, new int[] { 4, 5, 6, 7 }, type); break; case 'U': TestPinsPresent(socket, new int[] { 3, 4, 5, 6 }, type); if (socket.SerialPortName == null) { SocketRegistrationError(socket, "Socket of type U must specify serial port name"); } break; case 'R': TestPinsPresent(socket, new int[] { 3, 4, 5, 6, 7, 8, 9 }, type); break; case 'G': TestPinsPresent(socket, new int[] { 3, 4, 5, 6, 7, 8, 9 }, type); break; case 'B': TestPinsPresent(socket, new int[] { 3, 4, 5, 6, 7, 8, 9 }, type); break; case 'X': TestPinsPresent(socket, new int[] { 3, 4, 5 }, type); break; case 'Y': TestPinsPresent(socket, new int[] { 3, 4, 5, 6, 7, 8, 9 }, type); break; case 'Z': // manufacturer specific socket - no tests break; case '*': // * is a special case - daisylink modules don't actually declare their new socket in code, instead reusing the mainboard socket number // so we don't need the below, but it doesnt hurt to leave it in TestPinsPresent(socket, new int[] { 3, 4, 5 }, type); break; default: SocketRegistrationError(socket, "Socket type '" + type + "' is not supported by Gadgeteer"); break; } } } lock (Socket._sockets) { if (Socket.GetSocket(socket.SocketNumber, false, null, null) != null) { throw new Socket.InvalidSocketException("Cannot register socket - socket number " + socket.SocketNumber + " already used"); } Socket._sockets.Add(socket); socket._registered = true; } }