Module: ModBus::SP

Included in:
RTUClient, RTUServer
Defined in:
lib/rmodbus/sp.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#baudObject (readonly)

Returns the value of attribute baud.



9
10
11
# File 'lib/rmodbus/sp.rb', line 9

def baud
  @baud
end

#data_bitsObject (readonly)

Returns the value of attribute data_bits.



9
10
11
# File 'lib/rmodbus/sp.rb', line 9

def data_bits
  @data_bits
end

#parityObject (readonly)

Returns the value of attribute parity.



9
10
11
# File 'lib/rmodbus/sp.rb', line 9

def parity
  @parity
end

#portObject (readonly)

Returns the value of attribute port.



9
10
11
# File 'lib/rmodbus/sp.rb', line 9

def port
  @port
end

#read_timeoutObject (readonly)

Returns the value of attribute read_timeout.



9
10
11
# File 'lib/rmodbus/sp.rb', line 9

def read_timeout
  @read_timeout
end

#stop_bitsObject (readonly)

Returns the value of attribute stop_bits.



9
10
11
# File 'lib/rmodbus/sp.rb', line 9

def stop_bits
  @stop_bits
end

Instance Method Details

#open_serial_port(port, baud, opts = {}) ⇒ SerialPort

Open serial port

Parameters:

  • port (String)

    name serial ports (“/dev/ttyS0”)

  • baud (Integer)

    rate serial port (default 9600)

  • opts (Hash) (defaults to: {})

    the options of serial port

Options Hash (opts):

  • :data_bits (Integer)

    from 5 to 8

  • :stop_bits (Integer)

    1 or 2

  • :parity (Integer)

    :none, :even or :odd

Returns:

  • (SerialPort)

    io serial port



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rmodbus/sp.rb', line 19

def open_serial_port(port, baud, opts = {})
  @port, @baud = port, baud

  @data_bits, @stop_bits, @parity = 8, 1, :none

  @data_bits = opts[:data_bits] unless opts[:data_bits].nil?
  @stop_bits = opts[:stop_bits] unless opts[:stop_bits].nil?
  @parity = opts[:parity] unless opts[:parity].nil?

  CCutrer::SerialPort.new(@port, baud: @baud, data_bits: @data_bits, stop_bits: @stop_bits, parity: @parity)
end