How TINI Communicates with the 1-Wire Bus

10 May

How TINI Communicates with the 1-Wire Bus: Our discussion of how the PC communicates with the 1-Wire bus involved a lot of talk about the different ports on the PC, hardware adapters that connected the 1-Wire bus to those ports, and the various different software drivers used by Java to communicate with the hardware adapters. Life is much simpler when discussing TINI. TINI comes with a 1-Wire bus that’s ready for you to connect to, and it has an associated Java API that contains classes that allow you to communicate with that bus. This API, the TINI API, is closely related to, and sometimes draws upon, the 1-Wire API.

There are actually two 1-Wire buses on TINI—an external 1-Wire bus and an internal
1-Wire bus. Let’s take a close look at each one, and then look at some examples.

The TINI external 1-Wire bus
The method by which TINI interfaces with the external 1-Wire bus is straightforward. Pins 18 and 19 on the 80C390 microprocessor communicate directly with a DS2480 serial 1-Wire line driver. The DS2480 outputs a signal, OWIO, which is routed to pin 8 on the TINI edge card connector. That signal, OWIO, is a 1-Wire bus. That’s all there is to it. The TINI E10/20 socketboard has an RJ11 modular jack on it for the external 1-Wire bus. You plug a category-5 1-Wire cable into the jack and you are ready to go. Also on the socketboard is an iButton connector (S2) and a jumper that can be used to connect the bus to power or ground.

Figure 10-36: Schematic highlights of the DS2480 portion

The TINI internal 1-Wire bus

The TINI stick has an internal 1-Wire bus, used for communication on the board itself. It talks to U11, which is a DS2502 memory and Ethernet address chip. It also controls the CPU status LED. The schematic shows that it also talks to an EEPROM, labeled U9. The TINI board rev E has silk-screening for the device, showing where it would be, but the board itself doesn’t appear to have traces for it. The internal 1-Wire bus can be controlled through software just like the external one and it is routed off the TINI board via pin 17 on the edge card connector. On the socketboard it connects to a jumper, J4, and J11, which is a diagnostic port.

Figure 10-38: Portions of the schematic showing the internal 1-Wire bus

TINI port adapter objects
In our discussion of how to use a PC to communicate with the 1-Wire bus, we had numerous choices as to what type of communication port to use, what type pf electrical hardware adapter to use to connect that to the 1-Wire bus, and what type of software driver to use with Java to communicate with the 1-Wire bus. With TINI, as we have said, things are a little different. The software port adapter for the external 1-Wire bus on TINI is called the TINIExternalAdapter, and its port name is serial1. Both of these are fixed. If we are going to use the external 1-Wire bus on TINI, those are what we will use and we don’t have to deal with choices or options and think about compatibility. The situation is similar with the TINI internal 1-Wire bus. Its port adapter name is TINIInternalAdapter and its port is called default. These are also both fixed.

The TINI API
We’ve taken a brief look at how the TINI board talks to the 1-Wire bus. Now let’s look at how to use the TINI API to talk to the 1-Wire bus. In general, most 1-Wire programs that work on the PC will work on TINI. There are just a few things you have to keep in mind when compiling them. Let’s start with a series of examples dealing with the port adapters.
Example: A Java program for TINI that identifies port adapters
In our discussion above, we made note of the fact that the port adapters for the internal and external 1-Wire buses on TINI are known and fixed. It is still a good first exercise to see for ourselves the names of these ports. We can run the same program (PortAdapters.java) on our TINI stick to see these names. Don’t forget to pass the PortAdapter.class file through TINIConvertor to create PortAdapters.tini:

Let’s take a look at the program actually running on a TINI.
C:\> javac -bootclasspath                                                                  %TINI_HOME%2d\bin\tiniclasses.jar
-d bin src\PortAdapters.java
C:\> java                                                                                  -classpath %TINI_HOME%\bin\tini.jar;. BuildDependency
-p                                                                                         %TINI_HOME%\bin\owapi_dependencies_TINI.jar
-f bin
-x                                                                                         %TINI_HOME%\bin\owapi_dep.txt
-o bin\PortAdapters.tini
-d %TINI_HOME%\bin\tini.db
FTP PortAdapters.tini to your TINI, and then run the program:
TINI /> java PortAdapters.tini
PortAdapter = TINIExternalAdapter; CommPorts = serial1
PortAdapter = TINIInternalAdapter; CommPorts = default
TINI />

