1

データ「0x01」をパラレルポートに(書き込み)出力する必要があります。次のコードを使用してポートに書き込みますが、書き込みは行われず、プログラムが実行されるだけで何も起こりません。

import java.io.*;
import javax.comm.CommPortIdentifier;
import javax.comm.NoSuchPortException;
import javax.comm.ParallelPort;
import javax.comm.PortInUseException;

public class ParallelIO {

    private static OutputStream outputStream;
    private static InputStream inputStream;
    private static ParallelPort parallelPort;
    private static CommPortIdentifier port;
    static byte dat = 0x02;
    public static final String PARALLEL_PORT = "LPT1";

    public ParallelIO() {
        try {
            //detec the port
            System.out.println("Port : " + PARALLEL_PORT + " is detected");
            // get the parallel port connected to the output
            port = CommPortIdentifier.getPortIdentifier(PARALLEL_PORT);
            //port identified
            System.out.println("Port identified : " + port);
            // open the parallel port --
            //port(App name, timeout);
            parallelPort = (ParallelPort) port.open("0x0378", 50);
            //port opened
            System.out.println("Port opened : " + parallelPort);
            outputStream = parallelPort.getOutputStream();
            //get output
            System.out.println("Out put taken : " + outputStream);
            outputStream.write(dat);
            //data written
            System.out.println("Data Written : " + dat);
            outputStream.flush();
            outputStream.close();

        } catch (NoSuchPortException nspe) {
            System.out.println("\nPrinter Port LPT1 not found :     NoSuchPortException.\nException:\n" + nspe + "\n");
        } catch (PortInUseException piue) {
            System.out.println("\nPrinter Port LPT1 is in use : " +     "PortInUseException.\nException:\n" + piue + "\n");
        } catch (IOException ioe) {
            System.out.println("\nPrinter Port LPT1 failed to write : " + "IOException.\nException:\n" + ioe + "\n");
        } catch (Exception e) {
            System.out.println("\nFailed to open Printer Port LPT1 with exception : " + e +   "\n");
        } finally {
            if (port != null && port.isCurrentlyOwned()) {
                parallelPort.close();
            }
            System.out.println("Closed all resources.\n");
        }
    }

    public static void main(String[] args) {
        ParallelIO parr = new ParallelIO();
    }
}
4

1 に答える 1

0

comm.jar、win32.dll、および javax.comm.properties はありますか?

これらのファイルをこのパスに配置する必要があります

  1. Program Files\Java\jdk1.7.0_21\lib
  2. Program Files\Java\jdk1.7.0_21\bin
  3. Program Files\Java\jdk1.7.0_21\jre\bin
  4. Program Files\Java\jdk1.7.0_21\jre\lib
  5. Program Files\Java\jdk1.7.0_21\jre\lib\ext
于 2013-05-06T21:18:20.510 に答える