Class: Escalator::Uploader

Inherits:
Object
  • Object
show all
Includes:
PlcDefine
Defined in:
lib/escalator/uploader.rb

Constant Summary

Constants included from PlcDefine

PlcDefine::ESC_STATUS_FROM_PLC_ACK_CLEAR_PROGRAM, PlcDefine::ESC_STATUS_FROM_PLC_CYCLE_RUN, PlcDefine::ESC_STATUS_TO_PLC_CLEAR_PROGRAM, PlcDefine::ESC_STATUS_TO_PLC_STOP_PLC_FLAG

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Uploader

Returns a new instance of Uploader.



36
37
38
# File 'lib/escalator/uploader.rb', line 36

def initialize options={}
  @protocol = options[:protocol] if options[:protocol]
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



34
35
36
# File 'lib/escalator/uploader.rb', line 34

def data
  @data
end

#protocolObject

Returns the value of attribute protocol.



32
33
34
# File 'lib/escalator/uploader.rb', line 32

def protocol
  @protocol
end

#sourceObject

Returns the value of attribute source.



33
34
35
# File 'lib/escalator/uploader.rb', line 33

def source
  @source
end

Instance Method Details

#uploadObject



40
41
42
43
44
45
46
# File 'lib/escalator/uploader.rb', line 40

def upload
  # stop plc
  stop_plc
  clear_program
  write_program
  run_plc
end

#word_dataObject



55
56
57
58
59
60
# File 'lib/escalator/uploader.rb', line 55

def word_data
  data.each_slice(2).map do |pair|
    pair << 0 if pair.size == 1
    pair.pack("c*").unpack("n*")
  end.flatten
end