There’s nothing surprising about the results of this program, or how it works, but since port adapter objects are the foundation for communication with the 1-Wire bus, it’s important to understand them. With that in mind, we’re going to continue to look at a few simple programs that illustrate how to set up communications with the TINI 1-Wire buses. The first illustrates the default port adapter on TINI.
Example: Determining the default port on TINI
Even though our external and internal 1-Wire buses on TINI have fixed port adapters and ports, there is still a default port adapter. Again, we can use a previously written program to illustrate this. Compile DefaultAdapter.java and run it on your TINI stick to see these names. Don’t forget to pass the .class file through BuildDependency to create the .tini file.

C:\> javac -bootclasspath                                       %TINI_HOME%2d\bin\tiniclasses.jar
-d bin src\DefaultAdapter.java
C:\> java                                                       -classpath %TINI_HOME%\bin\tini.jar;. BuildDependency
-p                                                              %TINI_HOME%\bin\owapi_dependencies_TINI.jar
-f bin
-x                                                              %TINI_HOME%\bin\owapi_dep.txt
-o bin\PortAdapters.tini
-d %TINI_HOME%\bin\tini.db
FTP PortAdapters.tini to your TINI, and then run the program:
TINI /> java DefaultAdapter.tini
TINIExternalAdapter
serial1
TINI />

There’s nothing surprising about the results of this program, or how it works, but since port adapter objects are the foundation for communication with the 1-Wire bus, it’s important to understand them. With that in mind, we’re going to continue to look at a few simple programs that illustrate how to set up communications with the TINI 1-Wire buses. The first illustrates the default port adapter on TINI.

Example: Determining the default port on TINI
Even though our external and internal 1-Wire buses on TINI have fixed port adapters and ports, there is still a default port adapter. Again, we can use a previously written program to illustrate this. Compile DefaultAdapter.java and run it on your TINI stick to see these names. Don’t forget to pass the .class file through BuildDependency to create the .tini file.

C:\> javac -bootclasspath                                       %TINI_HOME%2d\bin\tiniclasses.jar
-d bin src\DefaultAdapter.java
C:\> java                                                       -classpath %TINI_HOME%\bin\tini.jar;. BuildDependency
-p                                                              %TINI_HOME%\bin\owapi_dependencies_TINI.jar
-f bin
-x                                                              %TINI_HOME%\bin\owapi_dep.txt
-o bin\PortAdapters.tini
-d %TINI_HOME%\bin\tini.db
FTP PortAdapters.tini to your TINI, and then run the program:
TINI /> java DefaultAdapter.tini
TINIExternalAdapter
serial1
TINI />

What this tells us is that the default port for TINI is the TINIExternalAdapter, on port serial1, which is on the external 1-Wire bus. Next, let’s take a look at a simple program that looks at the 1-Wire bus on TINI and determines the ROM ID for every 1-Wire device present.

Example: Determining the ROM ID for all 1-Wire devices attached to TINI
We’ve already looked at a similar program for doing this on the PC, and we could actually use that program here just as well, but we’re going to review this a little because it provides us an example of the different ways of declaring and creating DSPortAdapter objects for TINI. If you like, you can pass the ROM_ID.class through TINIConvertor. Or better yet, BuildDependency and -add all of the OneWireContainer types (ie: OneWireContainer10 or Thermometers to get all temperature sensors) that you know you have connected. Then try running ROM_ID on your TINI. You will need to properly specify the PortAdapter and CommPort for TINI.

TINI /> java ROM_ID.tini TINIExternalAdapter serial1
or
TINI /> java ROM_ID.tini TINIInternalAdapter default

This clearly shows how you can write Java programs that use the 1-Wire API that will compile and run on both your PC and TINI with no modification. You can simplify your Java quite a bit if you only intend to run your programs on a TINI. This will also help save valuable memory space for other functions. A specialized version of ROM_ID (called TINIROM_ID) program is presented below in its entirety, then explained. Also a sample output is shown.

