本文整理汇总了C#中Microsoft.SPOT.Hardware.I2CDevice.I2CTransaction类的典型用法代码示例。如果您正苦于以下问题:C# I2CDevice.I2CTransaction类的具体用法?C# I2CDevice.I2CTransaction怎么用?C# I2CDevice.I2CTransaction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
I2CDevice.I2CTransaction类属于Microsoft.SPOT.Hardware命名空间,在下文中一共展示了I2CDevice.I2CTransaction类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: SiliconLabsSI7005
public SiliconLabsSI7005(byte deviceId = DeviceIdDefault, int clockRateKHz = ClockRateKHzDefault, int transactionTimeoutmSec = TransactionTimeoutmSecDefault)
{
this.deviceId = deviceId;
this.clockRateKHz = clockRateKHz;
this.transactionTimeoutmSec = transactionTimeoutmSec;
using (OutputPort i2cPort = new OutputPort(Pins.GPIO_PIN_SDA, true))
{
i2cPort.Write(false);
Thread.Sleep(250);
}
using (I2CDevice device = new I2CDevice(new I2CDevice.Configuration(deviceId, clockRateKHz)))
{
byte[] writeBuffer = { RegisterIdDeviceId };
byte[] readBuffer = new byte[1];
// The first request always fails
I2CDevice.I2CTransaction[] action = new I2CDevice.I2CTransaction[]
{
I2CDevice.CreateWriteTransaction(writeBuffer),
I2CDevice.CreateReadTransaction(readBuffer)
};
if( device.Execute(action, transactionTimeoutmSec) == 0 )
{
// throw new ApplicationException("Unable to send get device id command");
}
}
}
开发者ID:CanterburyRegionalCouncil,项目名称:AirQualityMonitoringDevice,代码行数:30,代码来源:SiliconLabsSI7005.cs
示例2: Main
public static void Main()
{
//our 10 bit address
const ushort address10Bit = 0x1001; //binary 1000000001 = 129
const byte addressMask = 0x78; //reserved address mask 011110XX for 10 bit addressing
//first MSB part of address
ushort address1 = addressMask | (address10Bit >> 8); //is 7A and contains the two MSB of the 10 bit address
I2CDevice.Configuration config = new I2CDevice.Configuration(address1, 100);
I2CDevice device = new I2CDevice(config);
//second LSB part of address
byte address2 = (byte)(address10Bit & 0xFF); //the other 8 bits (LSB)
byte[] address2OutBuffer = new byte[] { address2 };
I2CDevice.I2CWriteTransaction addressWriteTransaction = device.CreateWriteTransaction(address2OutBuffer);
//prepare buffer to write data
byte[] outBuffer = new byte[] { 0xAA };
I2CDevice.I2CWriteTransaction writeTransaction = device.CreateWriteTransaction(outBuffer);
//prepare buffer to read data
byte[] inBuffer = new byte[4];
I2CDevice.I2CReadTransaction readTransaction = device.CreateReadTransaction(inBuffer);
//execute transactions
I2CDevice.I2CTransaction[] transactions =
new I2CDevice.I2CTransaction[] { addressWriteTransaction, writeTransaction, readTransaction };
device.Execute(transactions, 100);
}
开发者ID:meikeric,项目名称:DotCopter,代码行数:29,代码来源:Program.cs
示例3: ReadValue
public double ReadValue()
{
double temp;
byte[] inBuffer = new byte[2];
I2CDevice.I2CReadTransaction readTransaction = I2CDevice.CreateReadTransaction(inBuffer);
//execute both transactions
I2CDevice.I2CTransaction[] transactions =
new I2CDevice.I2CTransaction[] { readTransaction };
int transferred = device.Execute(transactions,
100 //timeout in ms
);
// The value is now converted
temp = (float)(inBuffer[0] << 1) / 2;
if ((inBuffer[1] >> 7) != 0)
temp += (float)0.5;
if ((inBuffer[0] >> 7) != 0)
temp = -temp;
Thread.Sleep(1000);
return temp;
}
开发者ID:apalayret,项目名称:IHA_Project_North_Pole,代码行数:25,代码来源:TemperatureMeter.cs
示例4: Init
/// <summary>
/// Turns on the Oscillator. Turns on the Display. Turns off Blinking. Sets Brightness to full.
/// </summary>
public void Init()
{
Config = new I2CDevice.Configuration(HT16K33_ADRESS, HT16K33_CLKRATE);
Matrix = new I2CDevice(Config);
byte[] write = new byte[1];
write[0] = HT16K33_OSC_ON; // IC Oscillator ON
byte[] write2 = new byte[1];
write2[0] = HT16K33_DISPLAY_ON; // Display ON
I2CDevice.I2CTransaction[] i2cTx = new I2CDevice.I2CTransaction[1];
i2cTx[0] = I2CDevice.CreateWriteTransaction(write);
I2CDevice.I2CTransaction[] i2cTx2 = new I2CDevice.I2CTransaction[1];
i2cTx2[0] = I2CDevice.CreateWriteTransaction(write2);
Matrix.Execute(i2cTx, Timeout);
Matrix.Execute(i2cTx2, Timeout);
// initialize DisplayBuffer
for (int i = 0; i < 8; i++)
{
DisplayBuffer[i] = 0x00;
}
}
开发者ID:MichaelCastano,项目名称:netmf.MC.LEDBackpack,代码行数:29,代码来源:Matrix_8x8.cs
示例5: Read
public void Read(I2CDevice.Configuration config, byte[] buffer, int transactionTimeout)
{
_slaveDevice.Config = config;
I2CDevice.I2CTransaction[] i2CTransactions = new I2CDevice.I2CTransaction[] { I2CDevice.CreateReadTransaction(buffer) };
lock (_slaveDevice)
_slaveDevice.Execute(i2CTransactions, transactionTimeout);
}
开发者ID:lukecummings,项目名称:DotCopter,代码行数:7,代码来源:I2CBus.cs
示例6: Sketch01
public static void Sketch01()
{
//create I2C object
//note that the netmf i2cdevice configuration requires a 7-bit address! It set the 8th R/W bit automatically.
I2CDevice.Configuration con =
new I2CDevice.Configuration(0x68, 100);
I2CDevice MyI2C = new I2CDevice(con);
// Create transactions
// We need 2 in this example, we are reading from the device
// First transaction is writing the "read command"
// Second transaction is reading the data
I2CDevice.I2CTransaction[] xActions =
new I2CDevice.I2CTransaction[2];
// create write buffer (we need one byte)
byte[] RegisterNum = new byte[1] { 0x14 };
xActions[0] = I2CDevice.CreateWriteTransaction(RegisterNum);
// create read buffer to read the register
byte[] RegisterValue = new byte[1];
xActions[1] = I2CDevice.CreateReadTransaction(RegisterValue);
// Now we access the I2C bus using a timeout of one second
// if the execute command returns zero, the transaction failed (this
// is a good check to make sure that you are communicating with the device correctly
// and don’t have a wiring issue or other problem with the I2C device)
if (MyI2C.Execute(xActions, 1000) == 0)
{
Debug.Print("Failed to perform I2C transaction");
}
else
{
Debug.Print("Register value: " + RegisterValue[0].ToString());
}
}
开发者ID:binary10,项目名称:Netduino,代码行数:35,代码来源:Test.cs
示例7: ds1624Thread
private void ds1624Thread()
{
I2CDevice.I2CTransaction[] cmdStartConversion = new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(new byte[] {0xEE}) };
I2CDevice.I2CTransaction[] cmdStartRead = new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(new byte[] { 0xAA }) };
byte[] temperatureData = new byte[2];
I2CDevice.I2CTransaction[] cmdRead = new I2CDevice.I2CTransaction[] { I2CDevice.CreateReadTransaction(temperatureData) };
while (runThread == true)
{
if (i2cDevice.Execute(cmdStartConversion, 100) == 0)
{
throw new Exception("i2c");
}
Thread.Sleep(1000);
if (i2cDevice.Execute(cmdStartRead, 100) == 0)
{
throw new Exception("i2c");
}
if (i2cDevice.Execute(cmdRead, 100) < 2)
{
throw new Exception("i2c");
}
else
{
this.lastTemperature = this.ConvertTemperature(temperatureData);
this.TemperatureEvent(this.LastTemperature);
}
}
}
开发者ID:adamlin1970,项目名称:NetmfSTM32,代码行数:32,代码来源:DS1624.cs
示例8: TSL2561
public TSL2561(byte I2CAddress, int ClockinKHz)
{
I2CConfig = new I2CDevice.Configuration(I2CAddress, ClockinKHz);
I2C = new I2CDevice(I2CConfig);
// read the ID register.
var Actions = new I2CDevice.I2CTransaction[2];
byte[] rx = new byte[1];
Actions[0] = I2CDevice.CreateWriteTransaction(new byte[] { 0x0a });
Actions[1] = I2CDevice.CreateReadTransaction(rx);
if (I2C.Execute(Actions, 1000) == 0)
{
Debug.Print("Read ID Register failed");
// exit or something
}
else
{
Debug.Print("ID value: " + rx[0].ToString());
}
// 4 msb must be 0001 for a TSL2561
if ((rx[0] & 0xf0) != 0xa0)
{
// exit or something
}
setGain(0x10);
Thread.Sleep(5); // Mandatory after each Write transaction !!!
}
开发者ID:rhekkers,项目名称:LuxPlugOnPanda,代码行数:28,代码来源:TSL2561.cs
示例9: GetVersion
public bool GetVersion(out byte majorVersion, out byte minorVersion)
{
var command = new byte[1];
command[0] = 0x00;
var writeAction = new I2CDevice.I2CTransaction[]
{
I2CDevice.CreateWriteTransaction(command),
};
i2c.Execute(writeAction, 1000);
var response = new byte[3];
var readAction = new I2CDevice.I2CTransaction[]
{
I2CDevice.CreateReadTransaction(response),
};
i2c.Execute(readAction, 1000);
if (response[0] != 0x80)
{
majorVersion = 0;
minorVersion = 0;
return false;
}
majorVersion = response[2];
minorVersion = response[1];
return true;
}
开发者ID:matsujirushi,项目名称:TextileSensorKit,代码行数:28,代码来源:MjTextileSensor.cs
示例10: GetChannel
/// <summary>
///
/// </summary>
/// <param name="channel"></param>
/// <returns></returns>
public int GetChannel(Channels channel)
{
//Odd high
//Even low
byte[] msb = new byte[]
{
(byte)((int)channel << 1)
};
byte[] lsb = new byte[]
{
(byte)(((int)channel << 1) + 1)
};
byte[] msbOut = new byte[1];
byte[] lsbOut = new byte[1];
I2CDevice.I2CTransaction[] transaction = new I2CDevice.I2CTransaction[]
{
I2CDevice.CreateWriteTransaction(msb),
I2CDevice.CreateReadTransaction(msbOut),
I2CDevice.CreateWriteTransaction(lsb),
I2CDevice.CreateReadTransaction(lsbOut),
};
int output = ((((int) msbOut[0]) << 8) | (lsbOut[0]));
return output;
}
开发者ID:wramsdell,项目名称:Netduino_Example,代码行数:35,代码来源:FpgaPpmReader.cs
示例11: clear
public void clear()
{
I2CDevice.I2CTransaction[] write = new I2CDevice.I2CTransaction[] {
I2CDevice.CreateWriteTransaction(new byte[] { 0x82 })
};
m_display.Execute(write, 1000);
}
开发者ID:akafugu,项目名称:twidisplay,代码行数:7,代码来源:TWIDisplay.cs
示例12: Write
void Write (byte[] writeBuffer)
{
Connect ();
// create a write transaction containing the bytes to be written to the device
var writeTransaction = new I2CDevice.I2CTransaction[] {
I2CDevice.CreateWriteTransaction(writeBuffer)
};
// write the data to the device
int written = this.i2cDevice.Execute (writeTransaction, TransactionTimeout);
while (written < writeBuffer.Length) {
byte[] newBuffer = new byte[writeBuffer.Length - written];
Array.Copy (writeBuffer, written, newBuffer, 0, newBuffer.Length);
writeTransaction = new I2CDevice.I2CTransaction[]
{
I2CDevice.CreateWriteTransaction(newBuffer)
};
written += this.i2cDevice.Execute (writeTransaction, TransactionTimeout);
}
// make sure the data was sent
if (written != writeBuffer.Length) {
throw new Exception ("Could not write to device.");
}
}
开发者ID:Roddoric,项目名称:Monkey.Robotics,代码行数:29,代码来源:I2CBlock.cs
示例13: Write
/// <summary>
/// Write to a I2C slave device.
/// </summary>
/// <param name="device">I2C slave device.</param>
/// <param name="writeBuffer">Bytes to be written to the slave.</param>
/// <param name="transactionTimeout">Time in mS the system will allow for a transaction.</param>
public void Write(I2CSlave device, byte[] writeBuffer, int transactionTimeout)
{
Device.Config = new I2CDevice.Configuration(device.Address, ClockRate);
I2CDevice.I2CTransaction[] writeTransaction = new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(writeBuffer) };
lock(Device)
if(Device.Execute(writeTransaction, transactionTimeout) != writeBuffer.Length)
throw new IOException("Could not write to slave.");
}
开发者ID:metroidprimedude,项目名称:ASEC-Robotics,代码行数:14,代码来源:I2C.cs
示例14: Read
/// <summary>
/// Read from a I2C slave device.
/// </summary>
/// <param name="device">I2C slave device.</param>
/// <param name="readBuffer">Bytes to be read from the slave.</param>
/// <param name="transactionTimeout">The amount of time the system will wait before resuming execution of the transaction.</param>
public void Read(I2CSlave device, byte[] readBuffer, int transactionTimeout)
{
Device.Config = new I2CDevice.Configuration(device.Address, ClockRate);
I2CDevice.I2CTransaction[] readTransaction = new I2CDevice.I2CTransaction[] { I2CDevice.CreateReadTransaction(readBuffer) };
lock(Device)
if(Device.Execute(readTransaction, transactionTimeout) != readBuffer.Length)
throw new IOException("Could not read from slave.");
}
开发者ID:metroidprimedude,项目名称:ASEC-Robotics,代码行数:14,代码来源:I2C.cs
示例15: changeAddress
// 0x81
public void changeAddress(uint new_addr)
{
if (new_addr > 255) return;
I2CDevice.I2CTransaction[] write = new I2CDevice.I2CTransaction[] {
I2CDevice.CreateWriteTransaction(new byte[] { 0x80, (byte)new_addr })
};
m_display.Execute(write, 1000);
}
开发者ID:akafugu,项目名称:twidisplay,代码行数:10,代码来源:TWIDisplay.cs
示例16: ReadRegister
public byte[] ReadRegister(I2CDevice.Configuration config, byte register, int timeout)
{
var registerValue = new byte[] { 0, 0 };
var xActions = new I2CDevice.I2CTransaction[2];
xActions[0] = I2CDevice.CreateWriteTransaction(new[] { register });
xActions[1] = I2CDevice.CreateReadTransaction(registerValue);
Transact(config, xActions, timeout);
return registerValue;
}
开发者ID:FlankPhi,项目名称:HomeAutomation,代码行数:11,代码来源:I2CBus.cs
示例17: GetData
public static byte GetData(I2CDevice FPGA, byte Port)
{
int I2CTimeout = 1000;
byte[] buffer = new byte[1];
var transaction = new I2CDevice.I2CTransaction[]
{
I2CDevice.CreateWriteTransaction(new byte[] {Port}),
I2CDevice.CreateReadTransaction(buffer)
};
FPGA.Execute(transaction, I2CTimeout);
return buffer[0];
}
开发者ID:wramsdell,项目名称:Netduino_Example,代码行数:12,代码来源:Program.cs
示例18: WriteRegister
public void WriteRegister(I2CDevice.Configuration config, byte register, byte[] buffer, int transactionTimeout)
{
_slaveDevice.Config = config;
I2CDevice.I2CTransaction[] i2CTransactions = new I2CDevice.I2CTransaction[]
{
I2CDevice.CreateWriteTransaction(new byte[] {register})
,
I2CDevice.CreateWriteTransaction(buffer)
};
lock (_slaveDevice)
_slaveDevice.Execute(i2CTransactions, transactionTimeout);
}
开发者ID:lukecummings,项目名称:DotCopter,代码行数:12,代码来源:I2CBus.cs
示例19: SetRedLED
public static void SetRedLED(I2CDevice FPGA, bool state)
{
int I2CTimeout = 1000;
byte[] buffer = new byte[2];
buffer[0] = 0x10;
buffer[1] = state ? (byte)0x01 : (byte)0x00;
var transaction = new I2CDevice.I2CTransaction[]
{
I2CDevice.CreateWriteTransaction(buffer)
};
FPGA.Execute(transaction, I2CTimeout);
}
开发者ID:wramsdell,项目名称:Netduino_Example,代码行数:12,代码来源:Program.cs
示例20: readValues
void readValues(I2CDevice adxl345, short[] result)
{
byte[] values = new byte[6];
I2CDevice.I2CTransaction[] xActions = new I2CDevice.I2CTransaction[2];
byte[] RegisterNum = new byte[1] { valuesRegister };
xActions[0] = adxl345.CreateWriteTransaction(RegisterNum);
xActions[1] = adxl345.CreateReadTransaction(values);
if (adxl345.Execute(xActions, 1000) == 0)
throw new Exception("Unable to read accelerometer");
result[0] = (short)(values[0] + (values[1] << 8));
result[1] = (short)(values[2] + (values[3] << 8));
result[2] = (short)(values[4] + (values[5] << 8));
}
开发者ID:jbuusao,项目名称:NETMF-Projects,代码行数:13,代码来源:Program.cs
注:本文中的Microsoft.SPOT.Hardware.I2CDevice.I2CTransaction类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论