Subject: [ruby-ffi] Re: libnfc example troubles |
From: Wayne Meissner |
Date: 6/1/13 1:29 AM |
To: ruby-ffi@googlegroups.com |
Hi everyone.
i need some backup to get going with my project trying to make ruby-wrapper for libnfc:Test program(trying to simulate this c example:):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) Output of testprogram(connecting to nfc interface but will call the last method with succes) :ACS / ACR122U PICC Interface-2My FFI library: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], :int endHeader function that i am trying to implement: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); The c example program are running flawlessly and i am connecting to the nfc interface, but somehow the last method is attached wrong but how?I have been stucked here for some days now trying to figure out why my rb test program will not call the method properbly, when the c version works great.
Any help will be much appreciated.