def on_code(obj=nil, &block)
	  @on_code_obj = obj
      @on_code = Proc.new { |device, obj_ptr, data, data_length, bit_count, repeat|
		data_string = []
		data_length.times { |i|
			data_string[i] = data[i].get_uchar(0).to_s(16)
		}
		
	    yield self, data_string, data_length, bit_count, repeat, object_for(obj_ptr)
	}
      Klass.set_OnCode_Handler(@handle, @on_code, pointer_for(obj))
    end
def on_code(obj=nil, &block)
	  @on_code_obj = obj
      @on_code = Proc.new { |device, obj_ptr, data, data_length, bit_count, repeat|
		data_string = []
		data_length.times { |i|
			data_string[i] = data[i].get_uchar(0).to_s(16)
		}
		
	    yield self, data_string, data_length, bit_count, repeat, object_for(obj_ptr)
	}
      Klass.set_OnCode_Handler(@handle, @on_code, pointer_for(obj))
    end
Sets a code handler callback function. This is called whenever a new code is recognized.

 @param [String] obj Object to pass to the callback function. This is optional.
 @param [Proc] Block When the callback is executed, the device and object are yielded to this block.
 @example
   ir.on_code do |device, data, data_length, bit_count, repeat, obj|
	    puts "Code #{data} received, length: #{data_length}, bit count: #{bit_count}, repeat: #{repeat}"
   end
 As this runs in it's own thread, be sure that all errors are properly handled or the thread will halt and not fire any more.
 @return [Boolean] returns true or raises an error