class Escalator::Uploader

Attributes

data[RW]
protocol[RW]
source[RW]

Public Class Methods

new(options={}) click to toggle source
# File lib/escalator/uploader.rb, line 36
def initialize options={}
  @protocol = options[:protocol] if options[:protocol]
end

Public Instance Methods

upload() click to toggle source
# File lib/escalator/uploader.rb, line 40
def upload
  # stop plc
  stop_plc
  clear_program
  write_program
  run_plc
end
word_data() click to toggle source
# 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

Private Instance Methods

clear_program() click to toggle source
# File lib/escalator/uploader.rb, line 73
def clear_program
  @protocol.set_word_to_device ESC_STATUS_TO_PLC_STOP_PLC_FLAG | ESC_STATUS_TO_PLC_CLEAR_PROGRAM, EscDevice.status_to_plc_device
  Timeout.timeout(5) do
    v = @protocol.get_word_from_device EscDevice.status_from_plc_device
    break if (v & ESC_STATUS_TO_PLC_CLEAR_PROGRAM) != 0
    sleep 0.1
  end
  @protocol.set_word_to_device ESC_STATUS_TO_PLC_STOP_PLC_FLAG, EscDevice.status_to_plc_device
end
run_plc() click to toggle source
# File lib/escalator/uploader.rb, line 83
def run_plc
  @protocol.set_word_to_device 0, EscDevice.status_to_plc_device
  Timeout.timeout(5) do
    v = @protocol.get_word_from_device EscDevice.status_from_plc_device
    break if (v & ESC_STATUS_FROM_PLC_CYCLE_RUN) != 0
    sleep 0.1
  end
end
stop_plc() click to toggle source
# File lib/escalator/uploader.rb, line 64
def stop_plc
  @protocol.set_word_to_device ESC_STATUS_TO_PLC_STOP_PLC_FLAG, EscDevice.status_to_plc_device
  Timeout.timeout(5) do
    v = @protocol.get_word_from_device EscDevice.status_from_plc_device
    break if (v & ESC_STATUS_TO_PLC_STOP_PLC_FLAG) != 0
    sleep 0.1
  end
end
write_program() click to toggle source
# File lib/escalator/uploader.rb, line 92
def write_program
  word_data.each_slice(2*1024) do |chunk|
    @protocol.set_words_to_device chunk, EscDevice.program_area_device
  end
end