Pre-made iButton cables

9 May

Pre-made iButton cables: During our discussion of port adapters, we mentioned that some of them have iButton retaining clips as their 1-Wire interface (DS1411, DS1413, DS1410E) and we mentioned something called iButton cables. These are the DS1402X MicroLAN cables. They come in a variety of lengths and a variety of different flavors. Some of the more relevant ones are shown below. The significance of these is that some have an RJ11 plug on one end and an iButton interface on the other, so they can be plugged into the iButton retaining clips in the port adapters that are meant for iButtons.

DS9092R iButton port. This is basically an empty iButton container with little tabs on it that you can solder to. In effect, you can solder wires to this and make your own
iButton cable, or your own iButton-like devices.

DS9092R Tabbed MicroCan
DS1401 iButton front panel holder. This is a strip with four or 24 iButton holders all interconnected on a 1-Wire bus. You can put an iButton cable into one of them and put iButtons in the others. It’s a way of mating an iButton cable to multiple devices.

Figure 10-30: DS1401 iButton front panel holder

The 1-Wire Java API
Throughout the previous discussion we’ve made mention of the 1-Wire Java API. In this section we will be looking at this API and a number of examples of how to use it.

The 1-Wire Java API, TMEX drivers, and these mysterious
things called port adapters

Before we go into the details of what’s inside the Java API, we need to talk a little about how the API talks to the 1-Wire bus. The API itself is actually one piece of a very interrelated, three-piece puzzle.

1.  The Java API provides high-level control over the MicroLAN and the 1-Wire devices found on it. It can be used alone to drive the 1-Wire bus provided you are using a port adapter based on a DS2480 Serial 1-Wire line driver. The DS2480 takes timing-independent, byte-based commands from the serial port and formats them into proper 1-Wire timing. The Java API relies on that formatting from either the DS2480 or an additional low-level device driver. Examples of port adapters that contain the DS2480 are the DS1411 and the DS9097U-09.

2.The Touch Memory Exchange, or TMEX, software provides a standalone Windows-based utility for examining devices on a 1-Wire net connected to a personal computer. There are three drivers that come as part of the TMEX software:  IB10E32.DLL, IB97E32.DLL, and the IB97U32.DLL. These drivers provide the TMEX Windows-based utility with their interface with the 1-Wire bus. They also can be used by the Java API to provide low-level access to the 1-Wire bus. Which driver Java uses depends on which port adapter you’re using.

•  IB10E32.DLL provides low-level control over the PC parallel printer port, normally referred to as LPT1, and subsequent communication with the 1-Wire bus through the use of a DS1410E parallel port adapter.

•  IB97E32.DLL provides low-level control over the PC serial ports, such as COM1, and subsequent communication with the 1-Wire bus through the use of serial port adapters such as the DS1413 and DS9097E. Note, these two port adapters do not contain active circuitry in the form of the DS2480 serial line driver chip. They are passive, and this driver is intended to work with that in mind.

•  IB97U32.DLL provides low-level control over the PC serial ports, such as COM1, and subsequent communication with the 1-Wire bus through the use of serial port adapters such as the DS1411 and DS9097U-09. These port adapters have the DS2480 serial line driver chip in them, taking care of the timeslot generation, and this driver takes this into account. If this driver is installed on your machine, the Java API will use it when trying to communicate with DS2480-based devices. If it is not installed, it will fall back to driving the serial port itself.

3. The port adapters themselves provide the electromechanical interface to the communication ports on the PC. As we’ve noted above, some have active circuitry in them in the form of the DS2480 that generates timing. These devices, the DS1411 and DS9097U-09, don’t need the TMEX drivers and can be used with the Java API alone. Other devices, such as the DS1413, DS9097E, and DS1410E, don’t have the DS2480 and need the help of a native driver.

Below is a chart that summarizes the port adapters and the drivers that support them.

Table 10-11: Port adapter, driver summary

