Subject: [ruby-ffi] libnfc example troubles |
From: Anders Konring Olesen |
Date: 5/26/13 3:09 PM |
To: ruby-ffi@googlegroups.com |
require 'ffi'load '~/Documents/nfc/nfc_library.rb'device_ptr = FFI::MemoryPointer.new :pointercontext_ptr = FFI::MemoryPointer.new :pointertarget = NfcLibrary::NfcTarget.newNfcLibrary::nfc_init(context_ptr)device_ptr = NfcLibrary::nfc_open(context_ptr.read_pointer, nil)NfcLibrary::nfc_initiator_init(device_ptr)nmMifare = NfcLibrary::NfcModulation.newnmMifare[:nmt] = :NMT_ISO14443AnmMifare[:nbr] = :NBR_106device_name = NfcLibrary::nfc_device_get_name(device_ptr)puts device_nameNfcLibrary::nfc_initiator_select_passive_target(device_ptr, nmMifare, nil, 0, target.pointer)
ACS / ACR122U PICC Interface-2
module NfcLibraryextend FFI::Libraryffi_lib '/usr/local/Cellar/libnfc/1.7.0-rc1/lib/libnfc.4.dylib'typedef :pointer, :nfc_devicetypedef :pointer, :nfc_contextenum :NfcModulationType,[:NMT_ISO14443A, 1,:NMT_JEWEL,:NMT_ISO14443B,:NMT_ISO14443BI,:NMT_ISO14443B2SR,:NMT_ISO14443B2CT,:NMT_FELICA,:NMT_DEP]enum :NfcBaudRate,[:NBR_UNDEFINED, 0,:NBR_106,:NBR_212,:NBR_424,:NBR_847]class NfcIso14443aInfo < FFI::Structlayout :abtAtqa, :uint8, 2,:btSak, :uint8,:szUidLen, :size_t,:abtUid, :uint8, 10,:szAtsLen, :size_t,:abtAts, :uint8, 254endclass NfcTargetInfo < FFI::Unionlayout :nai, NfcLibrary::NfcIso14443aInfo# :nfi, :nfc_felica_info,# :nbi, :nfc_iso14443b_info,# :nii, :nfc_iso14443bi_info,# :nsi, :nfc_iso14443b2sr_info,# :nci, :nfc_iso14443b2ct_info,# :nji, :nfc_jewel_info,#:ndi, :nfc_dep_infoendclass NfcModulation < FFI::Structlayout :nmt, :NfcModulationType,:nbr, :NfcBaudRateendclass NfcTarget < FFI::Structlayout :nfc_target_info, NfcLibrary::NfcTargetInfo,:nfc_modulation, NfcLibrary::NfcModulationendattach_function :nfc_init, [:pointer], :voidattach_function :nfc_target_init, [:pointer, :pointer, :pointer, :size_t, :int], :intattach_function :nfc_open, [:pointer, :string], :pointerattach_function :nfc_close, [:pointer], :voidattach_function :nfc_list_devices, [:pointer, :string, :int], :intattach_function :nfc_initiator_init, [:pointer], :intattach_function :nfc_device_get_name, [:pointer], :stringattach_function :nfc_initiator_select_passive_target, [:pointer, NfcLibrary::NfcModulation, :pointer, :size_t, :pointer], :intend
NFC_EXPORT int nfc_initiator_select_passive_target(nfc_device *pnd, const nfc_modulation nm, const uint8_t *pbtInitData, const size_t szInitData, nfc_target *pnt);