private float ReadCapSen1_1(byte[] RegAddrBuf1, byte[] RegAddrBuf2) { byte[] ReadBuf1, ReadBuf2; ReadBuf1 = new byte[2]; /* We read 2 bytes sequentially */ ReadBuf2 = new byte[2]; /* We read 2 bytes sequentially */ I2CSensor.WriteRead(RegAddrBuf1, ReadBuf1); I2CSensor.WriteRead(RegAddrBuf2, ReadBuf2); /* In order to get the raw 16-bit data values, we need to separate the bytes */ int RawData = BitConverter.ToInt16(ReadBuf1, 0); //int RawData = BitConverter.ToInt16(ReadBuf, 0); CapMeasure capMeas1_1; capMeas1_1.CapReadLSB1_1 = (0xFF00 & RawData) >> 8; capMeas1_1.CapreadMSB1_1 = 0x00FF & RawData; /* In order to get the raw 16-bit data values, we need to separate the bytes */ RawData = BitConverter.ToInt16(ReadBuf2, 0); capMeas1_1.CapReadLSB1_2 = (0xFF00 & RawData) >> 8; capMeas1_1.CapreadMSB1_2 = 0x00FF & RawData; int CapLabel1_1 = (capMeas1_1.CapreadMSB1_1 * 256 + capMeas1_1.CapReadLSB1_1); int CapLabel1_2 = capMeas1_1.CapreadMSB1_2 * 256 + capMeas1_1.CapReadLSB1_2; int CapLabel1Both = (CapLabel1_1 * 256 + capMeas1_1.CapreadMSB1_2); float FinalCapMeasure = CapLabel1Both / 524288; return(FinalCapMeasure); }
private OneRegisterRead ReadOneReg(byte[] RegAddrBuf) { byte[] ReadBuf; ReadBuf = new byte[2]; // need to read the two bytes stored in the targeted register I2CSensor.WriteRead(RegAddrBuf, ReadBuf); // A little confusing but decided to parse the two bytes into separate bytes, convert to 'int' // then return this information so we can perform calculations. int RawData = BitConverter.ToInt16(ReadBuf, 0); OneRegisterRead OneRegReadDataOut; OneRegReadDataOut.DataMSB = 0xFF00 & RawData >> 8; OneRegReadDataOut.DataLSB = 0x00FF & RawData; // if reading Done bit, use this statement ==> ((byte)(0x08 & RawData) >> 3) return(OneRegReadDataOut); }