internal byte ReadByte(byte address)
        {
            byte[] buffer = { address };
            byte[] value  = new byte[1];

            // _device.WriteRead(buffer, value);
            _device.Write(buffer);
            _device.Read(value);

            return(value[0]);
        }
Пример #2
0
        public static UInt32 Read24Bits(UnixI2cDevice device, byte reg, ByteOrder byteOrder, string exceptionMessage)
        {
            try
            {
                byte[] addr = { reg };

                byte[] data = new byte[3];

                // device.WriteRead(addr, data);
                device.Write(addr);
                device.Read(data);

                switch (byteOrder)
                {
                case ByteOrder.BigEndian:
                    return((UInt32)((data[0] << 16) | (data[1] << 8) | data[2]));

                case ByteOrder.LittleEndian:
                    return((UInt32)((data[2] << 16) | (data[1] << 8) | data[0]));

                default:
                    throw new SensorException($"Unsupported byte order {byteOrder}");
                }
            }
            catch (Exception exception)
            {
                throw new SensorException(exceptionMessage, exception);
            }
        }
Пример #3
0
        public static void Write(UnixI2cDevice device, byte reg, byte command, string exceptionMessage)
        {
            try
            {
                byte[] buffer = { reg, command };

                device.Write(buffer);
            }
            catch (Exception exception)
            {
                throw new SensorException(exceptionMessage, exception);
            }
        }
Пример #4
0
        public static byte Read8Bits(UnixI2cDevice device, byte reg, string exceptionMessage)
        {
            try
            {
                byte[] addr = { reg };

                byte[] data = new byte[1];

                // device.WriteRead(addr, data);
                device.Write(addr);
                device.Read(data);
                return(data[0]);
            }
            catch (Exception exception)
            {
                throw new SensorException(exceptionMessage, exception);
            }
        }