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); } } }
private static int writePause = 5; // Mandatory after each Write transaction !!! public static ArrayList Scan(this I2CDevice device, ushort startAddress, ushort endAddress, int clockRate, int timeout) { ArrayList addresses = new ArrayList(); for (ushort address = startAddress; address <= endAddress; address++) { var ConfigSav = device.Config; device.Config = new I2CDevice.Configuration(address, clockRate); byte x = 0; var xActions = new I2CDevice.I2CTransaction[1]; xActions[0] = I2CDevice.CreateReadTransaction(new byte[1] { x }); int result = device.Execute(xActions, timeout); if (result != 0) { addresses.Add(address); } device.Config = ConfigSav; //Thread.Sleep(writePause); // Mandatory after each Write transaction !!! } return(addresses); }
/// <summary> /// Read array of bytes at specific register from the I2C slave device. /// </summary> /// <param name="config">I2C slave device configuration.</param> /// <param name="register">The register to read bytes from.</param> /// <param name="readBuffer">The array of bytes that will contain the data read from the device.</param> /// <param name="transactionTimeout">The amount of time the system will wait before resuming execution of the transaction.</param> public void ReadRegister(I2CDevice.Configuration config, byte register, byte[] readBuffer) { byte[] writeBuffer = { register }; // create an i2c write transaction to be sent to the device. I2CDevice.I2CTransaction[] transactions = new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(writeBuffer), I2CDevice.CreateReadTransaction(readBuffer) }; // the i2c data is sent here to the device. int transferred; lock (this.m_i2c) { this.m_i2c.Config = config; transferred = this.m_i2c.Execute(transactions, TransactionTimeout); } // make sure the data was sent. if (transferred != writeBuffer.Length + readBuffer.Length) { throw new IOException("Read Failed: " + transferred + "!=" + (writeBuffer.Length + readBuffer.Length)); } }
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); }
private void ConfigDevice() { if (device == null) { device = new I2CDevice(new I2CDevice.Configuration((ushort)(AddressBase + baseAddressOffset), EmxI2cClock)); xConfigAction = new I2CDevice.I2CTransaction[1]; xConfigAction[0] = I2CDevice.CreateWriteTransaction(configReg); xReadAction = new I2CDevice.I2CTransaction[1]; xReadAction[0] = I2CDevice.CreateReadTransaction(dataReg); } double[] lsbValues = new double[4] { 0.001, 0.00025, 0.0000625, 0.000015625 }; lsbVolts = lsbValues[(ushort)resolution]; countsMask = (1 << (12 + (int)resolution * 2)) - 1; maxValue = 1 << (11 + (int)resolution * 2); gainDivisor = Math.Pow(2.0, (double)gain); configReg[0] = (byte)((ushort)gain + ((ushort)resolution << 2) + ((ushort)conversionMode << 4) + ((ushort)channel << 5)); WriteConfigReg(); configDirty = false; }
public byte[] WriteRead(byte[] write, ushort length) { _device.Config = _configuration; var read = new byte[length]; I2CDevice.I2CTransaction[] transaction = { I2CDevice.CreateWriteTransaction(write), I2CDevice.CreateReadTransaction(read) }; var bytesTransferred = 0; var retryCount = 0; while (_device.Execute(transaction, _transactionTimeout) != (write.Length + read.Length)) { if (retryCount > 3) { throw new Exception("WriteRead: Retry count exceeded."); } retryCount++; } //while (bytesTransferred != (write.Length + read.Length)) //{ // if (retryCount > 3) // { // throw new Exception("WriteRead: Retry count exceeded."); // } // retryCount++; // bytesTransferred = _device.Execute(transaction, _transactionTimeout); //} return(read); }
static ArrayList FindDevices() { var deviceAddresses = new ArrayList(); for (ushort address = 0x48; address < 0x48 + 0x07; address++) { var device = new I2CDevice(new I2CDevice.Configuration(address, ClockRateKHz)); byte[] writeBuffer = { 0x00 }; byte[] readBuffer = new byte[2]; I2CDevice.I2CTransaction[] action = new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(writeBuffer) , I2CDevice.CreateReadTransaction(readBuffer) }; var transactionResult = device.Execute(action, transactionTimeout); if (transactionResult == 3) { deviceAddresses.Add(device.Config.Address); Debug.Print("Found device @" + device.Config.Address); } else { Debug.Print("No device found @" + device.Config.Address); } device.Dispose(); } return(deviceAddresses); }
/// <summary> /// Reads the raw counts from the ADC /// </summary> /// <param name="number">Number of bytes to read (four if 18-bit conversion else three) </param> /// <returns>Result of 12, 14, 16 or 18-bit conversion</returns> double dataReadRaw(byte number) { Int32 data = 0; byte[] inbuffer = new byte[number]; I2CDevice.I2CReadTransaction readTransaction = I2CDevice.CreateReadTransaction(inbuffer); I2CDevice.I2CTransaction[] xAction = new I2CDevice.I2CTransaction[] { readTransaction }; _i2cBus = new I2CDevice(_config); int transferred = _i2cBus.Execute(xAction, _transactionTimeOut); _i2cBus.Dispose(); if (transferred < inbuffer.Length) { throw new System.IO.IOException("Error i2cBus " + _sla); } else if ((inbuffer[number - 1] & 0x80) == 0) // End of conversion { if (_resolution == SampleRate.EighteenBits) { data = (((Int32)inbuffer[0]) << 16) + (((Int32)inbuffer[1]) << 8) + (Int32)inbuffer[2]; } else { data = (((Int32)inbuffer[0]) << 8) + (Int32)inbuffer[1]; } _endOfConversion = true; return(data &= _dataMask); } else { _endOfConversion = false; return(0); // return something } }
/// <summary> /// Reading temperature in desired format /// </summary> /// <param name="format"></param> /// <returns></returns> public override double ReadTemperature(TemperatureFormat format) { I2CDevice.I2CTransaction[] i2cTx = new I2CDevice.I2CTransaction[2]; byte[] register = new byte[1]; byte[] data = new byte[2]; register[0] = TEMPERATURE_REG_ADDR; i2cTx[0] = I2CDevice.CreateWriteTransaction(register); i2cTx[1] = I2CDevice.CreateReadTransaction(data); int result = i2cDevice.Execute(i2cTx, TIMEOUT); //converting 12-bit temperature to double int rawTemperature = (data[0] << 4) | (data[1] >> 4); double temperature = 0; if (register.Length + data.Length == result) { if ((rawTemperature & 0x0800) > 0) { rawTemperature = (rawTemperature ^ 0xffff) + 1; temperature = -1; } temperature *= rawTemperature * 0.0625f; } return(temperature + ((format == TemperatureFormat.KELVIN) ? 273.15 : 0.0)); }
public void SetupDevice() { relayPort = new OutputPort((Cpu.Pin) 21, false); relayPort.Write(true); var i2cConfig = new I2CDevice.Configuration(0x51, 400); i2cSensor = new I2CDevice(i2cConfig); var xwsaction = I2CDevice.CreateWriteTransaction(new byte[] { 0x01 }); var xrsaction = I2CDevice.CreateReadTransaction(new byte[8]); i2cSensor.Execute(new I2CDevice.I2CTransaction[] { xwsaction, xrsaction }, 100); var read = xrsaction.Buffer; var temperature = BitConverter.ToDouble(read, 0); var accelOrder = I2CDevice.CreateWriteTransaction(new byte[] { 0x02 }); var accelRead = I2CDevice.CreateReadTransaction(new byte[24]); i2cSensor.Execute(new I2CDevice.I2CTransaction[] { accelOrder, accelRead }, 100); var accelX = BitConverter.ToDouble(accelRead.Buffer, 0); var accelY = BitConverter.ToDouble(accelRead.Buffer, 8); var accelZ = BitConverter.ToDouble(accelRead.Buffer, 16); }
/// <summary> /// ''' Read one byte at the address /// ''' </summary> private static string ReadByte(int Address) { try { I2cBus.Device.Config = Configuration; var Data = new byte[1]; var xActions = new I2CDevice.I2CTransaction[1]; xActions[0] = I2CDevice.CreateWriteTransaction(new byte[] { HighByte(Address), LowByte(Address) }); Thread.Sleep(5); I2cBus.Device.Execute(xActions, 1000); xActions[0] = I2CDevice.CreateReadTransaction(Data); Thread.Sleep(5); I2cBus.Device.Execute(xActions, 1000); // Convert the byte to string return(Strings.ChrW(Data[0]).ToString()); } catch (Exception ex) { return("Error: ReadBtye " + ex.ToString()); } }
/// <summary> /// Reads an arbitrary RTC or RAM register /// </summary> /// <param name="address">Register address between 0x00 and 0x3f</param> /// <param name="length">The number of bytes to read</param> /// <returns>The value of the bytes read at the address</returns> public byte[] ReadRegister(byte address, int length = 1) { if (length < 1) { throw new ArgumentOutOfRangeException("length", "Must read at least 1 byte"); } if (address + length - 1 > DS1307_RAM_END_ADDRESS) { throw new ArgumentOutOfRangeException("Invalid register address"); } var buffer = new byte[length]; lock (clock) { clock.Config = config; // Read the RAM register @ the address var transaction = new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(new byte[] { address }), I2CDevice.CreateReadTransaction(buffer) }; if (clock.Execute(transaction, DS1307_I2C_TRANSACTION_TIMEOUT_MS) == 0) { throw new Exception("I2C transaction failed"); } } return(buffer); }
public double AcquisitionTemperature() { byte[] temp = new byte[2]; //Besoin de 2 octets double realtemp = 0.0; //15 chiffres de précision(virgule flottante) MyI2C.Config = Temperature; xActions = new I2CDevice.I2CTransaction[3]; //Création de 3 transactions byte[] commande1 = new byte[1] { 238 }; //Commande EE(Début de conversion) byte[] commande2 = new byte[1] { 170 }; //Commande AA(Lecture de la température) //Transactions xActions[0] = I2CDevice.CreateWriteTransaction(commande1); //Représente une transaction I2c qui écrit dans le dispositif adressé xActions[1] = I2CDevice.CreateWriteTransaction(commande2); xActions[2] = I2CDevice.CreateReadTransaction(temp); //Représente une transaction I2c qui lit le dispositif adressé MyI2C.Execute(xActions, 1000); //Accès au bus I2c avec un délai de 1sec realtemp = temp[0]; if (temp[1] != 0) //(opérateur d'inégalité) { realtemp = realtemp + 0.5; } return(realtemp); }
public static void Main() { // // Create a new I2C device for the TMP102 on address 0x48 with the clock // running at 50 KHz. // I2CDevice tmp102 = new I2CDevice(new I2CDevice.Configuration(0x48, 50)); // // Create a transaction to read two bytes of data from the TMP102 sensor. // byte[] buffer = new byte[2]; I2CDevice.I2CTransaction[] reading = new I2CDevice.I2CTransaction[1]; reading[0] = I2CDevice.CreateReadTransaction(buffer); while (true) { // // Read the temperature. // int bytesRead = tmp102.Execute(reading, 100); // // Convert the reading into Centigrade and Fahrenheit. // int sensorReading = ((buffer[0] << 4) | (buffer[1]) >> 4); double centigrade = sensorReading * 0.0625; double fahrenheit = centigrade * 1.8 + 32; // // Display the readings in the debug window and pause before repeating. // Debug.Print(centigrade.ToString() + " C / " + fahrenheit.ToString() + " F"); Thread.Sleep(1000); } }
/// <summary> /// Generic read operation from I2C slave device. /// </summary> /// <param name="config">I2C slave device configuration.</param> /// <param name="readBuffer">The array of bytes that will contain the data read from the device.</param> /// <param name="transactionTimeout">The amount of time the system will wait before resuming execution of the transaction.</param> public int Read(I2CDevice.Configuration config, byte[] readBuffer, int transactionTimeout) { lock (_slaveDevice) { // Set i2c device configuration. _slaveDevice.Config = config; // create an i2c read transaction to be sent to the device. I2CDevice.I2CTransaction[] readXAction = new I2CDevice.I2CTransaction[] { I2CDevice.CreateReadTransaction(readBuffer) }; // the i2c data is received here from the device. int transferred = _slaveDevice.Execute(readXAction, transactionTimeout); // make sure the data was received. if (transferred != readBuffer.Length) { throw new Exception("Could not read from device."); } return(transferred); } }
public void Read() { I2CDevice MyI2C = new I2CDevice(i2con); //create transactions (we need 2 in this example) I2CDevice.I2CTransaction[] readActions = new I2CDevice.I2CTransaction[2]; // create write buffer (we need one byte) byte[] RegisterNum = new byte[1] { 2 }; readActions[0] = I2CDevice.CreateWriteTransaction(RegisterNum); // create read buffer to read the register byte[] RegisterValue = new byte[1]; readActions[1] = I2CDevice.CreateReadTransaction(RegisterValue); // Now we access the I2C bus and timeout in one second if no responce MyI2C.Execute(readActions, 1000); if (currentValue != RegisterValue[0]) { currentValue = RegisterValue[0]; if (OnChange != null) { OnChange(dialId, currentValue); } } MyI2C.Dispose(); //Debug.Print("Register value: " + RegisterValue[0].ToString()); }
private const byte RegisterDeviceId = 0xE5; // public static void Main() { using (I2CDevice device = new I2CDevice(new I2CDevice.Configuration(I2CAddressDefault, ClockRateKHz))) { byte[] writeBuffer = { RegisterDevice }; byte[] readBuffer = new byte[1]; // check that the ADXL345 sensor connected I2CDevice.I2CTransaction[] action = new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(writeBuffer), I2CDevice.CreateReadTransaction(readBuffer) }; if (device.Execute(action, TransactionTimeoutMilliseconds) != 0) { Debug.Print("DeviceId read success"); } else { Debug.Print("DeviceId read failure"); } if (readBuffer[0] == RegisterDeviceId) { Debug.Print("DeviceId correct"); } else { Debug.Print("DeviceId incorrect"); } } }
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 !!! }
/// <summary> /// Receive data back from the nunchuck, /// returns 1 on successful read. returns 0 on failure /// </summary> public bool GetData() { if (_isDisposed) { throw new ObjectDisposedException(); } if (!IsConnected) { Init(InitTimeout); return(false); } // send request for data WriteToDevice(0x00); // get the data byte[] inputBuffer = new byte[6]; var readTransaction = I2CDevice.CreateReadTransaction(inputBuffer); // execute both transactions int tranferred = _device.Execute(new I2CDevice.I2CTransaction[] { readTransaction }, TransactionTimeout); // less then 6 bytes read? if (tranferred != inputBuffer.Length) { // communication error, no need to reinitialize return(false); } if (!_disableEncryption) { // decrypt data in buffer for (int i = 0; i < 6; i++) { inputBuffer[i] = DecodeByte(inputBuffer[i]); } } // check if all 0xff read? byte cnt = 0; for (int i = 0; i < inputBuffer.Length; i++) { if (inputBuffer[i] == 0xff) { cnt++; } } if (cnt == inputBuffer.Length) { // this is connection error. _isConnected = false; return(false); } ExtractData(inputBuffer); return(true); }
public byte[] readI2CRegister(int addr) { Debug.Print("Attempting to read I2C register " + addr.ToString("X2")); i2cDevice.Config = i2cReadConfig; byte Addr = (byte)(addr & 0x00FF); byte[] buffer = new byte[1]; I2CDevice.I2CTransaction[] reading = new I2CDevice.I2CTransaction[2]; reading[0] = I2CDevice.CreateWriteTransaction(new byte[] { Addr }); reading[1] = I2CDevice.CreateReadTransaction(buffer); Debug.Print("Executing read transaction..."); int bytesRead = i2cDevice.Execute(reading, 100); if (bytesRead == 0) { throw new NullReferenceException("0 bytes read for i2c register " + addr.ToString("X2")); } string message = "Read I2c " + addr.ToString("X2") + ":"; for (int index = 0; index < buffer.Length; index++) { message += " " + buffer[index].ToString("X2"); } Debug.Print("Transaction complete, reading " + buffer.Length + " bytes"); Debug.Print(message); return(buffer); }
public int WriteRead(byte[] writeBuffer, ref byte[] readBuffer) { I2CDevice.I2CTransaction[] xaction = new I2CDevice.I2CTransaction[2]; xaction[0] = I2CDevice.CreateWriteTransaction(writeBuffer); xaction[1] = I2CDevice.CreateReadTransaction(readBuffer); return(_device.Execute(xaction, _timeout)); }
/// <summary> /// Reads all the settings. /// </summary> /// <remarks>Reads all the settings from the FT5306</remarks> public void ReadSettings(byte StartAddr) { I2CDevice.I2CTransaction[] _readActions2 = new I2CDevice.I2CTransaction[12]; I2CDevice.I2CReadTransaction readAction2; I2CDevice.I2CWriteTransaction writeAction2; byte[] _registerValues2 = new byte[10]; byte dummy; writeAction2 = I2CDevice.CreateWriteTransaction(new byte[1] { StartAddr }); readAction2 = I2CDevice.CreateReadTransaction(_registerValues2); _readActions2 = new I2CDevice.I2CTransaction[] { writeAction2, readAction2 }; lock (_sharedBus) { _sharedBus.Config = _busConfiguration; if (_sharedBus.Execute(_readActions2, 500) == 0) { Debug.Print("Failed to perform I2C transaction"); } } dummy = _registerValues2[0]; }
/// <summary> /// Scan range of addresses and print devices to debug output. /// </summary> /// <param name="startAddress">Start of scanning (included)</param> /// <param name="endAddress">End of scanning (included)</param> /// <param name="clockRateKhz">frequency in Khz</param> public static void ScanAddresses(ushort startAddress, ushort endAddress, ushort clockRateKhz = 100) { Debug.Print("Scanning..."); for (ushort adr = startAddress; adr <= endAddress; adr++) { I2CDevice device = new I2CDevice(new I2CDevice.Configuration(adr, clockRateKhz)); byte[] buff = new byte[1]; try { I2CDevice.I2CReadTransaction read = I2CDevice.CreateReadTransaction(buff); var ret = device.Execute(new I2CDevice.I2CTransaction[] { read }, 1000); if (ret > 0) { Debug.Print("Device on address: " + adr); } else { Debug.Print("NO: " + adr); } } catch (Exception) { continue; } finally { //otestovat yda se dela pokazde device.Dispose(); device = null; } } Debug.Print("Scanning finished."); }
/// /// Reads an arbitrary RTC or RAM register /// /// Register address between 0x00 and 0x3f /// The value of the byte read at the address public byte this[byte address] { get { if (address > DS1307_RAM_END_ADDRESS) { throw new ArgumentOutOfRangeException("Invalid register address"); } var value = new byte[1]; // Read the RAM register @ the address var transaction = new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(new byte[] { address }), I2CDevice.CreateReadTransaction(value) }; if (clock.Execute(transaction, DS1307_I2C_TRANSACTION_TIMEOUT_MS) == 0) { throw new Exception("I2C transaction failed"); } return(value[0]); } }
public BlinkMCommand(String name, char command, int argCount, int retValCount, int postExecuteDelayMillis = 0) { _postExecuteDelayMillis = postExecuteDelayMillis; _name = name; _command = command; _argCount = argCount; _retValCount = retValCount; _args = new byte[_argCount + 1]; _args[0] = (byte)_command; _retVals = new byte[_retValCount]; _transactions = new I2CDevice.I2CTransaction[_retValCount == 0 ? 1 : 2]; _transactions[0] = I2CDevice.CreateWriteTransaction(_args); if (_retValCount > 0) { _transactions[1] = I2CDevice.CreateReadTransaction(_retVals); } _expectedBytesTransferred = _args.Length + _retVals.Length; _flushTransaction = new I2CDevice.I2CTransaction[] { I2CDevice.CreateReadTransaction(_flushBuffer) }; }
public SiliconLabsSI7005() { using (I2CDevice device = new I2CDevice(new I2CDevice.Configuration(DeviceId, ClockRateKHz))) { byte[] writeBuffer = { RegisterIdDeviceId }; byte[] readBuffer = new byte[1]; // check that sensor connected I2CDevice.I2CTransaction[] action = new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(writeBuffer), I2CDevice.CreateReadTransaction(readBuffer) }; if (device.Execute(action, TransactionTimeoutMilliseconds) == 0) { // The first read always fails } if (device.Execute(action, TransactionTimeoutMilliseconds) == 0) { throw new Exception("Unable to read DeviceId"); } if (readBuffer[0] != RegisterDeviceId) { throw new Exception("DeviceId invalid"); } } }
//I2C read function that takes the address, and buffer, and returns amount of transactions private static int I2CRead(byte Address, byte[] Data) { ReadCommand = new I2CDevice.I2CTransaction[2]; ReadCommand[0] = I2CDevice.CreateWriteTransaction(new byte[] { Address }); ReadCommand[1] = I2CDevice.CreateReadTransaction(Data); ReadCheck = MyI2C.Execute(ReadCommand, 100); return(ReadCheck); }
/// <summary> /// Writes an array of 8-bit bytes to the interface, and reads an array of 8-bit bytes from the interface. /// </summary> /// <param name="WriteBuffer">An array with 8-bit bytes to write</param> /// <param name="ReadBuffer">An array with 8-bit bytes to read</param> /// <returns>The amount of transferred bytes</returns> public int WriteRead(byte[] WriteBuffer, byte[] ReadBuffer) { _I2CDevice.Config = this._Configuration; return(_I2CDevice.Execute(new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(WriteBuffer), I2CDevice.CreateReadTransaction(ReadBuffer) }, this.Timeout)); }
private static byte[] Read(int responseLength) { var buffer = new byte[responseLength]; var actions = new I2CDevice.I2CTransaction[1]; actions[0] = I2CDevice.CreateReadTransaction(buffer); Hardware.I2CBus.Execute(_i2CConfiguration, actions, _i2CTimeOut); return(buffer); }
/// <summary> /// 指定アドレスを起点として複数バイトデータを取得する /// </summary> /// <param name="reg">データ取得対象の先頭アドレス</param> /// <param name="data">取得データ</param> protected void RegReads(byte reg, ref byte[] data) { _adata[0] = reg; _trRegRead = new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(_adata), I2CDevice.CreateReadTransaction(data) }; _i2C.Execute(_trRegRead, _timeout); }