Class: Phidgets::RFID

Inherits:
Common
  • Object
show all
Defined in:
lib/phidgets/rfid.rb,
ext/phidgets/phidgets_rfid.c

Constant Summary collapse

PROTOCOL_EM4100 =

EM4100 (EM4102) 40-bit

INT2NUM(PROTOCOL_EM4100)
PROTOCOL_ISO11785_FDX_B =

ISO11785 FDX-B encoding (Animal ID)

INT2NUM(PROTOCOL_ISO11785_FDX_B)
PROTOCOL_PHIDGETS =

PhidgetTAG Protocol 24 character ASCII

INT2NUM(PROTOCOL_PHIDGETS)

Instance Method Summary collapse

Methods inherited from Common

#close, #getAttached, #getChannel, #getChannelClass, #getChannelClassName, #getChannelName, #getChannelSubclass, #getDataInterval, #getDeviceChannelCount, #getDeviceClass, #getDeviceClassName, #getDeviceID, #getDeviceLabel, #getDeviceName, #getDeviceSKU, #getDeviceSerialNumber, #getDeviceVersion, #getHubPort, #getHubPortCount, #getIsChannel, #getIsHubPortDevice, #getIsLocal, #getIsRemote, #getServerHostname, #getServerName, #getServerPeerName, #getServerUniqueName, #open, #openWaitForAttachment, #setChannel, #setDataInterval, #setDeviceLabel, #setDeviceSerialNumber, #setHubPort, #setIsHubPortDevice, #setIsLocal, #setIsRemote, #setOnAttachHandler, #setOnDetachHandler, #setOnErrorHandler, #setOnPropertyChangeHandler, #setServerName, #writeDeviceLabel

Constructor Details

#newObject

Creates a Phidget RFID object.



9
10
11
12
13
# File 'ext/phidgets/phidgets_rfid.c', line 9

VALUE ph_rfid_init(VALUE self) {
  ph_data_t *ph = get_ph_data(self);
  ph_raise(PhidgetRFID_create((PhidgetRFIDHandle *)(&(ph->handle))));
  return self;
}

Instance Method Details

#getAntennaEnabledBoolean Also known as: antenna_enabled?

The on/off state of the antenna. You can turn the antenna off to save power. You must turn the antenna on in order to detect and read RFID tags.

Returns:

  • (Boolean)


15
16
17
# File 'ext/phidgets/phidgets_rfid.c', line 15

VALUE ph_rfid_get_antenna_enabled(VALUE self) {
  return ph_get_bool(get_ph_handle(self), (phidget_get_bool_func)PhidgetRFID_getAntennaEnabled);
}

#getLastTagObject Also known as: last_tag

Gets the most recently read tag’s data, even if that tag is no longer within read range. Only valid after at least one tag has been read.



24
25
26
27
28
29
# File 'ext/phidgets/phidgets_rfid.c', line 24

VALUE ph_rfid_get_last_tag(VALUE self) {
  char tag[256];
  PhidgetRFID_Protocol protocol;
  ph_raise(PhidgetRFID_getLastTag((PhidgetRFIDHandle)get_ph_handle(self), tag, 256, &protocol));
  return rb_ary_new3(2, rb_str_new2(tag), INT2NUM(protocol));
}

#getTagPresentBoolean Also known as: tag_present?

This property is true if a compatibile RFID tag is being read by the reader. TagPresent will remain true until the tag is out of range and can no longer be read.

Returns:

  • (Boolean)


31
32
33
# File 'ext/phidgets/phidgets_rfid.c', line 31

VALUE ph_rfid_get_tag_present(VALUE self) {
  return ph_get_bool(get_ph_handle(self), (phidget_get_bool_func)PhidgetRFID_getTagPresent);
}

#setAntennaEnabled(state) ⇒ Object Also known as: antenna_enabled=

The on/off state of the antenna. You can turn the antenna off to save power. You must turn the antenna on in order to detect and read RFID tags.



19
20
21
22
# File 'ext/phidgets/phidgets_rfid.c', line 19

VALUE ph_rfid_set_antenna_enabled(VALUE self, VALUE on) {
  ph_raise(PhidgetRFID_setAntennaEnabled((PhidgetRFIDHandle)get_ph_handle(self), TYPE(on) == T_TRUE ? PTRUE : PFALSE));
  return Qnil;
}

#setOnTagHandler(cb_proc = nil, &cb_block) ⇒ Object Also known as: on_tag

call-seq:

setOnTagHandler(proc=nil, &block)

Assigns a handler that will be called when the Tag event occurs.



11
12
13
14
15
# File 'lib/phidgets/rfid.rb', line 11

def setOnTagHandler(cb_proc = nil, &cb_block)
  @on_tag_thread.kill if defined? @on_tag_thread and @on_tag_thread.alive?
  callback = cb_proc || cb_block
  @on_tag_thread = Thread.new {ext_setOnTagHandler(callback)}
end

#setOnTagLostHandler(cb_proc = nil, &cb_block) ⇒ Object Also known as: on_tag_lost

call-seq:

setOnTagLostHandler(proc=nil, &block)

Assigns a handler that will be called when the TagLost event occurs.



22
23
24
25
26
# File 'lib/phidgets/rfid.rb', line 22

def setOnTagLostHandler(cb_proc = nil, &cb_block)
  @on_tag_lost_thread.kill if defined? @on_tag_lost_thread and @on_tag_lost_thread.alive?
  callback = cb_proc || cb_block
  @on_tag_lost_thread = Thread.new {ext_setOnTagLostHandler(callback)}
end

#write(tag, protocol, lock) ⇒ Object

Writes data to the tag being currently read by the reader. You cannot write to a read-only or locked tag.



35
36
37
38
# File 'ext/phidgets/phidgets_rfid.c', line 35

VALUE ph_rfid_write(VALUE self, VALUE tag, VALUE protocol, VALUE lock) {
  ph_raise(PhidgetRFID_write((PhidgetRFIDHandle)get_ph_handle(self), StringValueCStr(tag), NUM2INT(protocol), TYPE(lock) == T_TRUE ? PTRUE : PFALSE));
  return Qnil;
}