class ModBus::RTUViaTCPServer
RTU
over TCP
server implementation @example
srv = RTUViaTCPServer.new(10002, 1) srv.coils = [1,0,1,1] srv.discrete_inputs = [1,1,0,0] srv.holding_registers = [1,2,3,4] srv.input_registers = [1,2,3,4] srv.debug = true srv.start
Public Class Methods
new(port = 10002, uid = 1, opts = {})
click to toggle source
Init server @param [Integer] port listen port @param [Integer] uid slave device @param [Hash] opts options of server @option opts [String] :host host of server default '127.0.0.1' @option opts [Float, Integer] :max_connection max of TCP
connection with server default 4
Calls superclass method
# File lib/rmodbus/rtu_via_tcp_server.rb, line 28 def initialize(port = 10002, uid = 1, opts = {}) @uid = uid opts[:host] = DEFAULT_HOST unless opts[:host] opts[:max_connection] = 4 unless opts[:max_connection] super(port, host = opts[:host], maxConnection = opts[:max_connection]) end
Protected Instance Methods
serve(io)
click to toggle source
Serve requests @param [TCPSocket] io socket
# File lib/rmodbus/rtu_via_tcp_server.rb, line 38 def serve(io) serv_rtu_requests(io) do |msg| exec_req(msg[1..-3], @coils, @discrete_inputs, @holding_registers, @input_registers) end end