So, how your software deals with low-level communications to the 1-Wire bus is actually a function of the port adapter that you are using and what you have installed on your computer. Here we have to bring up a word of caution: discussions of how the 1-Wire bus is being controlled often involve the phrase “port adapter” in different contexts with slightly different meanings. Sometimes “port adapter” means a piece of hardware that you connect on your computer and then connect the 1-Wire bus to. Other times, it means a Java software object in a program. We’ll try to put things in the proper perspective as we go and will touch upon this issue again, as needed, as we go through examples later. Now, let’s look at the 1-Wire Java API. We’ll start with a summary of the packages and classes.

Example: finding all 1-Wire devices on a specific port
The first example we’ll start with is a Java program that communicates with the 1-Wire bus and retrieves the 64-bit ROM ID of all the devices it finds on the bus. Let’s take a high-level look at how we’ll do it.

1. Read the port adapter to be used on the PC and the communication port it is to be connected to as command line arguments.
2. Create a port adapter object, using the DSPortAdapter class, and the OneWire AccessProvider class.

Figure 10-31: 1-Wire API packages and classes

3. Create an Enumeration of device containers, each an instance of the OneWireContainer class.
4. Loop over each element in the enumeration and for each element, create a OneWireContainer object.
5. Use methods in the OneWireContainer class to grab the ROM ID and device description. Print them.
6. Done!

Looking at this flow, four classes are interesting: DSPortAdapter, OneWireAccessProvider, Enumeration, and OneWireDeviceContainer. These classes are going to be a large part of many of our programs. Let’s talk about each one, and then we’ll look at the program and see it run.

The DSPortAdapter class
The DSPortAdapter class is an abstract class found in the Java 1-Wire API. As an abstract class, it can only be subclassed and can’t be instantiated. For instance, you can’t do the following:

DSPortAdapter myAdapter = new DSPortAdapter();

You’ll get a compiler error. You can however, declare DSPortAdapter objects in the following manner:

DSPortAdapter myAdapter = null;

Then, you can get access to the DSPortAdapter derivatives by using the OneWireAccessProvider class in the following manner:

myAdapter = OneWireAccessProvider.getPortAdapter(adapter_name, port_name);

The DSPortAdapter class has a few abstract methods—that is, methods that are not implemented and need to be implemented somewhere else—and many methods that are implemented. Some of the most useful ones are listed below. There are many others, and some that are similar to these, but take different arguments. Refer to the actual API documentation for the complete list.

Port and Port Adapter Related Methods
• public abstract boolean adapterDetected()
• public abstract String getAdapterName()
• public abstract Enumeration getPortNames()
• public abstract String getPortName()
• public abstract boolean selectPort( String port_name )
• public abstract void freePort()

Device Container Related Methods
• public Enumeration getAllDeviceContainers()
• public OneWireContainer getFirstDeviceContainer()
• public OneWireContainer getNextDeviceContainer()
• public OneWireContainer getDeviceContainer( String )

Search Related Methods
• public abstract boolean findFirstDevice()
• public abstract boolean findNextDevice()
• public String getAddressAsString()

Device Family Related Methods
• public void targetAllFamilies()
• public void targetFamily( int family )

The OneWireAccessProvider class
The OneWireAccessProvider class provides the object creation for the abstract DSPortAdapter class. It also provides several useful methods.

• public static Enumeration enumerateAllAdapters()
• public static DSPortAdapter getAdapter( String adapter, String port )
• public static DSPortAdapter getDefaultAdapter()

The Enumeration class
The Enumeration class isn’t strictly a 1-Wire thing, it’s also a Java thing. Instances of the Enumeration class represent a series of objects that can be sequenced through. Two useful methods:

• public boolean hasMoreElements()
• public Object nextElement()

The OneWireContainer class
Instances of the OneWireContainer class, OneWireContainer objects, represent specific devices on the 1-Wire bus. They can be thought of as encapsulating the specific port adapter being used, the 1-Wire device network address, and the methods used for dealing with the 1-Wire device. There are methods in this class that are applicable to any device.

• public String getName()
• public String getDescription()
• public String getAddressAsString()
• public boolean isPresent()

The OneWireContainer class has numerous subclasses, such as the OneWireContainer10 class that deals specifically with 1-Wire devices that have a family code (the first 8 bits of the ROM ID) of 10h. Devices in this family are all thermometer devices. The OneWireContainer10 class extends the OneWireContainer class and adds many methods that are specifically related to temperature measurement.

