The Visual Designer view for your iPhone remote
control application can be seen in Screenshot 1. As you
can see, we have laid out three buttons, three status
indicators, a connect button, a connection status area, an
information label, and an IP address text box. The actual
visual that is shown to the user is depicted in Phoneshot 1.
Let’s get to work on the iPhone application code:
ADVANCED TECHNIQUES FOR DESIGN ENGINEERS
We have programmed the trio of D1 Mini I/O pins
to toggle on every reception of a valid command that
is directed towards that particular I/O pin. Once the
addressed I/O pin has been toggled, we use AsyncStreams
and B4RSerializator to encode a return message to the
client informing it of the status of the addressed I/O pin.
Coding the Client iPhone
B4I will be used to bring our iPhone code to life. The
code we generate with B4I will also run on an iPad. Coding
with B4I is very similar to coding with Visual Basic. The
B4I graphical user interface (GUI) is created using Visual
Designer, which also generates the skeleton subroutine
calls for the graphical widgets.
Once we have defined all the application objects and
generated the widget subroutines, we can then start to
flesh in our application code. Again, we won’t get into the
details of how to use B4I as you can get the full Monty
from the B4I website.
As you can see, following the conversion of incoming
bytes to an array, the command string (which is now an
array) is parsed. The code contained within the subroutine
astream_NewData uses the Boolean state of the Mini I/O
pin to determine the state of the physical Mini I/O pin.
when the application starts.
n SCREENSHOT 1. Visual Designer lets us lay out the buttons and views just
as we want them to be seen on the iPhone screen.
n PHONESHOT 1. This is an iPhone
screenshot of our application in a
disconnected state. Note the broken
red chain at the far left of the IP
address text box.
54 February 2018