Class: ModBus::RTUServer
- Inherits:
-
Object
- Object
- ModBus::RTUServer
- Defined in:
- lib/rmodbus/rtu_server.rb
Overview
RTU server implementation
Constant Summary
Constants included from Server
Instance Attribute Summary
Attributes included from SP
#baud, #data_bits, #parity, #port, #read_timeout, #stop_bits
Attributes included from Server
#coils, #discrete_inputs, #holding_registers, #input_registers, #uid
Attributes included from Debug
#debug, #raise_exception_on_mismatch, #read_retries, #read_retry_timeout
Instance Method Summary collapse
-
#initialize(port, baud = 9600, uid = 1, opts = {}) ⇒ RTUServer
constructor
Init RTU server.
-
#join ⇒ Object
Join server.
-
#start ⇒ Object
Start server.
-
#stop ⇒ Object
Stop server.
Methods included from SP
Constructor Details
#initialize(port, baud = 9600, uid = 1, opts = {}) ⇒ RTUServer
Init RTU server
20 21 22 23 24 |
# File 'lib/rmodbus/rtu_server.rb', line 20 def initialize(port, baud=9600, uid=1, opts = {}) Thread.abort_on_exception = true @sp = open_serial_port(port, baud, opts) @uid = uid end |
Instance Method Details
#join ⇒ Object
Join server
42 43 44 |
# File 'lib/rmodbus/rtu_server.rb', line 42 def join @serv.join end |
#start ⇒ Object
Start server
27 28 29 30 31 32 33 |
# File 'lib/rmodbus/rtu_server.rb', line 27 def start @serv = Thread.new do serv_rtu_requests(@sp) do |msg| exec_req(msg[1..-3], @coils, @discrete_inputs, @holding_registers, @input_registers) end end end |
#stop ⇒ Object
Stop server
36 37 38 39 |
# File 'lib/rmodbus/rtu_server.rb', line 36 def stop Thread.kill(@serv) @sp.close end |