本文整理汇总了C#中Windows.Devices.I2c.I2cDevice类的典型用法代码示例。如果您正苦于以下问题:C# I2cDevice类的具体用法?C# I2cDevice怎么用?C# I2cDevice使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
I2cDevice类属于Windows.Devices.I2c命名空间,在下文中一共展示了I2cDevice类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Execute
public override void Execute(I2cDevice i2CDevice)
{
i2CDevice.Write(GenerateRegisterSensorPackage());
byte[] buffer = new byte[9];
i2CDevice.Read(buffer);
ParseResponse(buffer);
}
开发者ID:rishabhbanga,项目名称:CK.HomeAutomation,代码行数:9,代码来源:ReadDHT22SensorCommand.cs
示例2: Write
public static bool Write(I2cDevice device, byte reg, byte command)
{
byte[] val = new byte[2];
val[0] = reg;
val[1] = command;
try {
device.Write(val);
return true;
} catch {
return false;
}
}
开发者ID:emmellsoft,项目名称:RTIMULibCS,代码行数:13,代码来源:RTI2C.cs
示例3: Write
public static void Write(I2cDevice device, byte reg, byte command, string exceptionMessage)
{
try
{
byte[] buffer = { reg, command };
device.Write(buffer);
}
catch (Exception exception)
{
throw new SensorException(exceptionMessage, exception);
}
}
开发者ID:harshatech2012,项目名称:RPi.SenseHat,代码行数:13,代码来源:I2CSupport.cs
示例4: 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
示例5: GPSFetch
/// <summary>
/// Displays the GPS data on the screen.
/// </summary>
/// <param name="device">The I2C device</param>
/// <param name="index">0 for Venus, 1 for Copernicus</param>
/// <param name="display">An array containing 4 text boxes - lat, lon, alt, vel</param>
private void GPSFetch(I2cDevice device, int index, params TextBlock[] display) {
byte[] data = new byte[17];
// Receive 17 bytes starting from lat register (0x10), where 0x30 is the second GPS
byte address = (byte)(((index == 0) ? 0x00 : 0x20) + 0x10);
device.WriteRead(new byte[] { address }, data);
// Convert all to correct types
double lat = BitConverter.ToInt32(data, 0) * 1E-6;
double lon = BitConverter.ToInt32(data, 4) * 1E-6;
double vel = BitConverter.ToInt16(data, 8) * 1E-1;
double head = BitConverter.ToInt16(data, 10) * 1E-1;
double alt = BitConverter.ToInt32(data, 12) * 1E-2;
int satellites = (int)data[16];
// Write to the screen
if (satellites > 0) {
display[0].Text = lat.ToString("F6");
display[1].Text = lon.ToString("F6");
display[2].Text = alt.ToString("F1");
display[3].Text = vel.ToString("F1");
} else {
display[0].Text = "NO FIX";
display[1].Text = satellites.ToString();
display[2].Text = "";
display[3].Text = "";
}
}
开发者ID:Scorillo47,项目名称:hab,代码行数:31,代码来源:MainPage.xaml.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: 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
示例8: 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
示例9: 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
示例10: Read16Bits
public static UInt16 Read16Bits(I2cDevice device, byte reg, ByteOrder byteOrder, string exceptionMessage)
{
try
{
byte[] addr = { reg };
byte[] data = new byte[2];
device.WriteRead(addr, data);
switch (byteOrder)
{
case ByteOrder.BigEndian:
return (UInt16)((data[0] << 8) | data[1]);
case ByteOrder.LittleEndian:
return (UInt16)((data[1] << 8) | data[0]);
default:
throw new SensorException($"Unsupported byte order {byteOrder}");
}
}
catch (Exception exception)
{
throw new SensorException(exceptionMessage, exception);
}
}
开发者ID:harshatech2012,项目名称:RPi.SenseHat,代码行数:27,代码来源:I2CSupport.cs
示例11: 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
示例12: GoPiGo
internal GoPiGo(I2cDevice device)
{
if (device == null) throw new ArgumentNullException(nameof(device));
DirectAccess = device;
_motorController = new MotorController(this);
_encoderController = new EncoderController(this);
}
开发者ID:adamphillips,项目名称:GoPiGo,代码行数:7,代码来源:GoPiGo.cs
示例13: InitializeAsync
public async Task InitializeAsync()
{
var dis = await DeviceInformation.FindAllAsync(deviceSelector); /* Find the I2C bus controller device with our selector string */
Device = await I2cDevice.FromIdAsync(dis[0].Id, Settings); /* Create an I2cDevice with our selected bus controller and I2C settings */
await InitializeSensorAsync();
}
开发者ID:shaoyiwork,项目名称:IoTHelpers,代码行数:7,代码来源:I2cDeviceBase.cs
示例14: 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
示例15: RgbLcdDisplay
internal RgbLcdDisplay(I2cDevice rgbDevice, I2cDevice textDevice)
{
if (rgbDevice == null) throw new ArgumentNullException(nameof(rgbDevice));
if (textDevice == null) throw new ArgumentNullException(nameof(textDevice));
RgbDirectAccess = rgbDevice;
TextDirectAccess = textDevice;
}
开发者ID:Seeed-Studio,项目名称:GrovePiExamples_win10,代码行数:8,代码来源:RgbLcdDisplay.cs
示例16: InitPyGlow
private void InitPyGlow(I2cDevice device)
{
device.Write(new byte[] { 0x00, 0x01 });
device.Write(new byte[] { 0x13, 0xFF });
device.Write(new byte[] { 0x14, 0xFF });
device.Write(new byte[] { 0x15, 0xFF });
ClearLeds(device);
}
开发者ID:TigerLeep,项目名称:Windows.10.IoT.Raspberry.Pi.Playground,代码行数:8,代码来源:MainPage.xaml.cs
示例17: MMA8453
public MMA8453(I2cDevice device) {
this.device = device;
this.write = new byte[1] { 0x01 };
this.read = new byte[6];
this.disposed = false;
this.device.Write(new byte[] { 0x2A, 0x01 });
}
开发者ID:amykatenicho,项目名称:IoTWorkshop,代码行数:8,代码来源:MMA8453.cs
示例18: SSD1603Controller
//constructor
public SSD1603Controller(I2cDevice device, GpioPin pinReset = null)
{
_busType = BusTypes.I2C;
_i2cDevic = device;
_pinReset = pinReset;
Empty();
Debug.WriteLine(string.Format("SSD1603 controller on {0} created", _busType));
}
开发者ID:q-life,项目名称:Q.IoT,代码行数:9,代码来源:SSD1603Controller.cs
示例19: Mb85rcvDevice
protected Mb85rcvDevice(I2cDevice device, int size)
{
// Validate
if (device == null) throw new ArgumentNullException(nameof(device));
// Initialize members
Hardware = device;
Size = size;
}
开发者ID:emlid,项目名称:Navio-SDK-Windows-IoT,代码行数:9,代码来源:Mb85rcvDevice.cs
示例20: Read
public static bool Read(I2cDevice device, byte reg, byte[] data)
{
byte[] addr = new byte[1];
addr[0] = reg;
try {
device.WriteRead(addr, data);
return true;
} catch {
return false;
}
}
开发者ID:emmellsoft,项目名称:RTIMULibCS,代码行数:11,代码来源:RTI2C.cs
注:本文中的Windows.Devices.I2c.I2cDevice类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论