To post comments on this article and find any associated files and/or downloads,
go to www.nutsvolts.com/magazine/issue/2017/07.
sudo java -jar b4j-bridge.jar
Screenshot 3 is the result of a successful execution
of the b4j-bridge.jar file. As you can see, the Pi spits up
its IP address and port numbers for the FTP transfers.
Now that we have the Pi’s IP address, we can plug it
into B4J and attempt to connect.
Things are good in Screenshot 4. At this point, we
can generate PiFace code and upload it to the RaspbPi.
Once the Pi has the code, we can use the B4J Bridge to
remotely debug it.
■ SCREENSHOT 2. This command sequence downloads the
b4j-bridge.jar file into the current Raspberry Pi directory.
Let’s Write Some Code
B4J can be used to create UI and non-UI
applications. We will create non-UI applications for the
PiFace. Console and server applications fall in the non-UI category. Thus, the PiFace applications will have no
fancy user interface. We must be sure to select Non-UI
■ SCREENSHOT 3. We need the Pi’s IP address to hook up the
PiFace application to avoid a Java runtime error
“bridge.” The FTP ports are nice to have, but we don’t use
them or care about them.
Here is the non-UI code skeleton that B4J
generates for us:
‘Non-UI application (console / server
#Region Project Attributes
■ SCREENSHOT 4. We can now upload code to the Raspberry
Sub AppStart (Args() As String)
Pi and debug it remotely under the control of B4J.
6. So, if you’re familiar with VB6, you are a rung up on the
learning curve ladder. B4J runs on a PC and generates the
PiFace code that we will be loading onto our Pi. To get
code down to the Pi and enable remote debugging, we
need to run a program on the Pi that “bridges” B4J to the
‘‘‘Return true to allow the default exceptions
handler to handle the uncaught exception.
Sub Application_Error (Error As Exception,
StackTrace As String) As Boolean
Pi. That program is aptly called B4J Bridge.
To get the Pi portion of B4J Bridge, we must
download the B4J jar file to our RaspPi. Here’s the Pi
command that accomplishes that:
It’s up to us to fill in the meat of the various B4J
subroutines. So, let’s start with the Process_Globals
Following the entry of the wget command, the Pi spits
out the text you see in Screenshot 2 and the b4j-bridge.jar
file is placed into the Pi’s current directory. At this point,
we can fire up B4J on the PC and attempt to “bridge” the
Process_Global variables can be declared as public or
private. Public variables are accessible by the entire
project. Private variables are limited to access only within
their module. The same thought holds true for variables
and subroutines. Private variables can only be accessed
within the subroutine, while public variables can be
accessed by any subroutine.
All global variables must be declared within the
Pi and B4J.
Before we attempt the connection, we must also kick
off the Pi portion of the bridge. Again, we resort to our
Process_Globals subroutine. To allow the variables to be
accessed from everywhere in the project, declare the
variables as public. Otherwise, declare them as private.
RaspPi terminal session and enter the following:
The public variables will live as long as the process lives.
56 July 2017