diff options
Diffstat (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/Listing2604.java')
| -rw-r--r-- | Master/Reference Architectures and Patterns/hjp5/examples/Listing2604.java | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2604.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2604.java new file mode 100644 index 0000000..0a9568b --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2604.java @@ -0,0 +1,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);
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file |
