Purpose
Provide an example of using REALBasic to use a U4x1 with OSX.
Description
The capabilities of the U4x1 allows it to interface to 1-wire temperature sensors. Dallas DS1822 sensors, specifically for this example. Other similar sensors could be used with minor code changes. This example assumes that there is a U401, U421, or U451 device on the Mac USB port and that the pins of port 1 are connected to DS1822 sensors.
Software
REALBasic is used, along with a package called MonkeyBread, to make this application. The MonkeyBread plug-in costs $28 at the time of this writing for the USB plug-in. This gives the REALBasic code writer a leg up on Mac USB interfacing.
The first task is to initialize the U4x1 structure. This looks for the first U4x1 and then connects to it. It also installs a callback for the reply messages.
Next is opening the specific U4x1 to communicate with, and grab a bunch of the device data.
Sending a USB message depends on more of the MonkeyBreak plug-in support. Here is code covering the transfer of data to the U4x1:
The Callback routine that stores the USB message content into a set of bytes:
These are some parts of a state machine that sends messages to the U4x1 device and processes the device replies:
The REALBasic code cycles through a large state machine scanning each of the DS1822 devices for temperature and putting the information in text boxes.
I cross-compile, so that is why this development window looks very much unlike OSX. 🙂