Class: ModBus::RTUServer

Inherits:
Object
  • Object
show all
Includes:
Debug, RTU, SP, Server
Defined in:
lib/rmodbus/rtu_server.rb

Overview

RTU server implementation

Examples:

srv = RTUServer.new('/dev/ttyS1', 9600)
slave = srv.with_slave(1)
slave.coils = [1,0,1,1]
slave.discrete_inputs = [1,1,0,0]
slave.holding_registers = [1,2,3,4]
slave.input_registers = [1,2,3,4]
srv.logger = Logger.new($stdout)
srv.start

Constant Summary

Constants included from Server

Server::FUNCS

Instance Attribute Summary

Attributes included from SP

#baud, #data_bits, #parity, #port, #read_timeout, #stop_bits

Attributes included from Server

#promiscuous, #request_callback, #response_callback

Attributes included from Debug

#logger, #raise_exception_on_mismatch, #read_retries, #read_retry_timeout

Instance Method Summary collapse

Methods included from SP

#open_serial_port

Methods included from Server

#with_slave

Constructor Details

#initialize(port, baud = 9600, opts = {}) ⇒ RTUServer

Init RTU server

Parameters:

See Also:



23
24
25
26
27
28
29
30
# File 'lib/rmodbus/rtu_server.rb', line 23

def initialize(port, baud = 9600, opts = {})
  Thread.abort_on_exception = true
  @sp = if port.is_a?(IO) || port.respond_to?(:read)
          port
        else
          open_serial_port(port, baud, opts)
        end
end

Instance Method Details

#joinObject

Join server



46
47
48
# File 'lib/rmodbus/rtu_server.rb', line 46

def join
  @serv.join
end

#startObject

Start server



33
34
35
36
37
# File 'lib/rmodbus/rtu_server.rb', line 33

def start
  @serv = Thread.new do
    serve(@sp)
  end
end

#stopObject

Stop server



40
41
42
43
# File 'lib/rmodbus/rtu_server.rb', line 40

def stop
  Thread.kill(@serv)
  @sp.close
end