larskanis/libusb

no _data_dump for FFI::Pointer

westonplatter opened this issue · 3 comments

Thanks for making edits to the LIBUSB library. Our design project would be of the question without it.

I realize this stems from an issue in FFI. Any ideas how to fix this?

I try to store a LIBUSB::Context object in the Rack::Session while using Sinatra. I can store the object in the Rack Session fine, but when I bring it back down, I get this error.

https://twitter.com/#!/westonplatter/status/180213943380348928/photo/1
TypeError at /session
no _dump_data is defined for class FFI::Pointer
file: cookie.rb location: dump line: 60

https://github.com/ffi/ffi/blob/master/lib/ffi/pointer.rb

Any help is appreciated.

I didn't use libusb in a web context, yet, but it doesn't make much sense to store LIBUSB objects into the session, for me. The objects are directly connected to underlying C structs, so they can not be marshaled. This is the same as for IO objects. You can create as many Context objects as you like and open+close the device within each request. Alternatively you could use some kind of background job, that can hold the device open.

The radio gem makes some use of libusb in a web context. Maybe it's helpful for you: https://github.com/ham21/radio/blob/master/lib/radio/controls/si570avr.rb

I wasn't sure if C objects could be marshalled. The example was really helpful. Thanks.

Fine. Btw: There is a convenience method Device#open_interface, which could save some lines of code.