Esempio n. 1
0
        protected byte[] Handle(I2cQuery query)
        {
            var address    = query.Address;
            var bufferSize = query.BufferSize;

            byte[] initializeWrite = null;

            if (query.ContainsProperty(MessageProperties.Initialize))
            {
                initializeWrite = query.Initialize;
            }

            try
            {
                var result = new byte[bufferSize];
                if (initializeWrite != null)
                {
                    _nativeI2CBus.WriteRead(address, initializeWrite, result);
                }
                else
                {
                    _nativeI2CBus.Read(address, result);
                }

                return(result);
            }
            catch (Exception exception)
            {
                Logger.LogWarning(exception, $"Error while accessing I2C device with address {address}. {exception.Message}");
                return(Array.Empty <byte>());
            }
        }
Esempio n. 2
0
        private async Task <byte[]> ReadFromBus()
        {
            var query  = I2cQuery.Create(_i2cAddress, _driver.GetReadTable(), _driver.BufferSize);
            var result = await MessageBroker.QueryService <I2cQuery, byte[]>(query);

            return(result);
        }