Closed Propanu closed 8 years ago
Think of libft4222 as serial port; it can can only be opened once. If it opened a second time it will fail. That's what you;re seeing. This is a mraa documentation bug.
Yeah that part is clear and I don't have an issue with that. But I would expect us to be able to return the existing subplaform handle on an init call the second time around. In fact I'm sure we already do this to some extent or you won't be able to use multiple sensors from UPM, we're just not catching this UPM+MRAA case.
Thanks for clarifying failure. If platform is already initialized I can't figure out how mraa_init() manages to initialize sub-platform a second time.I'll take a closer look.
I dug deeper and found that the mraa node module links to mraa object files, not the shared library. upm node modules do the right thing and link to the mraa shared library. Thus when a node project uses both mraa and a upm modules you end up with two mraa instances so mraa_init() is called twice. The second mraa_init() call results in the libft4222 double load and subsequent failure. Java and Python bindings will have the same problem.
I fixed this by changing the following lines in src/javascript/CMakeLists.txt.
swig_add_module (mraajs javascript mraajs.i ${mraa_LIB_SRCS})
swig_link_libraries (mraajs ${mraa_LIBS})
to
swig_add_module (mraajs javascript mraajs.i)
swig_link_libraries (mraajs mraa)
Similar changes should be made for Python and Java.
@arfoll - is this a valid fix?
Yeah it's valid - if it works as expected :D, there where some issues previously which is why mraa was built this way, wasted a few kBs.
@whbruce thanks for tracking this down and finding a fix. I can see many use cases were both MRAA & UPM are desired within the same application.
The Java fix is proving to be more complicated. There is JNI code in gpio.c (and maybe elsewhere) that complicates linking. It should be moved to src/java so it is exported by libmraajava.so and not libmraa.so. I'll get to this, but not for a few days.
UPM Java libraries link with libmraajava.so, and MRAA Java class should also load libmraajava.so. Are there any cases in which this doesn't happen already?
Currently libmraajava.so statically links to mraa but UPM jini shared libraries dynamically link to libmraa. So if a Java app instantiates both mraa and upm objects, the underlying platform object is instantiated twice as well which causes the problem reported by @Propanu.
I have a fix in progress, will issue a PR by EOD which Java team can review.
Done. See PR #441.
Awesome, thanks everyone for the quick turnaround!
Title says it all, if you try to use both MRAA and some UPM driver with the FT4222, the second subplatform init will fail. So far only tested this with node but I assume it will happen in other languages too. Here's the code:
And here's the log:
Thus you could use one or the other but not both. Using multiple UPM sensors seems to work as expected though.