Class: Smartware::SankyoConnection

Inherits:
CommandBasedDevice show all
Defined in:
lib/smartware/drivers/common/sankyo_connection.rb

Defined Under Namespace

Classes: CommandResponse

Constant Summary collapse

STX =
0xF2
ACK =
0x06
NAK =
0x15

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from CommandBasedDevice

#command, #receive_data

Constructor Details

#initializeSankyoConnection

Returns a new instance of SankyoConnection.



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/smartware/drivers/common/sankyo_connection.rb', line 30

def initialize
  super

  @command_timer = nil
  @initialize_device = nil
  @ready_for_commands = false
  @state = :drop

  EventMachine.add_periodic_timer(10) { check_dsr! }
  EventMachine.next_tick { check_dsr! }
end

Instance Attribute Details

#initialize_deviceObject

Returns the value of attribute initialize_device.



28
29
30
# File 'lib/smartware/drivers/common/sankyo_connection.rb', line 28

def initialize_device
  @initialize_device
end

Instance Method Details

#check_dsr!Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/smartware/drivers/common/sankyo_connection.rb', line 42

def check_dsr!
  if @io.dsr == 0
    @state = :drop
    kill_queue
  else
    was_ready, @ready_for_commands = @ready_for_commands, true

    if !was_ready
      @initialize_device.call
    end
  end
end