Listing 10-8: TINIROM_ID.java
import com.dalsemi.onewire.*;
import  com.dalsemi.onewire.adapter.*;
import  com.dalsemi.onewire.container.*;
import java.io.*;
import java.util.*;
public   class TINIROM_ID {
public static void main (String[] args) {
DSPortAdapter singleAdapter = null;
OneWireContainer singleContainer = null;
String singlePort = null;
Enumeration myAdapters = null;
Enumeration myPorts = null;
Enumeration myContainers = null;
myAdapters = OneWireAccessProvider.enumerateAllAdapters();
while (myAdapters.hasMoreElements()) {
singleAdapter = (DSPortAdapter)myAdapters.nextElement();
System.out.println(“Adapter Name: “ + singleAdapter.getAdapterName());
myPorts = singleAdapter.getPortNames();
while (myPorts.hasMoreElements()) {
singlePort = (String)myPorts.nextElement();
System.out.println(“Port Name: “ + singlePort);
try {
singleAdapter.selectPort(singlePort);
singleAdapter.targetAllFamilies();
myContainers = singleAdapter.getAllDeviceContainers();
while (myContainers.hasMoreElements()) {
singleContainer =
(OneWireContainer)myContainers.nextElement();
System.out.println(“ROM ID:
singleContainer.getAddressAsString());
}
singleAdapter.freePort();
} catch (Exception e) {}
}
System.out.println();
}
}
}

Our program begins with the usual import statements, class declaration, and main() method declaration. We declare a number of objects: a DSPortAdapter, a OneWireContainer, and three Enumerations. We’re going to grab an Enumeration of all the adapters present, then grab an Enumeration of all ports on the adapter, then grab an Enumeration of all device containers present on that adapter/port pair.

import com.dalsemi.onewire.*;
import  com.dalsemi.onewire.adapter.*;
import  com.dalsemi.onewire.container.*;
import java.io.*;
import java.util.*;
public   class TINIROM_ID {
public static void main (String[] args) {
DSPortAdapter singleAdapter = null;
OneWireContainer singleContainer = null;
String singlePort = null;
Enumeration myAdapters = null;
Enumeration myPorts = null;
Enumeration myContainers = null;

Here, we’re creating the Enumeration of port adapters, and iterating over each element in that Enumeration. For each one, we print out its name.

myAdapters = OneWireAccessProvider.enumerateAllAdapters();
while (myAdapters.hasMoreElements()) {
singleAdapter = (DSPortAdapter)myAdapters.nextElement();
System.out.println(“Adapter Name: “ +
singleAdapter.getAdapterName());

Here, we’re creating the Enumeration of port names relevant to the particular port adapter in question. We iterate over this Enumeration and print out the name for each.

myPorts = singleAdapter.getPortNames();
while (myPorts.hasMoreElements()) {
singlePort = (String)myPorts.nextElement();
System.out.println(“Port Name: “ + singlePort);

Now, we select the given port, tell the 1-Wire bus that any search ROM should include all device families, and create an Enumeration of device containers corresponding to all the devices found on the bus. For each device container, we access its ROM ID and print it.

try {
singleAdapter.selectPort(singlePort);
singleAdapter.targetAllFamilies();
myContainers = singleAdapter.getAllDeviceContainers();
while (myContainers.hasMoreElements()) {
singleContainer  =  (OneWireContainer)myContainers.nextElement();
System.out.println(“ROM ID:                                                              “ +
singleContainer.getAddressAsString());
}
singleAdapter.freePort();
} catch (Exception e) {}
}
System.out.println();
}
}
}
A sample run of this program on TINI looks like this:
C:\> javac -bootclasspath                                                                %TINI_HOME%\bin\tiniclasses.jar
-d bin src\TINIROM_ID.java


C:\> java                    -classpath %TINI_HOME%\bin\tini.jar;. BuildDependency
-p                           %TINI_HOME%\bin\owapi_dependencies_TINI.jar
-f bin
-x                           %TINI_HOME%\bin\owapi_dep.txt
-o bin\TINIROM_ID.tini
-d %TINI_HOME%\bin\tini.db

FTP the ROM_ID.tini to your TINI, and then run the program:

TINI /> java TINIROM_ID.tini
Adapter Name: TINIExternalAdapter
Port Name: serial1
ROM ID:   EF0000004B224210
ROM ID:                                                       9A0000000C152305
Adapter Name: TINIInternalAdapter
Port Name: default
ROM ID:   D45E70005C8FAA89
TINI />

The program above can be compiled and run unmodified on a PC. There’s nothing TINI-specific about it. Our next example is a modified version of this that is TINI- specific. Its purpose is to show us how to access the TINIExternalPortAdapter and TINIInternalPortAdapter objects.

Random Posts

Comments are closed.