Class: ADAM6050::Handler::Write

Inherits:
Object
  • Object
show all
Includes:
ADAM6050::Handler
Defined in:
lib/adam6050/handler/write.rb

Overview

Allows registed senders to change the output bits of the state.

From the manual:

Name        Write Digital Output
Description This command sets a single or all digital output channels to
            the specific ADAM-6000 module.
Syntax      #01bb(data)\r
            bb is used to indicate which channel(s) you want to set.
            Writing to all channels (write a byte): both characters
            should be equal to zero (BB=00).
            Writing to a single channel (write a bit): first character
            is 1, second character indicates channel number which can
            range from 0h to Fh.

Constant Summary collapse

MESSAGE_PREAMBLE =

Returns see Handler::MESSAGE_PREAMBLE.

Returns:

  • (String)

    see Handler::MESSAGE_PREAMBLE.

'#01'

Instance Method Summary collapse

Methods included from ADAM6050::Handler

#handles?, #validate?

Instance Method Details

#handle(msg, state) ⇒ Array<Integer, String>

Returns the next state and an optional reply.

Parameters:

  • msg (String)

    the incomming message.

  • state (Integer)

    the current state.

Returns:

  • (Array<Integer, String>)

    the next state and an optional reply.



27
28
29
30
31
32
33
34
35
36
# File 'lib/adam6050/handler/write.rb', line 27

def handle(msg, state, *)
  channel, value = parse msg
  next_state = if msg[3] == '1'
                 State.update state, channel, value
               else
                 State.update_all state, value
               end

  [next_state, '>']
end