Class: ADAM6050::Handler::Read

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

Overview

Allows registed senders to read the state.

From the manual:

Name        Read Channel Status
Description This command requests that the specified ADAM-6000 module
            return the status of its digital input channels.
Syntax      #01C\r
Response    !0100(data)(data)(data)(data)\r
            (data) a 2-character hexadecimal value representing the
            values of the digital input module.

TODO: The manual clearly states that onlyt the status of the input

channels should be included in the response. There are however
examples out there that also include the output.

Constant Summary collapse

MESSAGE_PREAMBLE =

Returns see Handler::MESSAGE_PREAMBLE.

Returns:

  • (String)

    see Handler::MESSAGE_PREAMBLE.

'$016'

Instance Method Summary collapse

Methods included from ADAM6050::Handler

#handles?, #validate?

Instance Method Details

#handle(_, state) ⇒ Integer, String

Parameters:

  • state (Integer)

    the current state.

Returns:

  • (Integer)

    the next state (always unchanged).

  • (String)

    the reply.



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

def handle(_, state, *)
  # From the manual:
  #   The first 2-character portion of the response (exclude the "!"
  #   character) indicates the address of the ADAM-6000 module. The second
  #   2-character portion of the response is reserved, and will always be
  #   00 currently.
  [state, '!0100' + State.to_bin(state)]
end