Sha256: c11135a10b8a02709630e202be607a0502e7c31a7d868c5fa9a5fe6570c9fd9f

Contents?: true

Size: 1.04 KB

Versions: 4

Compression:

Stored size: 1.04 KB

Contents

####################################################################################################
# @author       David Kirwan https://github.com/davidkirwan/ardtweeno
# @description  Ardtweeno serial device mock
#
# @date         05-06-2013
####################################################################################################

# Imports
require "rubygems"
require "serialport"
require "logger"

class SerialDeviceMock
  
  attr_accessor :sp, :log
  
  def initialize(dev, speed, timeout, options={})
    @log = options[:log] ||= Logger.new(STDOUT)
    @log.level = options[:level] ||= Logger::DEBUG
    
    @log.debug "Creating instance of SerialDeviceMock"
    
    @sp = SerialPort.new(dev, speed)
    @sp.read_timeout = timeout
  end
   
  def write(val)
    @log.debug "Writing #{val} to the serial device"
    @sp.write(val)
  end
  
  def read()
    data = @sp.read()
    @log.debug "The following was read from the device #{data}"
    return data
  end
  
  def close
    @log.debug "Closing SerialPortMock device"
    @sp.close
  end
  
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ardtweeno-0.5.0 test/serialport_mock.rb
ardtweeno-0.4.0 test/serialport_mock.rb
ardtweeno-0.3.1 test/serialport_mock.rb
ardtweeno-0.3.0 test/serialport_mock.rb