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.



11
12
13
# File 'lib/rmodbus/sp.rb', line 11

def baud
  @baud
end

#data_bitsObject (readonly)

Returns the value of attribute data_bits.



11
12
13
# File 'lib/rmodbus/sp.rb', line 11

def data_bits
  @data_bits
end

#parityObject (readonly)

Returns the value of attribute parity.



11
12
13
# File 'lib/rmodbus/sp.rb', line 11

def parity
  @parity
end

#portObject (readonly)

Returns the value of attribute port.



11
12
13
# File 'lib/rmodbus/sp.rb', line 11

def port
  @port
end

#read_timeoutObject (readonly)

Returns the value of attribute read_timeout.



11
12
13
# File 'lib/rmodbus/sp.rb', line 11

def read_timeout
  @read_timeout
end

#stop_bitsObject (readonly)

Returns the value of attribute stop_bits.



11
12
13
# File 'lib/rmodbus/sp.rb', line 11

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



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rmodbus/sp.rb', line 22

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