We’ve seen a general description of a program that will take in two command line parameters, the adapter name and the port name, and return the ROM ID codes of any 1-Wire devices on the bus as well as a description of those devices. We’ve just looked at the 1-Wire API classes that will be used in the program. Let’s now go through the program. First, we’ll present the entire program, then go though it line by line.


Listing 10-1: ROM_ID.java

import com.dalsemi.onewire.*;
import  com.dalsemi.onewire.adapter.*;
import  com.dalsemi.onewire.container.*;
import java.io.*;

import java.util.*;
public   class ROM_ID {
public static void main (String[] args) {
String                                                                      adapter_name = “”;
String                                                                      port_name            = “”;
DSPortAdapter myPortAdapter = null;
// Fetch the command line parameters if given
// adapter_name should be like {DS9097U} or DS9097U or
TINIExternalAdapter
if (args.length>0) { adapter_name = args[0]; }
// port_name should be like COM1, LPT1, /dev/ttyS0, or serial1
if (args.length>1) { port_name = args[1]; }
// Guess at defaults if the user didn’t specify
// Each operating system & platform is a little different.
if (adapter_name.length()<1) {
if (System.getProperty(“os.name”).indexOf(“slush”)!=-1) {
adapter_name = “TINIExternalAdapter”;
}
if (System.getProperty(“os.name”).indexOf(“Linux”)!=-1) {
adapter_name = “DS9097U”;
}
if (System.getProperty(“os.name”).indexOf(“Windows”)!=-1) {
adapter_name = “{DS9097U}”;
}
}
if (port_name.length()<1) {
if (System.getProperty(“os.name”).indexOf(“slush”)!=-1) {
port_name = “serial1”;
}
if (System.getProperty(“os.name”).indexOf(“Linux”)!=-1) {
port_name = “/dev/ttyS0”;
}
if (System.getProperty(“os.name”).indexOf(“Windows”)!=-1) {
port_name = “COM1”;
}
}
System.out.println( “Looking for “ + adapter_name + “ on “ + port_name );
try {
myPortAdapter =
OneWireAccessProvider.getAdapter(adapter_name, port_name);
System.out.println( “Found it!” );
}
catch (Exception e) {
System.out.println(e);

System.exit(0);
}
myPortAdapter.targetAllFamilies();
try {
myPortAdapter.beginExclusive(true);
Enumeration myContainers = myPortAdapter.getAllDeviceContainers();
while (myContainers.hasMoreElements()) {
OneWireContainer singleContainer =
(OneWireContainer)myContainers.nextElement();
System.out.println(“\nROM ID:
singleContainer.getAddressAsString());
System.out.println(“Device Name: “ + singleContainer.getName());
System.out.println(“Alternate Name: “ +
singleContainer.getAlternateNames());
System.out.println(“Description: \n” +
singleContainer.getDescription() + “\n”);
}
}
catch (Exception e) {
System.out.println(e);
System.exit(0);
}
}
}

First, we need to import the necessary libraries, and declare our class and the main() method.

import com.dalsemi.onewire.*;
import  com.dalsemi.onewire.adapter.*;
import  com.dalsemi.onewire.container.*;
import java.io.*;
import java.util.*;

