本文整理汇总了C#中Socket.ReservePin方法的典型用法代码示例。如果您正苦于以下问题:C# Socket.ReservePin方法的具体用法?C# Socket.ReservePin怎么用?C# Socket.ReservePin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Socket
的用法示例。
在下文中一共展示了Socket.ReservePin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NativeI2CBus
public NativeI2CBus(Socket socket, ushort address, int clockRateKhz, Module module)
{
if (_device == null)
{
socket.ReservePin(Socket.Pin.Eight, module);
socket.ReservePin(Socket.Pin.Nine, module);
_device = new I2CDevice(new I2CDevice.Configuration(0, 50));
}
_configuration = new I2CDevice.Configuration(address, clockRateKhz);
}
示例2: SPI
private SPI(Socket socket, Configuration conf, Sharing sharingMode, Cpu.Pin chipSelectPin, Module module)
{
SPIInstance si = SPIInstance.GetInstance(socket, module);
if (si.Users == 0)
{
socket.ReservePin(Socket.Pin.Seven, module);
socket.ReservePin(Socket.Pin.Eight, module);
socket.ReservePin(Socket.Pin.Nine, module);
}
else
{
if (si.SharingMode != Sharing.Shared)
{
throw new Exception("SPI bus " + si + " is already reserved, cannot instantiate it again");
}
if (sharingMode == Sharing.Exclusive)
{
throw new Exception("SPI bus " + si + " is already shared among " + si.Users + " users, cannot instantiate it for exclusive use");
}
}
this.spiInstance = si;
lock (this.spiInstance)
{
si.Users++;
si.SharingMode = sharingMode;
if (conf != null)
{
this.spiConfig = new Microsoft.SPOT.Hardware.SPI.Configuration(
(Cpu.Pin)chipSelectPin,
conf.ChipSelectActiveState,
conf.ChipSelectSetupTime,
conf.ChipSelectHoldTime,
conf.ClockIdleState,
conf.ClockEdge,
conf.ClockRateKHz,
si.SPIModule);
if (!si.IsInitialised)
{
si.SpotSPI = new Microsoft.SPOT.Hardware.SPI(this.spiConfig);
si.IsInitialised = true;
}
this.spotSPI = si.SpotSPI;
}
}
}
示例3: AnalogInput
// Note: A constructor summary is auto-generated by the doc builder.
/// <summary></summary>
/// <remarks>This automatically checks that the socket supports Type A, and reserves the pin used.
/// An exception will be thrown if there is a problem with these checks.</remarks>
/// <param name="socket">The socket.</param>
/// <param name="pin">The analog input pin to use.</param>
/// <param name="module">The module using the socket, which can be null if unspecified.</param>
public AnalogInput(Socket socket, Socket.Pin pin, Module module)
{
socket.EnsureTypeIsSupported('A', module);
socket.ReservePin(pin, module);
Cpu.AnalogChannel channel = Cpu.AnalogChannel.ANALOG_NONE;
switch (pin)
{
case Socket.Pin.Three:
channel = socket.AnalogInput3;
break;
case Socket.Pin.Four:
channel = socket.AnalogInput4;
break;
case Socket.Pin.Five:
channel = socket.AnalogInput5;
break;
}
// native implementation is preferred to an indirected one
if (channel == Cpu.AnalogChannel.ANALOG_NONE && socket.AnalogInputIndirector != null)
Interface = socket.AnalogInputIndirector(socket, pin, module);
else
Interface = new NativeAnalogInput(socket, pin, module, channel);
}
示例4: Create
/// <summary>
/// Creates an instance of <see cref="PwmOutput" /> for the given socket and pin number.
/// </summary>
/// <remarks>This automatically checks that the socket supports Type P, and reserves the pin.
/// An exception will be thrown if there is a problem with these checks.</remarks>
/// <param name="socket">The socket that supports pulse width modulation (PWM) output.</param>
/// <param name="pin">The pin on the socket that supports PWM.</param>
/// <param name="invert">Whether to invert the output voltage.</param>
/// <param name="module">The module using this PWM output interface, which can be null if unspecified.</param>
/// <returns>An instance of <see cref="PwmOutput" /> for the given socket and pin number.</returns>
public static PwmOutput Create(Socket socket, Socket.Pin pin, bool invert, Module module)
{
socket.EnsureTypeIsSupported('P', module);
socket.ReservePin(pin, module);
Cpu.PWMChannel channel = Cpu.PWMChannel.PWM_NONE;
switch (pin)
{
case Socket.Pin.Seven:
channel = socket.PWM7;
break;
case Socket.Pin.Eight:
channel = socket.PWM8;
break;
case Socket.Pin.Nine:
channel = socket.PWM9;
break;
}
// native implementation is preferred to an indirected one
if (channel == Cpu.PWMChannel.PWM_NONE && socket.PwmOutputIndirector != null)
return socket.PwmOutputIndirector(socket, pin, invert, module);
else
return new NativePwmOutput(socket, pin, invert, module, channel);
}
示例5: I2CBus
// Note: A constructor summary is auto-generated by the doc builder.
/// <summary></summary>
/// <remarks>This automatically checks that the socket supports Type I, and reserves the SDA and SCL pins.
/// An exception will be thrown if there is a problem with these checks.</remarks>
/// <param name="address">The address for the I2C device.</param>
/// <param name="clockRateKhz">The clock rate, in kHz, used when communicating with the I2C device.</param>
/// <param name="socket">The socket for this I2C device interface.</param>
/// <param name="module">The module using this I2C interface, which can be null if unspecified.</param>
public I2CBus(Socket socket, ushort address, int clockRateKhz, Module module)
{
socket.EnsureTypeIsSupported('I', module);
lock (I2CLock)
{
if (device == null)
{
socket.ReservePin(Socket.Pin.Eight, module);
socket.ReservePin(Socket.Pin.Nine, module);
device = new I2CDevice(new I2CDevice.Configuration(0, 50));
}
this.configuration = new I2CDevice.Configuration(address, clockRateKhz);
}
}
示例6: DigitalInput
// Note: A constructor summary is auto-generated by the doc builder.
/// <summary></summary>
/// <param name="socket">The socket for the digital input interface.</param>
/// <param name="pin">The pin used by the digital input interface.</param>
/// <param name="glitchFilterMode">
/// A value from the <see cref="GlitchFilterMode"/> enumeration that specifies
/// whether to enable the glitch filter on this digital input interface.
/// </param>
/// <param name="resistorMode">
/// A value from the <see cref="ResistorMode"/> enumeration that establishes a default state for the digital input interface. N.B. .NET Gadgeteer mainboards are only required to support ResistorMode.PullUp on interruptable GPIOs and are never required to support ResistorMode.PullDown; consider putting the resistor on the module itself.
/// </param>
/// <param name="module">The module using this interface, which can be null if unspecified.</param>
public DigitalInput(Socket socket, Socket.Pin pin, GlitchFilterMode glitchFilterMode, ResistorMode resistorMode, Module module)
{
this.port = new InputPort(socket.ReservePin(pin, module), glitchFilterMode == GlitchFilterMode.On, (Port.ResistorMode)resistorMode);
if (this.port == null)
{
// this is a mainboard error but should not happen since we check for this, but it doesnt hurt to double-check
throw new Socket.InvalidSocketException("Socket " + socket + " has an error with its Digital Input functionality. Please try a different socket.");
}
}
示例7: DigitalOutput
// Note: A constructor summary is auto-generated by the doc builder.
/// <summary></summary>
/// <param name="socket">The socket for the digital output interface.</param>
/// <param name="pin">The pin used by the digital output interface.</param>
/// <param name="initialState">The initial state to place on the digital output interface port.</param>
/// <param name="module">The module using this interface (which can be null if unspecified).</param>
public DigitalOutput(Socket socket, Socket.Pin pin, bool initialState, Module module)
{
this.port = new OutputPort(socket.ReservePin(pin, module), initialState);
if (this.port == null)
{
// this is a mainboard error but should not happen since we check for this, but it doesnt hurt to double-check
throw new Socket.InvalidSocketException("Socket " + socket + " has an error with its Digital Output functionality. Please try a different socket.");
}
}
示例8: Create
/// <summary>
/// Creates an instance of <see cref="InterruptInput" /> for the given socket and pin number.
/// </summary>
/// <param name="socket">The socket for the interrupt input interface.</param>
/// <param name="pin">The pin used by the interrupt input interface.</param>
/// <param name="glitchFilterMode">
/// A value from the <see cref="GlitchFilterMode"/> enumeration that specifies
/// whether to enable the glitch filter on this interrupt input interface.
/// </param>
/// <param name="resistorMode">
/// A value from the <see cref="ResistorMode"/> enumeration that establishes a default state for the interrupt input interface. N.B. .NET Gadgeteer mainboards are only required to support ResistorMode.PullUp on interruptable GPIOs and are never required to support ResistorMode.PullDown; consider putting the resistor on the module itself.
/// </param>
/// <param name="interruptMode">
/// A value from the <see cref="InterruptMode"/> enumeration that establishes the requisite conditions
/// for the interface port to generate an interrupt.
/// </param>
/// <param name="module">The module using this interrupt input interface, which can be null if unspecified.</param>
/// <returns>An instance of <see cref="InterruptInput" /> for the given socket and pin number.</returns>
public static InterruptInput Create(Socket socket, Socket.Pin pin, GlitchFilterMode glitchFilterMode, ResistorMode resistorMode, InterruptMode interruptMode, Module module)
{
Cpu.Pin reservedPin = socket.ReservePin(pin, module);
// native implementation is preferred to an indirected one
if (reservedPin == Cpu.Pin.GPIO_NONE && socket.InterruptIndirector != null)
return socket.InterruptIndirector(socket, pin, glitchFilterMode, resistorMode, interruptMode, module);
else
return new NativeInterruptInput(socket, pin, glitchFilterMode, resistorMode, interruptMode, module, reservedPin);
}
示例9: DigitalInput
// Note: A constructor summary is auto-generated by the doc builder.
/// <summary></summary>
/// <param name="socket">The socket for the digital input interface.</param>
/// <param name="pin">The pin used by the digital input interface.</param>
/// <param name="glitchFilterMode">
/// A value from the <see cref="GlitchFilterMode"/> enumeration that specifies
/// whether to enable the glitch filter on this digital input interface.
/// </param>
/// <param name="resistorMode">
/// A value from the <see cref="ResistorMode"/> enumeration that establishes a default state for the digital input interface. N.B. .NET Gadgeteer mainboards are only required to support ResistorMode.PullUp on interruptable GPIOs and are never required to support ResistorMode.PullDown; consider putting the resistor on the module itself.
/// </param>
/// <param name="module">The module using this interface, which can be null if unspecified.</param>
public DigitalInput(Socket socket, Socket.Pin pin, GlitchFilterMode glitchFilterMode, ResistorMode resistorMode, Module module)
{
Cpu.Pin reservedPin = socket.ReservePin(pin, module);
// native implementation is preferred to an indirected one
if (reservedPin == Cpu.Pin.GPIO_NONE && socket.DigitalInputIndirector != null)
Interface = socket.DigitalInputIndirector(socket, pin, glitchFilterMode, resistorMode, module);
else
Interface = new NativeDigitalInput(socket, pin, glitchFilterMode, resistorMode, module, reservedPin);
}
示例10: Create
/// <summary>
/// Creates an instance of <see cref="DigitalIO" /> for the given socket and pin number.
/// </summary>
/// <param name="socket">The socket for the digital input/output interface.</param>
/// <param name="pin">The pin used by the digital input/output interface.</param>
/// <param name="initialState">
/// The initial state to set on the digital input/output interface port.
/// This value becomes effective as soon as the port is enabled as an output port.
/// </param>
/// <param name="glitchFilterMode">
/// A value from the <see cref="GlitchFilterMode"/> enumeration that specifies
/// whether to enable the glitch filter on this digital input/output interface.
/// </param>
/// <param name="resistorMode">
/// A value from the <see cref="ResistorMode"/> enumeration that establishes a default state for the digital input/output interface. N.B. .NET Gadgeteer mainboards are only required to support ResistorMode.PullUp on interruptable GPIOs and are never required to support ResistorMode.PullDown; consider putting the resistor on the module itself.
/// </param>
/// <param name="module">The module using this interface, which can be null if unspecified.</param>
/// <returns>An instance of <see cref="DigitalIO" /> for the given socket and pin number.</returns>
public static DigitalIO Create(Socket socket, Socket.Pin pin, bool initialState, GlitchFilterMode glitchFilterMode, ResistorMode resistorMode, Module module)
{
Cpu.Pin reservedPin = socket.ReservePin(pin, module);
// native implementation is preferred to an indirected one
if (reservedPin == Cpu.Pin.GPIO_NONE && socket.DigitalIOIndirector != null)
return socket.DigitalIOIndirector(socket, pin, initialState, glitchFilterMode, resistorMode, module);
else
return new NativeDigitalIO(socket, pin, initialState, glitchFilterMode, resistorMode, module, reservedPin);
}
示例11: DigitalOutput
// Note: A constructor summary is auto-generated by the doc builder.
/// <summary></summary>
/// <param name="socket">The socket for the digital output interface.</param>
/// <param name="pin">The pin used by the digital output interface.</param>
/// <param name="initialState">The initial state to place on the digital output interface port.</param>
/// <param name="module">The module using this interface (which can be null if unspecified).</param>
public DigitalOutput(Socket socket, Socket.Pin pin, bool initialState, Module module)
{
Cpu.Pin reservedPin = socket.ReservePin(pin, module);
// native implementation is preferred to an indirected one
if (reservedPin == Cpu.Pin.GPIO_NONE && socket.DigitalOutputIndirector != null)
Interface = socket.DigitalOutputIndirector(socket, pin, initialState, module);
else
Interface = new NativeDigitalOutput(socket, pin, initialState, module, reservedPin);
}
示例12: Create
/// <summary>
/// Creates an instance of <see cref="I2CBus" /> for the given socket and pins.
/// </summary>
/// <remarks>This automatically checks that the socket supports Type I, and reserves the SDA and SCL pins.
/// An exception will be thrown if there is a problem with these checks.</remarks>
/// <param name="address">The address for the I2C device.</param>
/// <param name="clockRateKhz">The clock rate, in kHz, used when communicating with the I2C device.</param>
/// <param name="sdaPin">The SDA pin used by the I2C device.</param>
/// <param name="sclPin">The SCL pin used by the I2C device.</param>
/// <param name="socket">The socket for this I2C device interface.</param>
/// <param name="module">The module using this I2C interface, which can be null if unspecified.</param>
/// <returns>An instance of <see cref="I2CBus" /> for the given socket.</returns>
public static I2CBus Create(Socket socket, ushort address, int clockRateKhz, Socket.Pin sdaPin, Socket.Pin sclPin, Module module)
{
// There is only one I²C module in .NET Micro Framework, so the NativeI2CBus would just go and use it
// regardless of the requested pins, so we need to do the checks here instead.
Cpu.Pin reservedSclPin = socket.ReservePin(sclPin, module);
Cpu.Pin reservedSdaPin = socket.ReservePin(sdaPin, module);
Cpu.Pin nativeSclPin, nativeSdaPin;
HardwareProvider.HwProvider.GetI2CPins(out nativeSclPin, out nativeSdaPin);
// native implementation is preferred to an indirected one
if (reservedSdaPin == nativeSdaPin && reservedSclPin == nativeSclPin)
return new NativeI2CBus(socket, address, clockRateKhz, module);
else if (socket.I2CBusIndirector != null)
return socket.I2CBusIndirector(socket, sdaPin, sclPin, address, clockRateKhz, module);
else
return new SoftwareI2CBus(socket, sdaPin, sclPin, address, clockRateKhz, module);
}
示例13: InterruptInput
// Note: A constructor summary is auto-generated by the doc builder.
/// <summary></summary>
/// <param name="socket">The socket for the interrupt input interface.</param>
/// <param name="pin">The pin used by the interrupt input interface.</param>
/// <param name="glitchFilterMode">
/// A value from the <see cref="GlitchFilterMode"/> enumeration that specifies
/// whether to enable the glitch filter on this interrupt input interface.
/// </param>
/// <param name="resistorMode">
/// A value from the <see cref="ResistorMode"/> enumeration that establishes a default state for the interrupt input interface. N.B. .NET Gadgeteer mainboards are only required to support ResistorMode.PullUp on interruptable GPIOs and are never required to support ResistorMode.PullDown; consider putting the resistor on the module itself.
/// </param>
/// <param name="interruptMode">
/// A value from the <see cref="InterruptMode"/> enumeration that establishes the requisite conditions
/// for the interface port to generate an interrupt.
/// </param>
/// <param name="module">The module using this interrupt input interface, which can be null if unspecified.</param>
public InterruptInput(Socket socket, Socket.Pin pin, GlitchFilterMode glitchFilterMode, ResistorMode resistorMode, InterruptMode interruptMode, Module module)
{
this.port = new InterruptPort(socket.ReservePin(pin, module), glitchFilterMode == GlitchFilterMode.On, (Port.ResistorMode)resistorMode, (Port.InterruptMode)interruptMode);
if (this.port == null)
{
// this is a mainboard error but should not happen since we check for this, but it doesnt hurt to double-check
throw new Socket.InvalidSocketException("Socket " + socket + " has an error with its Interrupt Input functionality. Please try a different socket.");
}
this.SynchronousUnsafeEventInvocation = false;
this.port.OnInterrupt += new NativeEventHandler(this._port_OnInterrupt);
}
示例14: Create
/// <summary>
/// Creates an instance of <see cref="Serial" /> for the given socket.
/// </summary>
/// <remarks>This automatically checks that the socket supports Type U, and reserves the pins.
/// An exception will be thrown if there is a problem with these checks.</remarks>
/// <param name="baudRate">The baud rate for the serial port.</param>
/// <param name="parity">A value from the <see cref="SerialParity"/> enumeration that specifies
/// the parity for the port.</param>
/// <param name="stopBits">A value from the <see cref="SerialStopBits"/> enumeration that specifies
/// the stop bits for the port.</param>
/// <param name="dataBits">The number of data bits.</param>
/// <param name="socket">The socket for this serial interface.</param>
/// <param name="hardwareFlowControlRequirement">Specifies whether the module must use hardware flow control, will use hardware flow control if available, or does not use hardware flow control.</param>
/// <param name="module">The module using this interface (which can be null if unspecified).</param>
/// <returns>An instance of <see cref="Serial" /> for the given socket.</returns>
public static Serial Create(Socket socket, int baudRate, SerialParity parity, SerialStopBits stopBits, int dataBits, HardwareFlowControl hardwareFlowControlRequirement, Module module)
{
bool hwFlowSupported = false;
if (hardwareFlowControlRequirement == HardwareFlowControl.Required)
socket.EnsureTypeIsSupported('K', module);
else
{
hwFlowSupported = socket.SupportsType('K');
if (!hwFlowSupported)
socket.EnsureTypeIsSupported('U', module);
}
socket.ReservePin(Socket.Pin.Four, module);
socket.ReservePin(Socket.Pin.Five, module);
if (hardwareFlowControlRequirement != HardwareFlowControl.NotRequired)
{
// must reserve hardware flow control pins even if not using them, since they are electrically connected.
socket.ReservePin(Socket.Pin.Six, module);
socket.ReservePin(Socket.Pin.Seven, module);
}
string portName = socket.SerialPortName;
Serial instance;
if ((portName == null || portName == "") && socket.SerialIndirector != null)
instance = socket.SerialIndirector(socket, baudRate, (SerialParity)parity, (SerialStopBits)stopBits, dataBits, (HardwareFlowControl)hardwareFlowControlRequirement, module);
else
instance = new NativeSerial(socket, baudRate, (SerialParity)parity, (SerialStopBits)stopBits, dataBits, (HardwareFlowControl)hardwareFlowControlRequirement, module, portName, hwFlowSupported);
instance.NewLine = "\n";
instance.ReadTimeout = System.Threading.Timeout.Infinite;
instance.WriteTimeout = System.Threading.Timeout.Infinite;
return instance;
}
示例15: AnalogOutput
// Note: A constructor summary is auto-generated by the doc builder.
/// <summary></summary>
/// <remarks>This automatically checks that the socket supports Type O, and reserves the pin.
/// An exception will be thrown if there is a problem with these checks.</remarks>
/// <param name="socket">The analog output capable socket.</param>
/// <param name="pin">The pin to assign to the analog output.</param>
/// <param name="module">The module using this analog output interface, which can be null if unspecified.</param>
public AnalogOutput(Socket socket, Socket.Pin pin, Module module)
{
this.socket = socket;
socket.EnsureTypeIsSupported('O', module);
port = socket.AnalogOutput;
if (port == null)
{
// this is a mainboard error but should not happen since we check for this, but it doesnt hurt to double-check
throw new Socket.InvalidSocketException("Socket " + socket + " has an error with its Analog Output functionality. Please try a different socket.");
}
socket.ReservePin(pin, module);
}