本文整理汇总了C#中Socket.EnsureTypeIsSupported方法的典型用法代码示例。如果您正苦于以下问题:C# Socket.EnsureTypeIsSupported方法的具体用法?C# Socket.EnsureTypeIsSupported怎么用?C# Socket.EnsureTypeIsSupported使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Socket
的用法示例。
在下文中一共展示了Socket.EnsureTypeIsSupported方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: 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);
}
示例3: 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);
if (socket.I2CBusIndirector != null)
Interface = socket.I2CBusIndirector(socket, address, clockRateKhz, module);
else
Interface = new NativeI2CBus(socket, address, clockRateKhz, module);
}
示例4: 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;
}
示例5: 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);
}
示例6: Create
/// <summary>
/// Creates an instance of <see cref="AnalogOutput" /> for the given socket and pin number.
/// </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>
/// <returns>An instance of <see cref="AnalogOutput" /> for the given socket and pin number.</returns>
public static AnalogOutput Create(Socket socket, Socket.Pin pin, Module module)
{
socket.EnsureTypeIsSupported('O', module);
socket.ReservePin(pin, module);
Cpu.AnalogOutputChannel channel = socket.AnalogOutput5;
// native implementation is preferred to an indirected one
if (channel == Cpu.AnalogOutputChannel.ANALOG_OUTPUT_NONE && socket.AnalogOutputIndirector != null)
return socket.AnalogOutputIndirector(socket, pin, module);
else
return new NativeAnalogOutput(socket, pin, module, channel);
}
示例7: 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);
}
}
示例8: Create
/// <summary>
/// Creates an instance of <see cref="Spi" /> for the given socket.
/// </summary>
/// <param name="socket">The <see cref="Socket"/> for the <see cref="Spi"/> interface.</param>
/// <param name="spiConfiguration">The <see cref="SpiConfiguration"/> object for the <see cref="Spi"/> interface.</param>
/// <param name="sharingMode">The <see cref="SpiSharing"/> mode of the <see cref="SPI"/> interface.</param>
/// <param name="chipSelectSocket">The chip select <see cref="Socket"/> of the <see cref="Spi"/> interface. Can be null if not used.</param>
/// <param name="chipSelectSocketPin">The chip select pin on <paramref name="chipSelectSocket"/>.</param>
/// <param name="busySocket">The busy <see cref="Socket"/> of the <see cref="Spi" /> interface. Can be null if not used.</param>
/// <param name="busySocketPin">The busy pin to on the <paramref name="busySocket"/>.</param>
/// <param name="module">The <see cref="Module"/> that is connected to the <see cref="Spi"/> interface.</param>
/// <returns></returns>
public static Spi Create(Socket socket, SpiConfiguration spiConfiguration, SpiSharing sharingMode, Socket chipSelectSocket, Socket.Pin chipSelectSocketPin, Socket busySocket, Socket.Pin busySocketPin, Module module)
{
socket.EnsureTypeIsSupported('S', module);
Cpu.Pin reservedSelectPin = Socket.UnspecifiedPin;
Cpu.Pin reservedBusyPin = Socket.UnspecifiedPin;
if (chipSelectSocket != null)
reservedSelectPin = chipSelectSocket.ReservePin(chipSelectSocketPin, module);
if (busySocket != null)
reservedBusyPin = busySocket.ReservePin(busySocketPin, module);
// reserved pins will be:
// UnspecifiedPin if no chip select/busy pin is used
// UnnumberedPin if a chip select/busy pin was used on an indirected (non-forwarded socket)
// a valid Cpu.Pin otherwise
if (socket.SPIModule != Socket.SocketInterfaces.SPIMissing)
return new NativeSpi(socket, spiConfiguration, sharingMode, reservedSelectPin, reservedBusyPin, module, socket.SPIModule);
else
return socket.SpiIndirector(socket, spiConfiguration, sharingMode, chipSelectSocket, chipSelectSocketPin, busySocket, busySocketPin, module);
}
示例9: PWMOutput
// Note: A constructor summary is auto-generated by the doc builder.
/// <summary>
/// </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="module">The module using this PWM output interface, which can be null if unspecified.</param>
public PWMOutput(Socket socket, Socket.Pin pin, Module module)
{
this.pin = pin;
socket.EnsureTypeIsSupported('P',module);
switch(pin)
{
case Socket.Pin.Seven:
pwm = socket.PWM7;
break;
case Socket.Pin.Eight:
pwm = socket.PWM8;
break;
case Socket.Pin.Nine:
pwm = socket.PWM9;
break;
default:
if (module != null)
{
throw new Socket.InvalidSocketException("Module " + module + " cannot use PWM interface on pin " + pin + " - pin must be in range 7 to 9.");
}
else
{
throw new Socket.InvalidSocketException("Cannot use PWM interface on pin " + pin + " - pin must be in range 7 to 9.");
}
}
if (pwm == null)
{
// this is a mainboard error that should not happen (we already check for it in SocketInterfaces.RegisterSocket) but just in case...
throw new Socket.InvalidSocketException("Socket " + socket + " has an error with its PWM functionality. Please try a different socket.");
}
socket.ReservePin(pin, module);
this.pwm.Active = false;
}
示例10: SoftwareI2C
// Note: A constructor summary is auto-generated by the doc builder.
/// <summary></summary>
/// <remarks>This automatically checks that the socket supports Type X or Y as appropriate, and reserves the SDA and SCL pins.
/// An exception will be thrown if there is a problem with these checks.</remarks>
/// <param name="socket">The socket for this software I2C device interface.</param>
/// <param name="sdaPin">The socket pin used for I2C data.</param>
/// <param name="sclPin">The socket pin used for I2C clock.</param>
/// <param name="module">The module using this I2C interface, which can be null if unspecified.</param>
public SoftwareI2C(Socket socket, Socket.Pin sdaPin, Socket.Pin sclPin, Module module)
{
// first check the socket is compatible
if (sclPin > Socket.Pin.Five || sdaPin > Socket.Pin.Five)
{
socket.EnsureTypeIsSupported('Y', module);
}
else
{
socket.EnsureTypeIsSupported(new char[] { 'X', 'Y' }, module);
}
if (ForceManagedSoftwareI2CImplementation || socket.NativeI2CWriteRead == null) usingManaged = true;
// then see if we've already reserved the pins and got instances of the ports, otherwise do that.
string sdaPinString = socket.ToString() + "___" + sdaPin;
if (!ReservedSdaPinPorts.Contains(sdaPinString))
{
Cpu.Pin sdaCpuPin = socket.ReservePin(sdaPin, module);
if (usingManaged)
{
sdaPort = new TristatePort(sdaCpuPin, false, false, ForceManagedPullUps ? Port.ResistorMode.PullUp : Port.ResistorMode.Disabled);
}
ReservedSdaPinPorts.Add(sdaPinString, sdaPort);
}
else
{
sdaPort = (TristatePort)ReservedSdaPinPorts[sdaPinString];
}
string sclPinString = socket.ToString() + "___" + sclPin;
if (!ReservedSclPinPorts.Contains(sclPinString))
{
Cpu.Pin sclCpuPin = socket.ReservePin(sclPin, module);
if (usingManaged)
{
sclPort = new TristatePort(sclCpuPin, false, false, ForceManagedPullUps ? Port.ResistorMode.PullUp : Port.ResistorMode.Disabled);
}
ReservedSclPinPorts.Add(sclPinString, sclPort);
}
else
{
sclPort = (TristatePort)ReservedSclPinPorts[sclPinString];
}
this.socket = socket;
this.sdaPin = sdaPin;
this.sclPin = sclPin;
if (usingManaged)
{
lock (SoftwareI2CTimeoutList)
{
timeoutCount = -1; // Prevent the TimeoutHandler thread from watching this port for now
SoftwareI2CTimeoutList.Add(this);
if (timeoutThread == null)
{
threadExit = false;
timeoutThread = new Thread(new ThreadStart(TimeoutHandler));
timeoutThread.Start();
}
}
}
}
示例11: PWMOutput
// Note: A constructor summary is auto-generated by the doc builder.
/// <summary>
/// </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>
public PWMOutput(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;
}
if (channel == Cpu.PWMChannel.PWM_NONE && socket.PwmOutputIndirector != null)
Interface = socket.PwmOutputIndirector(socket, pin, invert, module);
else
Interface = new NativePwmOutput(socket, pin, invert, module, channel);
}
示例12: SPI
/// <summary>
///
/// </summary>
/// <param name="socket">The <see cref="Socket"/> for the <see cref="SPI"/> interface.</param>
/// <param name="spiConfiguration">The <see cref="Configuration"/> object for the <see cref="SPI"/> interface.</param>
/// <param name="sharingMode">The <see cref="Sharing"/> mode of the <see cref="SPI"/> interface.</param>
/// <param name="chipSelectSocket">The chip select <see cref="Socket"/>of the <see cref="SPI"/> interface.</param>
/// <param name="chipSelectPin">The <see cref="Socket"/></param>
/// <param name="module">The <see cref="Module"/> that is connected to the <see cref="SPI"/> interface.</param>
public SPI(Socket socket, Configuration spiConfiguration, Sharing sharingMode, Socket chipSelectSocket, Socket.Pin chipSelectPin, Module module)
{
socket.EnsureTypeIsSupported('S', module);
Cpu.Pin reservedSelectPin = Socket.UnspecifiedPin;
if (chipSelectSocket != null)
reservedSelectPin = chipSelectSocket.ReservePin(chipSelectPin, module);
if (socket.SPIModule != Socket.SocketInterfaces.SPIMissing)
Interface = new NativeSpi(socket, spiConfiguration == null ? null : new Socket.SocketInterfaces.SpiConfiguration(
spiConfiguration.ChipSelectActiveState,
spiConfiguration.ChipSelectSetupTime,
spiConfiguration.ChipSelectHoldTime,
spiConfiguration.ClockIdleState,
spiConfiguration.ClockEdge,
spiConfiguration.ClockRateKHz,
false), (Socket.SocketInterfaces.SpiSharing)sharingMode, reservedSelectPin, module, socket.SPIModule);
else
Interface = socket.SpiIndirector(socket, spiConfiguration == null ? null : new Socket.SocketInterfaces.SpiConfiguration(
spiConfiguration.ChipSelectActiveState,
spiConfiguration.ChipSelectSetupTime,
spiConfiguration.ChipSelectHoldTime,
spiConfiguration.ClockIdleState,
spiConfiguration.ClockEdge,
spiConfiguration.ClockRateKHz,
false), (Socket.SocketInterfaces.SpiSharing)sharingMode, chipSelectSocket, chipSelectPin, null, default(Socket.Pin), module);
_spiModule = socket.SPIModule;
}
示例13: Music
/////////////////////////////////////////////////////////////////////////////////////////////////////
// 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 Music(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.GetSocket(socketNumber, true, this, null);
_socket.EnsureTypeIsSupported(new[] {'S'}, this);
m_dataConfig = new SPI.Configuration(_socket.CpuPins[5], false, 0, 0, false, true, 2000, _socket.SPIModule, _socket.CpuPins[3], false);
m_cmdConfig = new SPI.Configuration(_socket.CpuPins[6], false, 0, 0, false, true, 2000, _socket.SPIModule, _socket.CpuPins[3], false);
}
示例14: GetInstance
public static SPIInstance GetInstance(Socket socket, Module module)
{
var spimodule = socket.SPIModule;
if (spimodule == Socket.SPIMissing)
{
// this is a mainboard error that should not happen (we already check for it in SocketInterfaces.RegisterSocket) but just in case...
throw new Socket.InvalidSocketException("Socket " + socket + " has an error with its SPI functionality. Please try a different socket.");
}
foreach (SPIInstance spiInstance in spiInstances)
{
if (spiInstance.SPIModule == spimodule)
{
return spiInstance;
}
}
socket.EnsureTypeIsSupported('S', module);
SPIInstance newSpiInstance = new SPIInstance(socket, spimodule);
spiInstances.Add(newSpiInstance);
return newSpiInstance;
}