Method: CTAPI::Cardterminal#read

Defined in:
lib/ctapi.rb

#read(address = 0, size = nil) ⇒ Object

Attempts to read data of length size starting at address. If size is nil, an attempt is made to read the whole card memory.



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
# File 'lib/ctapi.rb', line 168

def read(address = 0, size = nil)
  if size == nil
    if @card
      size = @card.memory_size - address
    else
      size = chunk_size
    end
  elsif @card and address + size > @card.memory_size
    size = @card.memory_size - address
  end
  return if size <= 0
  data = ''
  caught = catch(:break) do
    while size >= chunk_size
      d = read_chunk(address, chunk_size)
      if d
        data << d
        address += chunk_size
        size -= chunk_size
      else
        break :break  
      end
    end
  end
  if caught != :break and size > 0
    d = read_chunk(address, size) and data << d
  end
  data
end