private void WriteReg16Bit(RegAddr reg, ushort value) { Span <byte> valueArray = stackalloc byte[2]; BinaryPrimitives.WriteUInt16BigEndian(valueArray, value); WriteReg(reg, valueArray.ToArray()); }
private void WriteReg32Bit(RegAddr reg, UInt32 value) { Span <byte> valueArray = stackalloc byte[4]; BinaryPrimitives.WriteUInt32BigEndian(valueArray, value); WriteReg(reg, valueArray.ToArray()); }
private void WriteReg(RegAddr regAddr, byte[] values) { Thread.Sleep(1); Span <byte> regAddrBytes = stackalloc byte[2]; BinaryPrimitives.WriteUInt16BigEndian(regAddrBytes, (ushort)regAddr); this.i2CDevice.Write(regAddrBytes.ToArray().Concat(values).ToArray()); }
private byte[] ReadRegVariable(RegAddr regAddr, int n) { Thread.Sleep(1); Span <byte> outArray = stackalloc byte[n]; Span <byte> regAddrBytes = stackalloc byte[2]; BinaryPrimitives.WriteUInt16BigEndian(regAddrBytes, (ushort)regAddr); this.i2CDevice.WriteRead(regAddrBytes, outArray); return(outArray.ToArray()); }
private void WriteReg(RegAddr reg, byte value) { WriteReg(reg, new[] { value }); }
private UInt16 ReadReg16Bit(RegAddr regAddr) { return(BinaryPrimitives.ReadUInt16BigEndian(ReadRegVariable(regAddr, 2))); }
// Read an 8-bit register private byte ReadReg(RegAddr regAddr) { return(ReadRegVariable(regAddr, 1)[0]); }