本文整理汇总了C#中Windows.Devices.I2c.I2cConnectionSettings类的典型用法代码示例。如果您正苦于以下问题:C# I2cConnectionSettings类的具体用法?C# I2cConnectionSettings怎么用?C# I2cConnectionSettings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
I2cConnectionSettings类属于Windows.Devices.I2c命名空间,在下文中一共展示了I2cConnectionSettings类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Initialize
private async Task Initialize()
{
try
{
if (Interlocked.CompareExchange(ref _isInitialized, 1, 0) == 1)
{
return;
}
// Get a selector string that will return all I2C controllers on the system
string deviceSelector = I2cDevice.GetDeviceSelector();
// Find the I2C bus controller device with our selector string
var dis = await DeviceInformation.FindAllAsync(deviceSelector);
if (dis.Count == 0)
{
throw new Hdc100XInitializationException("No I2C controllers were found on the system");
}
var settings = new I2cConnectionSettings((int)_busAddress)
{
BusSpeed = I2cBusSpeed.FastMode
};
_sensorDevice = await I2cDevice.FromIdAsync(dis[0].Id, settings);
if (_sensorDevice == null)
{
throw new Hdc100XInitializationException(string.Format(
"Slave address {0} on I2C Controller {1} is currently in use by " +
"another application. Please ensure that no other applications are using I2C.",
settings.SlaveAddress,
dis[0].Id));
}
// Configure sensor:
// - measure with 14bit precision
// - measure both temperature and humidity
_sensorDevice.Write(new byte[] { 0x02, 0x10, 0x00 });
_initalizationCompletion.SetResult(true);
}
catch (Hdc100XInitializationException)
{
_initalizationCompletion.SetResult(false);
throw;
}
catch (Exception exc)
{
_initalizationCompletion.SetResult(false);
throw new Hdc100XInitializationException("Unexpected error during initialization", exc);
}
}
开发者ID:stormy-ua,项目名称:WindowsIoTCore.Drivers,代码行数:50,代码来源:Hdc100X.cs
示例2: Initialize
public async Task Initialize()
{
Debug.WriteLine("TCS34725::Initialize");
try
{
var settings = new I2cConnectionSettings(TCS34725_Address);
settings.BusSpeed = I2cBusSpeed.FastMode;
string aqs = I2cDevice.GetDeviceSelector(I2CControllerName);
var dis = await DeviceInformation.FindAllAsync(aqs);
colorSensor = await I2cDevice.FromIdAsync(dis[0].Id, settings);
// Now setup the LedControlPin
gpio = GpioController.GetDefault();
LedControlGPIOPin = gpio.OpenPin(LedControlPin);
LedControlGPIOPin.SetDriveMode(GpioPinDriveMode.Output);
}
catch (Exception e)
{
Debug.WriteLine("Exception: " + e.Message + "\n" + e.StackTrace);
throw;
}
}
开发者ID:apdutta,项目名称:prototype,代码行数:26,代码来源:TCS34725.cs
示例3: Init
/// <summary>
/// Initializes the I2C connection and channels.
/// </summary>
/// <returns>A <see cref="Task"/> instance which can be awaited on for completion.</returns>
public async Task Init()
{
if (SlaveAddress < 0) throw new Exception("Invalid SlaveAddress value configured. Please call the class constructor with a valid I2C bus slave address.");
Debug.WriteLine("Initializing PCA9685 against slave address {0}.", SlaveAddress);
string aqs = I2cDevice.GetDeviceSelector();
var i2cDevices = await DeviceInformation.FindAllAsync(aqs);
if (i2cDevices.Count == 0)
{
Debug.WriteLine("No I2C controllers were found on the system.");
return;
}
var settings = new I2cConnectionSettings(GeneralCallSlaveAddress);
settings.BusSpeed = I2cBusSpeed.FastMode;
GeneralCallDev = await I2cDevice.FromIdAsync(i2cDevices[0].Id, settings);
if (GeneralCallDev == null)
{
var errorMessage = string.Format(
"Slave address {0} on I2C Controller {1} is currently in use by another application.",
settings.SlaveAddress,
i2cDevices[0].Id);
throw new Exception(errorMessage);
}
SoftwareReset();
settings = new I2cConnectionSettings(SlaveAddress);
settings.BusSpeed = I2cBusSpeed.FastMode;
Dev = await I2cDevice.FromIdAsync(i2cDevices[0].Id, settings);
if (Dev == null)
{
var errorMessage = string.Format(
"Slave address {0} on I2C Controller {1} is currently in use by another application.",
settings.SlaveAddress,
i2cDevices[0].Id);
throw new Exception(errorMessage);
}
Debug.WriteLine("PCA9685 I2C channels created.");
SetAllChannelsDutyCycle(0.0f);
// Output drive mode is totem-pole not open drain
WriteReg(MODE2, OUTDRV);
// Turn-off oscillator and acknowledge All-Call transfers
WriteReg(MODE1, ALLCALL);
await Task.Delay(1);
byte mode1 = ReadReg(MODE1);
// Turn on oscillator
mode1 &= unchecked((byte)~SLEEP);
WriteReg(MODE1, mode1);
await Task.Delay(1);
Debug.WriteLine("PCA9685 initialization complete.");
}
开发者ID:fredfourie,项目名称:Argonaut,代码行数:64,代码来源:PCA9685.cs
示例4: initI2C
private async void initI2C()
{
try
{
var i2cSettings = new I2cConnectionSettings(I2C_ARDUINO);
i2cSettings.BusSpeed = I2cBusSpeed.FastMode;
string deviceSelector = I2cDevice.GetDeviceSelector(I2C_CONTROLLER_NAME);
var i2cDeviceControllers = await DeviceInformation.FindAllAsync(deviceSelector);
var i2cdev = await I2cDevice.FromIdAsync(i2cDeviceControllers[0].Id, i2cSettings);
byte[] wbuffer = new byte[] { 1, 2 };
byte[] rbuffer = new byte[8];
//var resutl = i2cdev.WriteReadPartial(wbuffer, rbuffer);
//Debug.WriteLine(resutl.Status);
//i2cdev.WriteRead(wbuffer, rbuffer);
i2cdev.Write(wbuffer);
await Task.Delay(10000);
var resutl = i2cdev.ReadPartial(rbuffer);
Debug.WriteLine(rbuffer[0]);
}
catch (Exception ex)
{
throw;
}
}
开发者ID:tkopacz,项目名称:iot-kabelki-azure-iot-hub,代码行数:26,代码来源:MainPage.xaml.cs
示例5: InitializeAsync
//Method to initialize the BMP280 sensor
public async Task InitializeAsync()
{
Debug.WriteLine("BMP280::InitializeAsync");
try
{
//Instantiate the I2CConnectionSettings using the device address of the BMP280
var settings = new I2cConnectionSettings(Bmp280Address)
{
BusSpeed = I2cBusSpeed.FastMode
};
//Set the I2C bus speed of connection to fast mode
//Use the I2CBus device selector to create an advanced query syntax string
var aqs = I2cDevice.GetDeviceSelector(I2CControllerName);
//Use the Windows.Devices.Enumeration.DeviceInformation class to create a collection using the advanced query syntax string
var dis = await DeviceInformation.FindAllAsync(aqs);
//Instantiate the the BMP280 I2C device using the device id of the I2CBus and the I2CConnectionSettings
_bmp280 = await I2cDevice.FromIdAsync(dis[0].Id, settings);
//Check if device was found
if (_bmp280 == null)
{
Debug.WriteLine("Device not found");
}
}
catch (Exception e)
{
Debug.WriteLine("Exception: " + e.Message + "\n" + e.StackTrace);
throw;
}
}
开发者ID:RGroenewald,项目名称:adafruitsample,代码行数:31,代码来源:BMP280.cs
示例6: StartScenarioAsync
private async Task StartScenarioAsync()
{
string i2cDeviceSelector = I2cDevice.GetDeviceSelector();
IReadOnlyList<DeviceInformation> devices = await DeviceInformation.FindAllAsync(i2cDeviceSelector);
// 0x40 was determined by looking at the datasheet for the HTU21D sensor.
var HTU21D_settings = new I2cConnectionSettings(0x40);
// If this next line crashes with an ArgumentOutOfRangeException,
// then the problem is that no I2C devices were found.
//
// If the next line crashes with Access Denied, then the problem is
// that access to the I2C device (HTU21D) is denied.
//
// The call to FromIdAsync will also crash if the settings are invalid.
//
// FromIdAsync produces null if there is a sharing violation on the device.
// This will result in a NullReferenceException in Timer_Tick below.
htu21dSensor = await I2cDevice.FromIdAsync(devices[0].Id, HTU21D_settings);
// Start the polling timer.
timer = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(500) };
timer.Tick += Timer_Tick;
timer.Start();
}
开发者ID:RasmusTG,项目名称:Windows-universal-samples,代码行数:25,代码来源:Scenario1_ReadData.xaml.cs
示例7: GetAvailableDevicesAddress
public async Task< List<byte> > GetAvailableDevicesAddress()
{
// get aqs filter to find i2c device
string aqs = I2cDevice.GetDeviceSelector("I2C1");
// Find the I2C bus controller with our selector string
var dis = await DeviceInformation.FindAllAsync(aqs);
if (dis.Count == 0)
throw new Exception("There is no I2C device"); // bus not found
List<byte> devicesList = new List<byte>();
for (byte i = 0; i < 127; i++)
{
I2cConnectionSettings settings = new I2cConnectionSettings(i);
// Create an I2cDevice with our selected bus controller and I2C settings
var device = await I2cDevice.FromIdAsync(dis[0].Id, settings);
var result = device.WritePartial(new byte[] { 0x00 });
if (result.Status == I2cTransferStatus.SlaveAddressNotAcknowledged) continue;
devicesList.Add(i);
device.Dispose();
}
return devicesList;
}
开发者ID:pozzzima123,项目名称:TcpListenerRTM,代码行数:25,代码来源:I2C.cs
示例8: Run
public async void Run()
{
var deviceSelector = I2cDevice.GetDeviceSelector("I2C1");
var devices = await DeviceInformation.FindAllAsync(deviceSelector);
if (devices.Count == 0)
{
return;
}
var settings = new I2cConnectionSettings(0x54); // 0x54 is the I2C device address for the PiGlow
using (I2cDevice device = await I2cDevice.FromIdAsync(devices[0].Id, settings))
{
InitPyGlow(device);
await Pulsate(
device,
brightness: 64,
numberOfPulses: 3,
speedOfPulses: 100);
await Pinwheel(
device,
brightness: 64,
numberOfSpins: 5,
speedOfSpin: 300);
ClearLeds(device);
}
}
开发者ID:TigerLeep,项目名称:Windows.10.IoT.Raspberry.Pi.Playground,代码行数:32,代码来源:MainPage.xaml.cs
示例9: MoveServo
/// <summary>
/// Moves servo to specified angle
/// </summary>
/// <param name="Angle">Angle to be moved</param>
/// <returns></returns>
public static async System.Threading.Tasks.Task<byte[]> MoveServo(byte Angle)
{
byte[] Response = new byte[1];
/* Gateway's I2C SLAVE address */
int SlaveAddress = 64; // 0x40
try
{
// Initialize I2C
var Settings = new I2cConnectionSettings(SlaveAddress);
Settings.BusSpeed = I2cBusSpeed.StandardMode;
if (AQS == null || DIS == null)
{
AQS = I2cDevice.GetDeviceSelector("I2C1");
DIS = await DeviceInformation.FindAllAsync(AQS);
}
using (I2cDevice Device = await I2cDevice.FromIdAsync(DIS[0].Id, Settings))
{
/* Send byte to the gateway to move servo at specified position */
Device.Write(new byte[] { Angle });
}
}
catch (Exception)
{
// SUPPRESS ANY ERROR
}
/* Return dummy or ZERO */
return Response;
}
开发者ID:AnuragVasanwala,项目名称:UltraSonic-Distance-Mapper,代码行数:38,代码来源:ArduinoGateway.cs
示例10: Initialize
public async Task Initialize()
{
Debug.WriteLine("PCA9685::Initialize");
try
{
var settings = new I2cConnectionSettings(PCA9685_Address);
settings.BusSpeed = I2cBusSpeed.FastMode;
string aqs = I2cDevice.GetDeviceSelector(I2CControllerName);
var dis = await DeviceInformation.FindAllAsync(aqs);
pca9685 = await I2cDevice.FromIdAsync(dis[0].Id, settings);
if (pca9685 == null)
{
Debug.WriteLine("PCA9685 failed to initialize");
}
await Begin();
setPWMFreq(60);
}
catch (Exception e)
{
Debug.WriteLine("Exception: " + e.Message + "\n" + e.StackTrace);
throw;
}
}
开发者ID:apdutta,项目名称:prototype,代码行数:28,代码来源:PCA9685.cs
示例11: InitializeSystem
internal async void InitializeSystem()
{
// initialize I2C communications
string deviceSelector = I2cDevice.GetDeviceSelector();
DeviceInformationCollection _i2cDeviceControllers = await DeviceInformation.FindAllAsync(deviceSelector);
if (_i2cDeviceControllers.Count == 0)
{
throw new I2cControllerNotFoundException(); ;
}
I2cConnectionSettings ambientTempI2cSettings = new I2cConnectionSettings(AMBIENT_TEMP_BASE_ADDRESS);
ambientTempI2cSettings.BusSpeed = I2cBusSpeed.StandardMode;
_i2cTempDevice = await I2cDevice.FromIdAsync(_i2cDeviceControllers[0].Id, ambientTempI2cSettings);
if (_i2cTempDevice == null)
{
throw new Exception(string.Format(
"Slave address {0} is currently in use on {1}. " +
"Please ensure that no other applications are using I2C.",
ambientTempI2cSettings.SlaveAddress,
_i2cDeviceControllers[0].Id));
}
HardwareReady = true;
if (SensorReady != null)
SensorReady(this, EventArgs.Empty);
}
开发者ID:AerialBreakSoftware,项目名称:Win10RaspberrySprinkle,代码行数:30,代码来源:i2cTempHumidity.cs
示例12: Initialise
public async Task Initialise(byte HardwareDeviceAddress)
{
System.Diagnostics.Debug.WriteLine("Initalise Started");
System.Diagnostics.Debug.WriteLine("Finding Device");
I2cConnectionSettings i2cSettings = new I2cConnectionSettings(HardwareDeviceAddress);
i2cSettings.BusSpeed = I2cBusSpeed.FastMode;
string DeviceSelector = I2cDevice.GetDeviceSelector(I2C_CONTROLLER_NAME);
DeviceInformationCollection i2cDeviceControllers = await DeviceInformation.FindAllAsync(DeviceSelector);
i2cDeviceChannel = await I2cDevice.FromIdAsync(i2cDeviceControllers[0].Id, i2cSettings);
System.Diagnostics.Debug.WriteLine("Device Found");
byte[] writeBuffer;
// Shutdown Register
writeBuffer = new byte[] { 0x00, 0x01 };
i2cDeviceChannel.Write(writeBuffer);
Debug.WriteLine("Shutdown Register set");
// Pin Enable Registers
writeBuffer = new byte[] { 0x13, 0xff };
i2cDeviceChannel.Write(writeBuffer);
writeBuffer = new byte[] { 0x14, 0xff };
i2cDeviceChannel.Write(writeBuffer);
writeBuffer = new byte[] { 0x15, 0xff };
i2cDeviceChannel.Write(writeBuffer);
System.Diagnostics.Debug.WriteLine("Initalise Complete");
}
开发者ID:QQOak,项目名称:i2cPWM,代码行数:35,代码来源:SN3218.cs
示例13: Init
public async void Init()
{
try
{
string aqs = I2cDevice.GetDeviceSelector(); /* Get a selector string that will return all I2C controllers on the system */
var dis = await DeviceInformation.FindAllAsync(aqs); /* Find the I2C bus controller device with our selector string */
var settings = new I2cConnectionSettings(I2CAddress)
{
BusSpeed = I2cBusSpeed.FastMode
};
_device = await I2cDevice.FromIdAsync(dis[0].Id, settings);
if (_device == null)
{
}
else
{
_isInited = true;
}
}
catch
{
_isInited = false;
throw;
}
}
开发者ID:TheBekker,项目名称:Bekker.Sensors,代码行数:28,代码来源:CMPS10.cs
示例14: Run
public async void Run(IBackgroundTaskInstance taskInstance)
{
//
// TODO: Insert code to perform background work
//
// If you start any asynchronous methods here, prevent the task
// from closing prematurely by using BackgroundTaskDeferral as
// described in http://aka.ms/backgroundtaskdeferral
//
var deferral = taskInstance.GetDeferral();
var settings = new I2cConnectionSettings(I2C_ADDRESS);
settings.BusSpeed = I2cBusSpeed.FastMode;
var aqs = I2cDevice.GetDeviceSelector(); /* Get a selector string that will return all I2C controllers on the system */
var dis = await DeviceInformation.FindAllAsync(aqs); /* Find the I2C bus controller devices with our selector string */
_dht11 = await I2cDevice.FromIdAsync(dis[0].Id, settings); /* Create an I2cDevice with our selected bus controller and I2C settings */
await begin();
while (true)
{
var temp = await readTemperature();
var hum = await readHumidity();
Debug.WriteLine($"{temp} C & {hum}% humidity");
await Task.Delay(2000);
}
deferral.Complete();
}
开发者ID:ZenRobotic,项目名称:DisplayBadge,代码行数:27,代码来源:StartupTask.cs
示例15: GetDevice
public static async Task<I2cDevice> GetDevice(int address, string controllerName)
{
var key = $"{address} - {controllerName}";
if (_deviceCache.ContainsKey(key))
{
return _deviceCache[key];
}
using (var l = await _locker.LockAsync())
{
if (_deviceCache.ContainsKey(key))
{
return _deviceCache[key];
}
var settings = new I2cConnectionSettings(address) { BusSpeed = I2cBusSpeed.FastMode };
var aqs = I2cDevice.GetDeviceSelector(controllerName);
var dis = await DeviceInformation.FindAllAsync(aqs);
var i2Cdevice = await I2cDevice.FromIdAsync(dis[0].Id, settings);
if (i2Cdevice == null)
{
return null;
}
_deviceCache.Add(key, i2Cdevice);
return i2Cdevice;
}
}
开发者ID:rahuldasnaskar,项目名称:xIOT,代码行数:34,代码来源:I2CDeviceCache.cs
示例16: Init
public async Task Init()
{
Debug.WriteLine("Initializing PCA9685");
string aqs = I2cDevice.GetDeviceSelector();
var dis = await DeviceInformation.FindAllAsync(aqs);
if (dis.Count == 0)
{
Debug.WriteLine("No I2C controllers were found on the system");
return;
}
var settings = new I2cConnectionSettings(GeneralCallSlaveAddress);
settings.BusSpeed = I2cBusSpeed.FastMode;
GeneralCallDev = await I2cDevice.FromIdAsync(dis[0].Id, settings);
if (GeneralCallDev == null)
{
Debug.WriteLine(
string.Format(
"Slave address {0} on I2C Controller {1} is currently in use by " +
"another application. Please ensure that no other applications are using I2C.",
settings.SlaveAddress,
dis[0].Id));
return;
}
SoftwareReset();
settings = new I2cConnectionSettings(SlaveAddress);
settings.BusSpeed = I2cBusSpeed.FastMode;
Dev = await I2cDevice.FromIdAsync(dis[0].Id, settings);
if (Dev == null)
{
Debug.WriteLine(
string.Format(
"Slave address {0} on I2C Controller {1} is currently in use by " +
"another application. Please ensure that no other applications are using I2C.",
settings.SlaveAddress,
dis[0].Id));
return;
}
Debug.WriteLine("PCA9685 I2C channels created");
SetAllChannelsDutyCycle(0.0f);
// Output drive mode is totem-pole not open drain
WriteReg(MODE2, OUTDRV);
// Turn-offi oscillator and acknowledge All-Call transfers
WriteReg(MODE1, ALLCALL);
await Task.Delay(1);
byte mode1 = ReadReg(MODE1);
// Trun-on oscillator
mode1 &= unchecked((byte)~SLEEP);
WriteReg(MODE1, mode1);
await Task.Delay(1);
Debug.WriteLine("PCA9685 initialization complete");
}
开发者ID:jadeiceman,项目名称:Argonaut,代码行数:59,代码来源:PCA9685.cs
示例17: OpenI2CConnection
/// <summary>
/// Opens a connection to the specified I2C device address.
/// </summary>
/// <param name="address">The 7-bit right aligned slave address (should not have 0x80
/// bit set!)</param>
/// <returns>A reference to the device</returns>
/// <exception cref="IOException">If I2C1 cannot be opened</exception>
private async Task<I2cDevice> OpenI2CConnection(int address) {
I2cConnectionSettings settings = new I2cConnectionSettings(address);
// Create settings to address device
settings.BusSpeed = I2cBusSpeed.FastMode;
settings.SharingMode = I2cSharingMode.Exclusive;
if (i2cID == null)
throw new IOException("Failed to find I2C controller matching " +
I2C_CONTROLLER);
return await I2cDevice.FromIdAsync(i2cID, settings);
}
开发者ID:Scorillo47,项目名称:hab,代码行数:17,代码来源:MainPage.xaml.cs
示例18: Init
public virtual async Task Init(int n=0)
{
var i2CSettings = new I2cConnectionSettings(0x77)
{
BusSpeed = I2cBusSpeed.FastMode,
SharingMode = I2cSharingMode.Shared
};
var i2c1 = I2cDevice.GetDeviceSelector("I2C1");
var devices = await DeviceInformation.FindAllAsync(i2c1);
sensor = await I2cDevice.FromIdAsync(devices[n].Id, i2CSettings);
}
开发者ID:GoreMaria,项目名称:HackSamples,代码行数:11,代码来源:I2CDevice.cs
示例19: I2cDeviceBase
public I2cDeviceBase(int slaveAddress, I2cBusSpeed busSpeed = I2cBusSpeed.FastMode, I2cSharingMode sharingMode = I2cSharingMode.Shared, string i2cControllerName = RaspberryPiI2cControllerName)
{
// Initialize I2C device
Settings = new I2cConnectionSettings(slaveAddress)
{
BusSpeed = busSpeed,
SharingMode = sharingMode
};
deviceSelector = I2cDevice.GetDeviceSelector(i2cControllerName); /* Find the selector string for the I2C bus controller */
}
开发者ID:shaoyiwork,项目名称:IoTHelpers,代码行数:11,代码来源:I2cDeviceBase.cs
示例20: GetDevice
private async static Task<I2cDevice> GetDevice(int slaveAddress)
{
string deviceSelector = I2cDevice.GetDeviceSelector();
var deviceControllers = await DeviceInformation.FindAllAsync(deviceSelector);
if (deviceControllers.Count == 0) throw new InvalidOperationException("No i2c controller found.");
var i2cSettings = new I2cConnectionSettings(0x20);
i2cSettings.BusSpeed = I2cBusSpeed.FastMode;
var device = await I2cDevice.FromIdAsync(deviceControllers[0].Id, i2cSettings);
return device;
}
开发者ID:CaptainBart,项目名称:Windows.Devices.Gpio.Components,代码行数:11,代码来源:Mcp230xx.cs
注:本文中的Windows.Devices.I2c.I2cConnectionSettings类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论