B4J Question How to check if Rasberry Pi GPIO Controller is present?

corwin42

Expert
Licensed User
Hi,

I am currently working on a project which should finally run on a raspberry pi and it uses the jPi4J library (GPIO).

For testing I want to run the application on a normal windows pc. How can I check, if the app is running on the pi so I can run the GPIO code only if running on the pi?

Catching the exception when initializing the gpio-controller does not work:

B4X:
Sub Process_Globals
    Private mController As GpioController
    Private IsGpioControllerInitialized As Boolean = False
End Sub

Private Sub InitializeGpioController
    If Not(IsGpioControllerInitialized) Then
        Try
            mController.Initialize
            IsGpioControllerInitialized = True
        Catch
            Log(LastException)
            Log("GPIO Controller not initialized")
        End Try
    End If
End Sub
I get the following error:
Jan 27, 2016 11:48:24 AM com.pi4j.util.NativeLibraryLoader load
SCHWERWIEGEND: Unable to load [libpi4j.so] using path: [/lib/libpi4j.so]
java.lang.IllegalArgumentException: The path has to be absolute, but found: \lib\libpi4j.so
at com.pi4j.util.NativeLibraryLoader.loadLibraryFromClasspath(NativeLibraryLoader.java:120)
at com.pi4j.util.NativeLibraryLoader.load(NativeLibraryLoader.java:92)
at com.pi4j.wiringpi.Gpio.<clinit>(Gpio.java:174)
at com.pi4j.io.gpio.RaspiGpioProvider.<init>(RaspiGpioProvider.java:51)
at com.pi4j.io.gpio.GpioFactory.getDefaultProvider(GpioFactory.java:106)
at com.pi4j.io.gpio.impl.GpioControllerImpl.<init>(GpioControllerImpl.java:54)
at com.pi4j.io.gpio.GpioFactory.getInstance(GpioFactory.java:89)
at anywheresoftware.b4j.objects.GpioControllerWrapper.Initialize(GpioControllerWrapper.java:51)
at b4j.example.pwm._initializegpiocontroller(pwm.java:74)
at b4j.example.pwm._initializeadafruitpwm(pwm.java:48)
at b4j.example.main._appstart(main.java:65)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
at b4j.example.main.main(main.java:29)
pwm._initializegpiocontroller (java line: 74)
java.lang.UnsatisfiedLinkError: com.pi4j.wiringpi.Gpio.wiringPiSetup()I
at com.pi4j.wiringpi.Gpio.wiringPiSetup(Native Method)
at com.pi4j.io.gpio.RaspiGpioProvider.<init>(RaspiGpioProvider.java:51)
at com.pi4j.io.gpio.GpioFactory.getDefaultProvider(GpioFactory.java:106)
at com.pi4j.io.gpio.impl.GpioControllerImpl.<init>(GpioControllerImpl.java:54)
at com.pi4j.io.gpio.GpioFactory.getInstance(GpioFactory.java:89)
at anywheresoftware.b4j.objects.GpioControllerWrapper.Initialize(GpioControllerWrapper.java:51)
at b4j.example.pwm._initializegpiocontroller(pwm.java:74)
at b4j.example.pwm._initializeadafruitpwm(pwm.java:48)
at b4j.example.main._appstart(main.java:65)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
at b4j.example.main.main(main.java:29)
main.main (java line: 29)
java.lang.RuntimeException: java.lang.UnsatisfiedLinkError: com.pi4j.wiringpi.Gpio.wiringPiSetup()I
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:114)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
at b4j.example.main.main(main.java:29)
Caused by: java.lang.UnsatisfiedLinkError: com.pi4j.wiringpi.Gpio.wiringPiSetup()I
at com.pi4j.wiringpi.Gpio.wiringPiSetup(Native Method)
at com.pi4j.io.gpio.RaspiGpioProvider.<init>(RaspiGpioProvider.java:51)
at com.pi4j.io.gpio.GpioFactory.getDefaultProvider(GpioFactory.java:106)
at com.pi4j.io.gpio.impl.GpioControllerImpl.<init>(GpioControllerImpl.java:54)
at com.pi4j.io.gpio.GpioFactory.getInstance(GpioFactory.java:89)
at anywheresoftware.b4j.objects.GpioControllerWrapper.Initialize(GpioControllerWrapper.java:51)
at b4j.example.pwm._initializegpiocontroller(pwm.java:74)
at b4j.example.pwm._initializeadafruitpwm(pwm.java:48)
at b4j.example.main._appstart(main.java:65)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
... 2 more
 
Top