public   class ROM_ID {
public static void main (String[] args) {

Next, we are going to declare some objects. Adapter_name and port_name are String objects that will represent the software port adapter we are using and the PC communication port we plan to connect to the 1-Wire bus, respectively. The DSPortAdapter, myPortAdapter, will be the object that represents our port adapter.

String  adapter_name = null;
String                                port_name   = null;
DSPortAdapter myPortAdapter = null;

The command line arguments are placed into our String objects. If no command line parameters are specified, then this block selects acceptable values and also shows the syntax. If you specify a PortAdapter name enclosed in curly braces then those are supported by the TMEX software; those not are those supported by the Java 1-Wire API directly. Note that there is no version of the native 1-wire PortAdapter for Linux so we need to use the Java 1-Wire API.

if (args.length>0) { adapter_name = args[0]; }
// port_name should be like COM1, LPT1, /dev/ttyS0, or serial1
if (args.length>1) { port_name = args[1]; }
if (adapter_name.length()<1) {
if (System.getProperty(“os.name”).indexOf(“slush”)!=-1) {
adapter_name = “TINIExternalAdapter”;
}
if (System.getProperty(“os.name”).indexOf(“Linux”)!=-1) {
adapter_name = “DS9097U”;
}
if (System.getProperty(“os.name”).indexOf(“Windows”)!=-1) {
adapter_name = “{DS9097U}”;
}
}
if (port_name.length()<1) {
if (System.getProperty(“os.name”).indexOf(“slush”)!=-1) {
port_name = “serial1”;
}
if (System.getProperty(“os.name”).indexOf(“Linux”)!=-1) {
port_name = “/dev/ttyS0”;
}
if (System.getProperty(“os.name”).indexOf(“Windows”)!=-1) {
port_name = “COM1”;
}
}
System.out.println( “Looking for “ + adapter_name + “ on “ + port_name );

Next, we need to set our DSPortAdapter object, myPortAdapter, to the DSPortAdapter returned by the OneWireAccessProvider.getAdapter() method. It takes our strings as arguments. Since this method throws the OneWireIOException and the OneWireException, we must either catch or specify these. We will catch these exceptions by enclosing this in a try/catch block.

try {
myPortAdapter = OneWireAccessProvider.getAdapter(adapter_name,
port_name);
} catch (Exception e) {
System.out.println(e);
System.exit(0);
}

We are interested in any 1-Wire device, so we must establish the fact that our search ROM process should look for all device families. This is done with the targetAllFamilies() method of the DSPortAdapter class.

myPortAdapter.targetAllFamilies();

The next section of code starts with the beginExclusive() method of the DSportAdapter class. This establishes the fact that the current program thread will get exclusive use of the 1-Wire bus to communicate with an iButton or 1-Wire Device. Following this, we create an Enumeration object, myContainers, and initialize it to contain all of the device container objects that can be found on the 1- Wire bus. These objects are found using the getAllDeviceContainers() method of the DSPortAdapter class. This method, and the beginExclusive() method both throw exceptions that must be caught or specified. We will catch them by putting them inside a try/catch block. Since the myContainers Enumeration is used throughout the rest of the program, the rest of the program must also be included in the same try/catch block, since they are only valid inside the block in which they were created.

try {
myPortAdapter.beginExclusive(true);
Enumeration myContainers = myPortAdapter.getAllDeviceContainers();

Next, we will loop through the Enumeration, once for each element, and create a single OneWireContainer object for each element. Then, we will use a series of methods to get at specific information about the OneWireContainer object. Since each OneWireContainer object basically represents a single 1-Wire device on the bus, that equates to getting information about the individual devices on the bus.

while (myContainers.hasMoreElements()) {
OneWireContainer singleContainer =
(OneWireContainer)myContainers.nextElement();
System.out.println(“\nROM ID:                                                              “ +
singleContainer.getAddressAsString());
System.out.println(“Device Name: “ +
singleContainer.getName());
System.out.println(“Alternate Name: “ +
singleContainer.getAlternateNames());
System.out.println(“Description: \n” +
singleContainer.getDescription() + “\n”);
}

Finally, we take care of any exceptions by catching them, printing them out, and exiting the program.

} catch (Exception e) {
System.out.println(e);
System.exit(0);
}
}
}

Earlier, we discussed the various Dallas Semiconductor components used to connect PC communications ports to the 1-Wire bus, such as the DS1410E, DS1413, and the DS9097U. We also mentioned that the Java API supports some of these directly, and some through the use of drivers found in the TMEX software (IB10E32.DLL, IB97E32.DLL, and IB97U32.DLL). In this program demo, we have all the drivers installed and the Java 1-Wire API. We’re going to communicate to the 1-Wire bus through the parallel port (LPT1) and the serial port (COM1). You may have different port names on your computer, but these are the ones that will be most commonly used. We also have on hand a DS1410E to connect the 1-Wire bus to the parallel port, and DS1411, DS1413, and some variety of DS9097U serial port adapters connect the COM1 serial port to the 1-Wire bus. Let’s start by querying the DS1410E connected to the LPT1 port. This device has spots for two iButtons, both of which are currently empty. The software “port adapter name” for this is the {DS1410E}. The curly brackets ( {} ) around the portAdapter name tells the 1-Wire API to use the TMEX native 1-Wire driver and the lack of curly braces means to the Java API 1-Wire drivers.

