Beispiel #1
0
        private void WriteReg16Bit(RegAddr reg, ushort value)
        {
            Span <byte> valueArray = stackalloc byte[2];

            BinaryPrimitives.WriteUInt16BigEndian(valueArray, value);

            WriteReg(reg, valueArray.ToArray());
        }
Beispiel #2
0
        private void WriteReg32Bit(RegAddr reg, UInt32 value)
        {
            Span <byte> valueArray = stackalloc byte[4];

            BinaryPrimitives.WriteUInt32BigEndian(valueArray, value);

            WriteReg(reg, valueArray.ToArray());
        }
Beispiel #3
0
        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());
        }
Beispiel #4
0
        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());
        }
Beispiel #5
0
 private void WriteReg(RegAddr reg, byte value)
 {
     WriteReg(reg, new[] { value });
 }
Beispiel #6
0
 private UInt16 ReadReg16Bit(RegAddr regAddr)
 {
     return(BinaryPrimitives.ReadUInt16BigEndian(ReadRegVariable(regAddr, 2)));
 }
Beispiel #7
0
 // Read an 8-bit register
 private byte ReadReg(RegAddr regAddr)
 {
     return(ReadRegVariable(regAddr, 1)[0]);
 }