Module: ModBus::SP
Instance Attribute Summary collapse
-
#baud ⇒ Object
readonly
Returns the value of attribute baud.
-
#data_bits ⇒ Object
readonly
Returns the value of attribute data_bits.
-
#parity ⇒ Object
readonly
Returns the value of attribute parity.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#read_timeout ⇒ Object
readonly
Returns the value of attribute read_timeout.
-
#stop_bits ⇒ Object
readonly
Returns the value of attribute stop_bits.
Instance Method Summary collapse
-
#open_serial_port(port, baud, opts = {}) ⇒ SerialPort
Open serial port.
Instance Attribute Details
#baud ⇒ Object (readonly)
Returns the value of attribute baud.
9 10 11 |
# File 'lib/rmodbus/sp.rb', line 9 def baud @baud end |
#data_bits ⇒ Object (readonly)
Returns the value of attribute data_bits.
9 10 11 |
# File 'lib/rmodbus/sp.rb', line 9 def data_bits @data_bits end |
#parity ⇒ Object (readonly)
Returns the value of attribute parity.
9 10 11 |
# File 'lib/rmodbus/sp.rb', line 9 def parity @parity end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
9 10 11 |
# File 'lib/rmodbus/sp.rb', line 9 def port @port end |
#read_timeout ⇒ Object (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_bits ⇒ Object (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
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rmodbus/sp.rb', line 20 def open_serial_port(port, baud, opts = {}) @port, @baud = port, baud @data_bits, @stop_bits, @parity, @read_timeout = 8, 1, SerialPort::NONE, 100 @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? @read_timeout = opts[:read_timeout] unless opts[:read_timeout].nil? io = SerialPort.new(@port, @baud, @data_bits, @stop_bits, @parity) io.flow_control = SerialPort::NONE io.read_timeout = @read_timeout io end |