lib/escalator/protocol/protocol.rb in escalator-0.2.1 vs lib/escalator/protocol/protocol.rb in escalator-0.2.2

- old
+ new

@@ -19,22 +19,28 @@ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -$:.unshift File.dirname(__FILE__) +dir = File.expand_path(File.dirname(__FILE__)) +$:.unshift dir unless $:.include? dir module Escalator module Protocol +end +end +module Escalator +module Protocol + class Protocol attr_accessor :host, :port, :log_level def initialize options={} @logger = Logger.new(STDOUT) - @logger.level = options[:log_level] || Logger::INFO + self.log_level = options[:log_level] || :info end def log_level= level @log_level = level.is_a?(String) ? level.to_sym : level case @log_level @@ -68,11 +74,32 @@ def set_words_to_device words, device; end def set_word_to_device word, device; set_words_to_device word, device; end def device_by_name name; nil; end + def get_from_devices device, count = 1 + d = device_by_name device + if d.bit_device? + get_bits_from_device count, d + else + get_words_from_device count, d + end + end + + def set_to_devices device, values + d = device_by_name device + if d.bit_device? + set_bits_to_device values, d + else + set_words_to_device values, d + end + end + end end end +require 'keyence/keyence' +# Use load instead require, because there are two emulator files. +load File.join(dir, 'emulator/emulator.rb') require 'mitsubishi/mitsubishi'