Method: I2C::Dev#write
- Defined in:
- lib/i2c/backends/i2c-dev.rb
#write(address, *params) ⇒ Object
this tries to lock the coms mutex, unless already held, then sends every param, begining with params[0] If the current param is a Fixnum, it is treated as one byte. If the param is a String, this string will be sent byte by byte. You can use Array#pack to create a string from an array For Fixnum there is a convenient function to_short which transforms the number to a string this way: 12345.to_short == [12345].pack(“s”)
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/i2c/backends/i2c-dev.rb', line 30 def write(address, *params) if(@comsMutex.owned?) keepLock = true; else @comsMutex.lock; end begin setup_device(address); raw_write(params); ensure @comsMutex.unlock() unless keepLock; end end |