Class: LadderDrive::Uploader
- Inherits:
-
Object
- Object
- LadderDrive::Uploader
- Includes:
- PlcDefine
- Defined in:
- lib/ladder_drive/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
-
#protocol ⇒ Object
Returns the value of attribute protocol.
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
- #data ⇒ Object
-
#initialize(options = {}) ⇒ Uploader
constructor
A new instance of Uploader.
- #upload ⇒ Object
- #word_data ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Uploader
Returns a new instance of Uploader.
35 36 37 |
# File 'lib/ladder_drive/uploader.rb', line 35 def initialize ={} @protocol = [:protocol] if [:protocol] end |
Instance Attribute Details
#protocol ⇒ Object
Returns the value of attribute protocol.
32 33 34 |
# File 'lib/ladder_drive/uploader.rb', line 32 def protocol @protocol end |
#source ⇒ Object
Returns the value of attribute source.
33 34 35 |
# File 'lib/ladder_drive/uploader.rb', line 33 def source @source end |
Instance Method Details
#data ⇒ Object
47 48 49 50 51 52 |
# File 'lib/ladder_drive/uploader.rb', line 47 def data @data ||= begin hex = IntelHex.load @source hex.codes end end |
#upload ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/ladder_drive/uploader.rb', line 39 def upload # stop plc stop_plc clear_program write_program run_plc end |
#word_data ⇒ Object
54 55 56 57 58 59 |
# File 'lib/ladder_drive/uploader.rb', line 54 def word_data data.each_slice(2).map do |pair| pair << 0 if pair.size == 1 pair.pack("C*").unpack("n*") end.flatten end |