Note: We don’t show the compile command-line options (like CLASSPATH, etc.) here because they might be confusing if you don’t put your files in the same folder names that we did. If you use the CDROM, the build.bat will compile the code for you.

C:\> javac src\ROM_ID.java -d bin
C:\> cd bin
C:\> java   ROM_ID {DS1410E} LPT1

ROM ID:                                                                                 280000001B2BB881
Device Name: DS1990A
Alternate Name: DS2401
Description:
64 bit unique serial number

The DS1410E contains a DS1990A 64-bit silicon serial number embedded within it, and our search has picked up that device. Suppose we were to put a temperature iButton into one of the DS1410E iButton clips and run the program:

C:\> java   ROM_ID {DS1410E} LPT1
ROM ID:   F40000004B212B10
Device Name: DS1920
Alternate Name: DS1820
Description:

Digital thermometer measures temperatures from -55C to 100C in typi- cally 0.2 seconds. +/- 0.5C Accuracy between 0C and 70C. 0.5C standard resolution, higher resolution through interpolation.Contains high and low temperature set points for generation of alarm.

ROM ID:                                                                  280000001B2BB881
Device Name: DS1990A
Alternate Name: DS2401
Description:
64 bit unique serial number

It has now found the iButton placed in the DS1410E. Let’s move on and try using a DS1411 serial port adapter in COM1. It can hold one iButton. Let’s put a different temperature iButton in it and try running the program. The DS1411 can be interfaced with the TMEX driver or the driver found in the 1-Wire API. Let’s try the TMEX driver first; the syntax for that port adapter is {DS9097U}.

C:\> java ROM_ID {DS9097U} COM1
ROM ID:   EF0000004B224210
Device Name: DS1920
Alternate Name: DS1820
Description:
Digital thermometer measures temperatures from -55C to 100C in typi- cally 0.2 seconds. +/- 0.5C Accuracy between 0C and 70C. 0.5C standard resolution, higher resolution through interpolation.Contains high and low temperature set points forgeneration of alarm.

ROM ID:                                                                               8B00000293A1C009
Device Name: DS1982
Alternate Name: DS2502
Description:
1024 bit Electrically Programmable Read Only Memory (EPROM) parti- tioned into four 256 bit pages.Each memory page can be permanently write-protected to prevent tampering. Architecture allows software to patch data by supersending a used page in favor of a newly programmed page.

The temperature iButton was found, as well as a DS1982 EPROM device. The EPROM is embedded in the DS1411 to act as a user-programmable data space. Let’s try running it using the Java 1-Wire API driver. The syntax for specifying that port

adapter is DS9097U.
C:\> java ROM_ID DS9097U COM1
ROM ID:   EF0000004B224210
Device Name: DS1920
Alternate Name: DS1820
Description:

Digital thermometer measures temperatures from -55C to 100C in typi- cally 0.2 seconds. +/- 0.5C Accuracy between 0C and 70C. 0.5C standard resolution, higher resolution through interpolation.Contains high and low temperature set points forgeneration of alarm.
ROM ID:                                                                  8B00000293A1C009
Device Name: DS1982
Alternate Name: DS2502
Description:

1024 bit Electrically Programmable Read Only Memory (EPROM) parti- tioned into four 256 bit pages.Each memory page can be permanently write-protected to prevent tampering. Architecture allows software to patch data by supersending a used page in favor of a newly programmed page.

Once again, it found the iButton and the embedded memory. Let’s try using the DS1413 serial port adapter. The syntax for referring to its software port adapter is {DS9097E}. We’ll put the same temperature iButton that we used in the DS1411 into it.

