Java Reference
In-Depth Information
To obtain the ADC value the program uses the DataPort class in the
com.dalsemi.system package. The system bus is mapped to memory so
that by specifying a memory address a particular device can be accessed. This
code in the Worker class:
DataPort p0 = new DataPort(0x380001);
// read ADC
int adcValue = p0.read();
first creates the DataPort object for the address specified in the constructor and
then reads the ADC value. The reading is combined with a hypertext header and
footer code to create an HTML file with the data. The Web Course provides a
link to a SNAP with its ADC connected to a device such as a solar panel voltage
output.
import java.net.*;
import java.io.*;
import java.util.*;
import com.dalsemi.system.*;
/** Modified Version of MicroServer for the Imsys
* SNAP card. **/
public class SnapAdcServer
{
/** Start program with optional port number argument. **/
public static void main (String args[]) throws
IOException {
int port; // port number
// Get the port number from the command line.
try {
port = Integer.parseInt (args[0]);
}
catch (Exception e) {
port = 2223; // Default
System.out.println ("Use default port = 2223");
}
// Create a ServerSocket object to watch that
// port for clients
ServerSocket server - socket = new ServerSocket (port);
System.out.println ( " Server started " );
// Loop indefinitely while waiting for clients
// to connect
 
Search WWH ::




Custom Search