From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- .../hjp5/examples/Listing2604.java | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Master/Reference Architectures and Patterns/hjp5/examples/Listing2604.java (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/Listing2604.java') 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 -- cgit v1.2.3