class Plc::Raspberrypi::RaspberrypiPlc

Public Class Methods

new(config={}) click to toggle source
Calls superclass method Plc::Emulator::EmuPlc::new
# File lib/plc/raspberrypi/raspberrypi_plc.rb, line 36
def initialize config={}
  super
  setup_io
end

Private Instance Methods

setup_io() click to toggle source
# File lib/plc/raspberrypi/raspberrypi_plc.rb, line 43
def setup_io
  @available_pi_piper = true
  @io_dict = { inputs:[], outputs:[] }
  config[:io][:inputs].each do |dev, info|
    @io_dict[:inputs] << [device_by_name(dev), Pin.new(pin:info[:pin], direction: :in, pull:(info[:pull].to_sym || :off), invert:info[:invert])]
  end
  config[:io][:outputs].each do |dev, info|
    @io_dict[:outputs] << [device_by_name(dev), Pin.new(pin:info[:pin], direction: :out)]
  end
rescue NoMethodError
  puts "WARN: defention of io is missing!"
rescue LoadError
  @available_pi_piper = false
  puts "WARN: pi_piper is not available in this system!"
end
sync_input() click to toggle source
Calls superclass method Plc::Emulator::EmuPlc#sync_input
# File lib/plc/raspberrypi/raspberrypi_plc.rb, line 59
def sync_input
  if @available_pi_piper
    @io_dict[:inputs].each do |device, pin|
      pin.read
      device.set_value pin.on?, :in
    end
  end
  super
end
sync_output() click to toggle source
Calls superclass method Plc::Emulator::EmuPlc#sync_output
# File lib/plc/raspberrypi/raspberrypi_plc.rb, line 69
def sync_output
  super
  return unless @available_pi_piper

  @io_dict[:outputs].each do |device, pin|
    if device.bool
      pin.on
    else
      pin.off
    end
  end
end