class Plc::Raspberrypi::RaspberrypiPlcServer
Public Class Methods
launch(config={})
click to toggle source
# File lib/plc/raspberrypi/raspberrypi_plc_server.rb, line 33 def launch config={} @server ||= begin server = new config server.run server end end
new(config = {})
click to toggle source
# File lib/plc/raspberrypi/raspberrypi_plc_server.rb, line 43 def initialize config = {} @port = config[:port] || 5555 @plc = RaspberrypiPlc.new config end
Public Instance Methods
run()
click to toggle source
# File lib/plc/raspberrypi/raspberrypi_plc_server.rb, line 48 def run puts "launching respberrypi plc ... " @plc.run puts "done launching" Thread.new do server = TCPServer.open @port loop do Thread.start(server.accept) do |socket| while line = socket.gets begin r = @plc.execute_console_commands line socket.puts r rescue => e socket.puts "E0 #{e}\r\n" end end end end end end