Building a Remote Data Logger in Java

Painting QR Code JIS X 0510 in Java Building a Remote Data Logger
7
Paint QR Code In Java
Using Barcode drawer for Java Control to generate, create QR Code image in Java applications.
Building a Remote Data Logger
Barcode Creation In Java
Using Barcode generation for Java Control to generate, create barcode image in Java applications.
Subclasses of LoggingDaemon implement the captureSample method to handle the details of collecting a single data sample This sample must be encapsulated within an object because it will be stored in a Vector The writeLogEntry method is used to write the individual elds contained in the sample object to the supplied instance of DataOutputStream LoggingDaemon s constructor is shown in Listing 74 The constructor requires the maximum number of samples to be held in the samples Vector along with the delay between consecutive samples The maxSamples eld is used to set the initial size of the Vector The delay is input to the constructor as a number of seconds The delay is converted to milliseconds so that it can be input directly into Thread s sleep method Finally the LoggingDaemon thread is set to a daemon thread This means that when the last non-daemon thread exits, LoggingDaemon will exit, along with any other daemon threads, allowing the process to terminate We do this because there isn t any point in continuing to log data if there isn t a server running to allow clients to download it Listing 74 LoggingDaemon s constructor
Bar Code Decoder In Java
Using Barcode recognizer for Java Control to read, scan read, scan image in Java applications.
import javaio*; import javautil*; public abstract class LoggingDaemon extends Thread { private int maxSamples; private int delay; private Vector samples; public LoggingDaemon(int maxSamples, int delay) throws LoggingException { thismaxSamples = maxSamples; // Convert delay from seconds to milliseconds thisdelay = delay * 1000; samples = new Vector(maxSamples); thissetDaemon(true); } public void stopLogging() { logEm = false; } }
QR Code JIS X 0510 Encoder In Visual C#.NET
Using Barcode printer for .NET Control to generate, create QR Code image in .NET applications.
stopLogging
QR Code 2d Barcode Maker In .NET Framework
Using Barcode generation for ASP.NET Control to generate, create QR Code JIS X 0510 image in ASP.NET applications.
method is shown in Listing 75 As long as the method is not invoked, the run method spins in an in nite loop collecting data samples at the speci ed interval
Encoding QR Code JIS X 0510 In .NET Framework
Using Barcode encoder for .NET Control to generate, create QR-Code image in .NET applications.
LoggingDaemon s run
Make QR Code JIS X 0510 In VB.NET
Using Barcode maker for VS .NET Control to generate, create QR Code image in .NET framework applications.
Collecting the Data Listing 75 LoggingDaemon s run method
DataMatrix Creation In Java
Using Barcode creation for Java Control to generate, create DataMatrix image in Java applications.
public void run() { while (logEm) { Object smp = captureSample(); if (smp != null) { synchronized (samples) { if (samplessize() == maxSamples) { // Remove the oldest entry samplesremoveElementAt(0); } samplesaddElement(smp); } } try { Threadsleep(delay); } catch (InterruptedException ie) {} } }
Barcode Creator In Java
Using Barcode generator for Java Control to generate, create bar code image in Java applications.
If the captureSample method returns null, there is no change in samples The method simply goes to sleep until it is time to try another sample This is a rather simplistic mechanism for handling errors that occur during data collection, but it is appropriate for our application Since every sample carries with it a time stamp, a client can determine that one or more samples were missed by simple analysis of the time stamps LoggingDaemon s writeLog method is shown in Listing 76 The writeLog method is invoked by the server when a client establishes a connection with the server, requesting a log of the recent data samples The writeLog method simply enumerates samples, invoking writeLogEntry for every data sample contained within the Vector The details of extracting and writing the actual eld data contained within the sample object are left to the subclass
Encoding UPCA In Java
Using Barcode generation for Java Control to generate, create GTIN - 12 image in Java applications.
Listing 76
Drawing Code 128 Code Set A In Java
Using Barcode generator for Java Control to generate, create Code-128 image in Java applications.
LoggingDaemon s writeLog method
UCC - 12 Encoder In Java
Using Barcode creation for Java Control to generate, create EAN / UCC - 13 image in Java applications.
public void writeLog(DataOutputStream dout) throws IOException { Vector sc = (Vector) samplesclone(); doutwriteInt(scsize()); for (Enumeration e = scelements(); ehasMoreElements(); ) { writeLogEntry(enextElement(), dout); } }
MSI Plessey Maker In Java
Using Barcode printer for Java Control to generate, create MSI Plessey image in Java applications.
Since we need to encapsulate the individual data readings within an object, we ll create a class named HumiditySample (shown in Listing 77) HumiditySample is just a thin wrapper on the sample data that provides public get methods for the individual elds HumiditySample s constructor takes the
Bar Code Generation In .NET
Using Barcode printer for .NET framework Control to generate, create bar code image in Visual Studio .NET applications.
7
ECC200 Creation In VS .NET
Using Barcode generation for .NET Control to generate, create Data Matrix ECC200 image in .NET framework applications.
Building a Remote Data Logger
Paint USS Code 128 In Visual C#
Using Barcode maker for .NET Control to generate, create USS Code 128 image in .NET framework applications.
readings attained using the HumiditySensor class and stores them in the temperature and relHumidity elds It also time stamps the readings using the SystemcurrentTimeMillis method, which returns the number of milliseconds between the current time and midnight, January 1, 1970 This is much simpler and faster for our purposes than storing the time stamp as a Date object We can put the burden of converting the timeStamp value to humanly readable date and time on the client program In the case that the client is written in Java, this job is trivial It can simply pass the timeStamp value received to the Date constructor that takes the long value returned from currentTimeMillis We ll make use of this in the next section, which presents a small sample client application Listing 77 HumiditySample
Creating UCC.EAN - 128 In VS .NET
Using Barcode encoder for Visual Studio .NET Control to generate, create EAN / UCC - 14 image in VS .NET applications.
public class HumiditySample { private double temperature; private double relHumidity; private long timeStamp; public HumiditySample(double relHumidity, double temperature) { thistemperature = temperature; thisrelHumidity = relHumidity; timeStamp = SystemcurrentTimeMillis(); } public long getTimeStamp() { return timeStamp; } public double getRelativeHumidity() { return relHumidity; } public double getTemperature() { return temperature; } }
Barcode Creator In .NET Framework
Using Barcode maker for Visual Studio .NET Control to generate, create bar code image in Visual Studio .NET applications.
Now that we have a simple framework for collecting, maintaining, and outputting a group of samples, we can create the class that performs the actual work of collecting individual samples The class HumidityLogger, shown in Listing 78, extends LoggingDaemon and provides implementations for the captureSample and writeLogEntry methods Listing 78 HumidityLogger
Barcode Decoder In Java
Using Barcode reader for Java Control to read, scan read, scan image in Java applications.
import javaioIOException; import javaioDataOutputStream;
Print Data Matrix 2d Barcode In VB.NET
Using Barcode generation for .NET Control to generate, create Data Matrix 2d barcode image in .NET framework applications.