Class: ForestClient::Printer

Inherits:
Object
  • Object
show all
Defined in:
lib/forest-client/printer.rb

Instance Method Summary collapse

Constructor Details

#initialize(ip) ⇒ Printer

Create a new instance of Printer by passing its IP address



8
9
10
# File 'lib/forest-client/printer.rb', line 8

def initialize(ip)
    @ip = ip
end

Instance Method Details

#get_consumable(id) ⇒ Object



122
123
124
125
126
127
128
129
130
131
# File 'lib/forest-client/printer.rb', line 122

def get_consumable(id)
    color = snmp_get("1.3.6.1.2.1.43.12.1.1.4.1.#{id}").to_s
    level = Integer(snmp_get("1.3.6.1.2.1.43.11.1.1.9.1.#{id}"))
    capacity = Integer(snmp_get("1.3.6.1.2.1.43.11.1.1.8.1.#{id}"))
    percentage = Float(level) * 100 / Float(capacity)
    return {:color => color,
        :level => level,
        :capacity => capacity,
        :percentage => percentage}
end

#get_consumable_namesObject



133
134
135
# File 'lib/forest-client/printer.rb', line 133

def get_consumable_names
    return snmp_walk('1.3.6.1.2.1.43.11.1.1.6.1').each { |item| item.chop! }
end

#get_consumablesObject



137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/forest-client/printer.rb', line 137

def get_consumables
    consumables = get_consumable_names

    ret = Array.new

    consumables.length.times do |id|
        cons = get_consumable(id + 1)
        cons[:name] = consumables.at(id)
        ret.push(cons)
    end

    return ret
end

#get_device(id) ⇒ Object

Returns the name and status of the specified device as a hash



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/forest-client/printer.rb', line 87

def get_device(id)
    
    # Get the device name
    name = snmp_get("1.3.6.1.2.1.25.3.2.1.3.#{id}")
    
    # Make the status human-readable
    case snmp_get("1.3.6.1.2.1.25.3.2.1.5.#{id}")
    when 1
        status = 'Unknown'
    when 2
        status = 'Running'
    when 3
        status = 'Warning'
    when 4
        status = 'Testing'
    when 5
        status = 'Down'
    else
        status = 'Unknown'
    end

    return {:name => name, :status => status}
end

#get_device_idsObject

Returns an array of all device IDs



82
83
84
# File 'lib/forest-client/printer.rb', line 82

def get_device_ids
    return snmp_walk('1.3.6.1.2.1.25.3.2.1.1')
end

#get_devicesObject

Returns an array of the results of get_device_status for all of the printer’s devices



113
114
115
116
117
118
119
120
# File 'lib/forest-client/printer.rb', line 113

def get_devices
    devices = get_device_ids
    ret = Array.new
    devices.each do |device|
        ret.push(get_device(device))
    end
    return ret
end

#get_displayObject

Query the printer for its display



59
60
61
# File 'lib/forest-client/printer.rb', line 59

def get_display
    return snmp_walk('1.3.6.1.2.1.43.16.5.1.2.1').at(0)
end

#get_ipObject

Return the IP address of the printer



13
14
15
# File 'lib/forest-client/printer.rb', line 13

def get_ip
    return @ip
end

#get_locationObject



199
200
201
# File 'lib/forest-client/printer.rb', line 199

def get_location
    return snmp_get('1.3.6.1.2.1.1.6.0')
end

#get_messagesObject

Query the printer for its message



49
50
51
# File 'lib/forest-client/printer.rb', line 49

def get_messages
    return snmp_walk('1.3.6.1.2.1.43.18.1.1.8').at(0)
end

#get_modelObject

Query the printer for its model number



39
40
41
# File 'lib/forest-client/printer.rb', line 39

def get_model
    return snmp_get('1.3.6.1.2.1.25.3.2.1.3.1')
end

#get_nameObject



203
204
205
# File 'lib/forest-client/printer.rb', line 203

def get_name
    return snmp_get('1.3.6.1.2.1.1.5.0')
end

#get_page_countObject

Query the printer for its pagecount



54
55
56
# File 'lib/forest-client/printer.rb', line 54

def get_page_count
    return Integer(snmp_get('1.3.6.1.2.1.43.10.2.1.4.1.1'))
end

#get_serialObject

Query the printer for its serial



44
45
46
# File 'lib/forest-client/printer.rb', line 44

def get_serial
    return snmp_walk('1.3.6.1.2.1.43.5.1.1.17').at(0)
end

#get_statusObject

Query the printer for its status The printer will return an integer which we convert into a meaninful string



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/forest-client/printer.rb', line 66

def get_status
    case snmp_get('1.3.6.1.2.1.25.3.5.1.1.1')
    when 1
        return 'Other'
    when 3
        return 'Idle'
    when 4
        return 'Printing'
    when 5
        return 'Warmup'
    else
        return 'Unknown'
    end
end

#get_traysObject



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/forest-client/printer.rb', line 151

def get_trays
    trays = Array.new
    snmp_walk('1.3.6.1.2.1.43.8.2.1.10.1').length.times do |id|
        tray = id + 1
        name = snmp_get("1.3.6.1.2.1.43.8.2.1.13.1.#{tray}")

        rem = snmp_get("1.3.6.1.2.1.43.8.2.1.10.1.#{tray}")
        case rem
        when -3
            status = 'OK'
        when -2
            status = 'Unknown'
        when 0
            status = 'Empty'
        else
            status = "#{rem} sheets remaining"
        end

        feed_dim = snmp_get("1.3.6.1.2.1.43.8.2.1.4.1.#{tray}")
        xfeed_dim = snmp_get("1.3.6.1.2.1.43.8.2.1.5.1.#{tray}")
        dim_units = snmp_get("1.3.6.1.2.1.43.8.2.1.3.1.#{tray}")

        if feed_dim.respond_to?(:to_i) && xfeed_dim.respond_to?(:to_i) && dim_units.respond_to?(:to_i)
            if feed_dim > 0 && xfeed_dim > 0
                if dim_units.to_i == 3
                    feed_dim = Float(feed_dim) / 10000
                    xfeed_dim = Float(xfeed_dim) / 10000
                elsif dim_units.to_i == 4
                    feed_dim = Float(feed_dim) * 0.0000393700787
                    xfeed_dim = Float(xfeed_dim) * 0.0000393700787
                end
            end
        end

        capacity = snmp_get("1.3.6.1.2.1.43.8.2.1.9.1.#{tray}")

        if capacity.respond_to?(:to_i)
            capacity = capacity.to_i
        else
            capacity = 0
        end     

        trays.push({:name => name, :status => status, :y => feed_dim, :x => xfeed_dim, :capacity => capacity})
    end

    return trays
end