Omg-Networked-Rfid
Installation
Add this line to your application's Gemfile:
gem 'omg-networked-rfid'
And then execute:
$ bundle
Or install it yourself as:
$ gem install omg-networked-rfid
Usage
It provides a few basic classes that you can use to read RFID cards remotely.
NetworkedRFID::RFIDReaderRepository
provides a repository for collective RFID reader polling.NetworkedRFID::RemoteRFIDReader
gives you a networked reader you can later add the repository. It delegates card reader events to a higher level delegate.NetworkedRFID::CardApplicationDelegate
one of the delegates that can processNetworkedRFID::RemoteRFIDReader
events. It translates those low-level events into card application events, which are then delegated further to a delegate of your choice. Your delegate is required to support only one method:card_scanned(card_number)
.
Example
Here's how you can read your cards using RFID cardreader and output their numbers to the console.
require "bundler"
Bundler.require
# Your sample upper-level delegate
class SampleCardProcessingDelegate
def card_scanned(card_number)
puts "Card has been scanned: #{card_number}"
end
end
# Make an instance of your delegate
card_processing_delegate = SampleCardProcessingDelegate.new
# Assign it to a message-level delegate
card_application_delegate = NetworkedRFID::CardApplicationDelegate.new
card_application_delegate.delegate = card_processing_delegate
# Create new RFID reader and add the message-level delegate to it
reader = NetworkedRFID::RemoteRFIDReader.new("192.168.1.100", 2000)
reader.delegate = card_application_delegate
# Finally add newly created RFID reader to the repository
repository = NetworkedRFID::RFIDReaderRepository.new
repository << reader
# Start main polling cycle
while true
repository.poll
end
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Merge Request