blob: 0a9568b57277f88e57df2d3fbdf961bc9f211118 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
/* Listing2604.java */
import java.util.*;
import java.io.*;
import javax.comm.*;
public class Listing2604
{
public static void printHello(Writer out)
throws IOException
{
String s = "Hello LPT1 World";
s += " " + s + " " + s;
for (int i = 1; i <= 50; ++i) {
out.write(s.substring(0, i) + "\r\n");
}
out.write("\f");
}
public static void main(String[] args)
{
Enumeration en = CommPortIdentifier.getPortIdentifiers();
while (en.hasMoreElements()) {
CommPortIdentifier cpi = (CommPortIdentifier)en.nextElement();
if (cpi.getPortType() == CommPortIdentifier.PORT_PARALLEL) {
if (cpi.getName().equals("LPT1")) {
try {
ParallelPort lpt1 = (ParallelPort)cpi.open(
"LPT1Test",
1000
);
OutputStreamWriter out = new OutputStreamWriter(
lpt1.getOutputStream()
);
printHello(out);
out.close();
lpt1.close();
System.exit(0);
} catch (PortInUseException e) {
System.err.println(e.toString());
System.exit(1);
} catch (IOException e) {
System.err.println(e.toString());
System.exit(1);
}
}
}
}
}
}
|