Class: Pport::GenPport

Inherits:
Object
  • Object
show all
Defined in:
lib/pport.rb

Overview

Class representing a generic parallel port, calls the platform appropriate class to actually interact with the port.

Instance Method Summary collapse

Constructor Details

#initialize(address) ⇒ GenPport

Creates a platform appropriate parallel port object.



24
25
26
27
28
29
30
31
32
33
# File 'lib/pport.rb', line 24

def initialize(address)

    @port = nil

    if RUBY_PLATFORM.match(/linux/i)
        @port = LinuxPport.new(address)
    elsif RUBY_PLATFORM.match(/mingw/i) or RUBY_PLATFORM.match(/mswin/i)
        @port = WinPport.new(address)
    end
end

Instance Method Details

#readObject

Reads the value of the port.



36
37
38
# File 'lib/pport.rb', line 36

def read()
    return @port.read
end

#to_sObject



50
51
52
# File 'lib/pport.rb', line 50

def to_s
    return @address
end

#write(val) ⇒ Object

Writes a value to the port.

The value must be an integer from 0 to 255. Invalid values will raise a RuntimeError.



44
45
46
47
48
# File 'lib/pport.rb', line 44

def write(val)
    val = val.to_i
    raise if val > 255 or val < 0
    @port.write(val)
end