The following sample code demonstrates the implementation and capabilities of the Class WaveLinkFile and its associated methods.
Java Sample
/**
* This source code is for demonstration purposes only and should be treated as such.
*
* This application demonstrates the use of the various
* WaveLinkFile methods. It assumes a display area of 20x8.
* In practice, you should use a WaveLinkTerminal
* object to format output to fit the current device.
*
*/
import com.wavelink.clientui.*;
import java.io.*;
public class JavaFileDemo extends WaveLinkApplication {
public void WaveLinkMain(String[] args)
{
WaveLinkIO ioIface = new WaveLinkIO();
WaveLinkFile fileIface = new WaveLinkFile();
String strBuffer, csBuffer;
int nTmp;
// The following lines clear the display and output the
// app title in reverse video.
try {
ioIface.RFPrint(0, 0, " Welcome To The ", WaveLinkIO.WLCLEAR | WaveLinkIO.WLREVERSE);
ioIface.RFPrint(0, 1, " WaveLinkFile Demo ", WaveLinkIO.WLREVERSE);
ioIface.RFPrint(0, 3, "Hit a key to proceed", WaveLinkIO.WLNORMAL);
// Hide the cursor for a cleaner display
ioIface.RFPrint(0, 20, "", WaveLinkIO.WLNORMAL);
ioIface.GetEvent();
// The WaveLinkFile object provides an easy way for applications to store, retrieve, list,
// and delete files from the device. Sometimes it is desirable to determine if a
// particular file resides on the device. The use ofRFListFiles Method is the quickest and
// easiest method to do this.
fileIface.RFListFiles("*.*");
// To find a particular file, pass the file name as the parameter to RFListFiles:
// nFound = rfFil.RFListFiles ("Target.dat")
// Since we just wish to list the files on the current RF device, we used the wildcard notation ("*.*").
nTmp = fileIface.RFFileCount();
// It would have been quicker to use the return value from RFListFiles instead of an additional function call, but RFFileCount was used for demonstration purposes.
for ( int lcv = 0; lcv < nTmp; lcv++ ) {
if ( (lcv % 7) == 0 ) ioIface.GetEvent();
ioIface.RFPrint(0, 0, " RF Device Files: ", WaveLinkIO.WLCLEAR | WaveLinkIO.WLFLUSHOUTPUT);
ioIface.RFPrint(0, lcv+1,fileIface.RFFileName(lcv), WaveLinkIO.WLNORMAL);
}
ioIface.GetEvent();
// When it is necessary to store data files on the device, the WaveLinkFile object provides
// methods to store, retrieve, and delete them.
ioIface.RFPrint(0, 2, "Storing data file...", WaveLinkIO.WLCLEAR | WaveLinkIO.WLFLUSHOUTPUT);
strBuffer = "A string representing data to be"+"stored on a device!";
fileIface.RFStoreFile("FLDemo.dat", strBuffer);
ioIface.RFPrint (0, 3, "Getting data file...", WaveLinkIO.WLNORMAL | WaveLinkIO.WLFLUSHOUTPUT);
csBuffer = fileIface.RFGetFile("FLDemo.dat");
if ( strBuffer.equals(csBuffer) )
ioIface.RFPrint(0, 4, "Data Read Success!", WaveLinkIO.WLNORMAL);
else
ioIface.RFPrint(0, 4, "Data Read Failure!", WaveLinkIO.WLNORMAL);
ioIface.RFPrint(0, 6, " Hit a key! ", WaveLinkIO.WLREVERSE);
ioIface.RFPrint(0, 9, "", WaveLinkIO.WLNORMAL);
ioIface.GetEvent();
// Anytime an application changes the configuration of a device, it should return it to its
// original values during cleanup
fileIface.RFDeleteFile("FLDemo.dat");
// Each of these has its own methods for interacting with the device.
}
catch ( WaveLinkError wlErr ) {
//Do error handling
}
}
}
Was this article useful?
The topic was:
Inaccurate
Incomplete
Not what I expected
Other