Sha256: 9b2e35f7b11cc841c97ab29ec9e09c44de1e32f1412a35ebc74678608ec16be7

Contents?: true

Size: 1.23 KB

Versions: 3

Compression:

Stored size: 1.23 KB

Contents

require 'oscheck'

if OsCheck.is_osx?
  require 'serialport.bundle'
else 
  require 'serialport.so'
end

class SerialPort
   private_class_method(:create)

   # Creates a serial port object.
   #
   # <tt>port</tt> may be a port number
   # or the file name of a defice.
   # The number is portable; so 0 is mapped to "COM1" on Windows,
   # "/dev/ttyS0" on Linux, "/dev/cuaa0" on Mac OS X, etc.
   #
   # <tt>params</tt> can be used to configure the serial port.
   # See SerialPort#set_modem_params for details
   def SerialPort::new(port, *params)
      sp = create(port)
      begin
         sp.set_modem_params(*params)
      rescue
         sp.close
         raise
      end
      return sp
   end

   # This behaves like SerialPort#new, except that you can pass a block
   # to which the new serial port object will be passed. In this case
   # the connection is automaticaly closed when the block has finished.
   def SerialPort::open(port, *params)
      sp = create(port)
      begin
         sp.set_modem_params(*params)
      rescue
         sp.close
         raise
      end
      if (block_given?)
        begin
           yield sp
        ensure             
           sp.close
        end
        return nil
      end
      return sp
   end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
monoxit-serialport-1.2.1.2 lib/serialport.rb
monoxit-serialport-1.2.1.1 lib/serialport.rb
hybridgroup-serialport-1.2.1 lib/serialport.rb