Java Reference
In-Depth Information
void setStreams (DataInputStream inStream,
PrintStream outStream) {
fPortInStream = inStream;
fPortOutStream= outStream;
}
/** Start data taking. **/
public void start () {
if (fPortInStream!= null && fPortOutStream!= null) {
fTakeData = true;
Thread thread = new Thread (this);
thread.start ();
}
}
/** Stop data taking. **/
public void stop () {
fTakeData = false;
}
/**
*Inthis method data is obtained in a loop until the
* fTakeData flag goes false.
*Asimple protocol requires that it first sends a
* password value to the device using the sendPW ()
* method. If that value is accepted, then receiveInt ()
* gets two bytes from the data stream and returns a int
* value created from them. The loop pauses for a time
* set by fPauseTime parameter before getting the next
* value;
*/
public void run () {
fParent.println ("Begin reading data from port.");
// Now get data
do {
try {
// The "login"
if (!sendPW ()) return;
// Get the raw data from the serial connection.
int data = receiveInt ();
// Calibrate the data.
double correctedData = fSlope*data - fOffset;
// Print the corrected data on the Outputable
// parent.
fParent.println (
 
Search WWH ::




Custom Search