コード例 #1
0
        public override EEPROM_BUFFER ReadPage(int addr, int len = EEPROM_BASE_CLASS.DEFAULT_PAGE_SIZE)
        {
            var r = new EEPROM_BUFFER(len);

#if NUSBIO2
            var inBuffer = new List <byte>()
            {
                (byte)(addr >> 8), (byte)(addr & 0xFF)
            };
            r.Buffer    = new byte[len]; // Must pre allocate the buffer for now
            r.Succeeded = Nusbio2NAL.I2C_Helper_WriteRead(base.DeviceId, inBuffer.ToArray(), r.Buffer) == 1;
            return(r);
#else
#if OPTIMIZE_I2C_CALL
            // This method is faster because the I2C write and read operations are
            // combined in one USB buffer
            r.Succeeded = this._i2c.Send16BitsAddressAndReadBuffer(addr, len, r.Buffer);
#else
            // Slower method because we have one USB operation for the I2C write
            // and one USB operation for the I2C read
            // The transfer of the data per say is the same
            var tmpArray = new byte[2];
            if (this._i2c.WriteBuffer(new byte[2] {
                (byte)(addr >> 8), (byte)(addr & 0xFF)
            }))
            {
                r.Succeeded = this._i2c.ReadBuffer(len, r.Buffer);
            }
#endif
#endif
            return(r);
        }
コード例 #2
0
        bool Ii2cOut.i2c_WriteReadBuffer(byte[] writeBuffer, byte[] readBuffer)
        {
#if NUSBIO2
            var r = Nusbio2NAL.I2C_Helper_WriteRead(this.DeviceID, writeBuffer, readBuffer) == 1;
            return(r);
#else
            if (this._i2c.WriteBuffer(writeBuffer))
            {
                return(this._i2c.ReadBuffer(readBuffer.Length, readBuffer));
            }
            else
            {
                return(false);
            }
#endif
        }