Class: Fluent::Plugin::SerialPortInput

Inherits:
Input
  • Object
show all
Defined in:
lib/fluent/plugin/in_serialport.rb

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



16
17
18
19
# File 'lib/fluent/plugin/in_serialport.rb', line 16

def configure(conf)
  super
  @device = device
end

#runObject



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fluent/plugin/in_serialport.rb', line 32

def run
  loop do
    break if @serial.closed?
    begin
      timenow = @include_time ? Time.now.to_s << ' ' : ''
      data = {@device => timenow << @serial.readline(@eol)}
      router.emit(@tag, Fluent::EventTime.now, data)
    rescue => ex
      log.warn(error: ex) unless stopped?
      break
    end
  end
end

#shutdownObject



27
28
29
30
# File 'lib/fluent/plugin/in_serialport.rb', line 27

def shutdown
  @serial.close
  super
end

#startObject



21
22
23
24
25
# File 'lib/fluent/plugin/in_serialport.rb', line 21

def start
  super
  @serial = SerialPort.new(@com_port, @baud_rate, 8, 1, SerialPort::NONE)
  thread_create(:in_serialport, &method(:run))
end