Java Reference
In-Depth Information
The input and output streams for the serial port are then obtained. The input
stream is wrapped as a DataInputStream and the output stream is wrapped
with a PrintStream .
...The getStreams() method in the class SerialToJavelin
...
/** Open the input and output streams **/
void getStreams () throws IOException {
fPortInStream =
new DataInputStream (fCurrentPort -- .getInputStream ());
fPortOutStream =
new PrintStream (fCurrentPort -- .getOutputStream (),
true);
}
When the user hits the " Go " button, the actionPerformed() method
is invoked again and the code section for the " Go " command invokes the
start() method in the GetJavelinData class. The complete listing of this
class is given here:
import java.io.*;
import javax.comm.*;
import java.util.*;
/**
* This program communicates over a serial port with the
* Javelin evaluation card. It obtains data values from
* the device following a simple protocol that involves
* first sending a "password" (a two byte number) and
* then reading two bytes at a time that are converted
*toanint primitive type value.
*
* The Javelin has been programmed to respond
* appropriately to the protocol used here. See
* Chapter 24 for information about the Javelin.
*
* The class is runnable so that the data taking loop
* runs in a thread.
*/
public class GetJavelinData implements Runnable
{
// These are the input and output streams over the port
DataInputStream fPortInStream;
Search WWH ::




Custom Search