Method: I2C::Dev#read

Defined in:
lib/i2c/backends/i2c-dev.rb

#read(address, size, *params) ⇒ Object

this tries to lock the coms mutex (unless already held), then sends *params, if given, and then tries to read size bytes. The result is a String which can be treated with String#unpack afterwards



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/i2c/backends/i2c-dev.rb', line 49

def read(address, size, *params)
	if(@comsMutex.owned?)
		keepLock = true;
	else
		@comsMutex.lock;
	end

	begin
		setup_device(address);
		raw_write(params) unless params.empty?
		result = raw_read(size);
	ensure
		@comsMutex.unlock() unless keepLock;
		return result;
	end
end