C:\> java ROM_ID {DS9097E} COM1
ROM ID:   EF0000004B224210
Device Name: DS1920
Alternate Name: DS1820
Description:
Digital thermometer measures temperatures from -55C to 100C in typi- cally 0.2 seconds. +/- 0.5C Accuracy between 0C and 70C. 0.5C standard resolution, higher resolution through interpolation.Contains high and low temperature set points forgeneration of alarm.

The temperature iButton was found without any other devices. The DS1413 doesn’t contain any embedded 1-Wire devices in it for ID or memory storage. For the sake of argument, what do you think would happen if we tried to use the wrong software port adapter name when trying to communicate with it? Let’s try…

C:\> java ROM_ID {DS9097U} COM1

com.dalsemi.onewire.OneWireException: 1-Wire Net not available

It didn’t work. When we specify the {DS9097U} port adapter name, we’re telling the Java program to use the TMEX driver and look for a port adapter on COM1 that uses a DS2480 serial line driver for communication. That means it looks for a DS9097U or a DS1411.

Before we leave this example program, let’s try one more thing. We have a DS9097U Universal COM Port Adapter, and a small circuit board with four DS2406 1-Wire switches on it. Connecting the two, we have a 6” piece of telephone wire. The DS9097U port adapter can be accessed with the port adapter name of {DS9097U}, using the TMEX driver, or DS9097U, using the Java 1-Wire API. Let’s use the Java 1-Wire version.

Figure 10-32: Photo of Dallas Semiconductor LED board with DS9097U COM port adapter

Figure 10-33: Schematic of Dallas Semiconductor LED board with DS9097U COM port adapter

C:\> java ROM_ID DS9097U COM1
ROM ID:                                                                                   9E00000017844012
Device Name: DS2406
Alternate Name: Dual Addressable Switch, DS2407
Description:
1-Wire Dual Addressable Switch. PIO pin channel A sink capability of typical 50mA at 0.4V with soft turn-on; optional channel B typical 10 mA at 0.4V. 1024 bits of Electrically Programmable Read Only Memory (EPROM) partitioned into four 256 bit pages. 7 bytes of user-program- mable status memory to control the device.

ROM ID:                                           7F00000017841A12
Device Name: DS2406
Alternate Name: Dual Addressable Switch, DS2407
Description:
1-Wire Dual Addressable Switch. PIO pin channel A sink capability of typical 50mA at 0.4V with soft turn-on; optional channel B typical 10 mA at 0.4V. 1024 bits of Electrically Programmable Read Only Memory (EPROM) partitioned into four 256 bit pages. 7 bytes of user-program- mable status memory to control the device.

ROM ID:                                                                 0200000017461E12
Device Name: DS2406
Alternate Name: Dual Addressable Switch, DS2407
Description:
1-Wire Dual Addressable Switch. PIO pin channel A sink capability of typical 50mA at 0.4V with soft turn-on; optional channel B typical 10 mA at 0.4V. 1024 bits of Electrically Programmable Read Only Memory (EPROM) partitioned into four 256 bit pages. 7 bytes of user-program- mable status memory to control the device.

ROM ID:                                                                 9200000017473B12
Device Name: DS2406
Alternate Name: Dual Addressable Switch, DS2407
Description:
1-Wire Dual Addressable Switch. PIO pin channel A sink capability of typical 50mA at 0.4V with soft turn-on; optional channel B typical 10 mA at 0.4V. 1024 bits of Electrically Programmable Read Only Memory (EPROM) partitioned into four 256 bit pages. 7 bytes of user-program- mable status memory to control the device.

ROM ID:   D1000001B934D509
Device Name: DS1982
Alternate Name: DS2502
Description:
1024 bit Electrically Programmable Read Only Memory (EPROM) parti- tioned into four 256 bit pages.Each memory page can be permanently write-protected to prevent tampering. Architecture allows software to patch data by supersending a used page in favor of a newly programmed page.

It found four DS2406 devices and a DS1982 EPROM memory device. The four DS2406 devices correspond to the devices on the little circuit board and the DS1892 is embedded in the DS9097U itself.

394-Example: Finding devices by family on a specific port

Random Posts

Comments are closed.