Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Javax.comm Help!!!

Options
  • 06-04-2004 9:59pm
    #1
    Closed Accounts Posts: 11


    Hey,

    I am trying to use the code below to connect to a COM1 on my computer. When i run the program I is telling me that it cannot find the COM1 even though there is a modem on COM1.

    Any ideas???

    import java.util.*;
    import javax.comm.*;

    public class Dialer {

    static Enumeration portList;
    static CommPortIdentifier portId;
    static SerialPort serialPort;
    static boolean portFound = false;
    static String defaultPort = "COM1";

    public static void main(String[] args) {

    if (args.length > 0) {
    defaultPort = args[0];
    }

    portList = CommPortIdentifier.getPortIdentifiers();
    while (portList.hasMoreElements()) {
    portId = (CommPortIdentifier) portList.nextElement();
    System.out.print(portId + " port \n");
    if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
    if (portId.getName().equals("COM1")) {
    System.out.println("Found port " + defaultPort);
    portFound = true;
    try {
    serialPort = (SerialPort) portId.open("Dialer", 2000);
    } catch (PortInUseException e) {
    System.out.println("Port in use.");
    System.out.println(e.getMessage());
    }
    System.out.println("COM port found");
    }
    }
    }
    if (!portFound) {
    System.out.println("port " + defaultPort + " not found.");
    }
    }
    }


Comments

  • Registered Users Posts: 19,396 ✭✭✭✭Karoma


    post up the actual error (stacktrace)


  • Registered Users Posts: 491 ✭✭Justice


    jee that sounds like ur trying to fix a hardware problem with a pair of binoculars.

    anyway, u can have a modem on ur list of hardware but not have the relevent com port.

    check com ports in devicemanager. see if their function and have no conflicts

    if their not here and they arent picked up by plug an play then gluck :) you could add it manually but success of that is highly dependant on what the problem is (it aint gunna work if uve a genuine hardware problem)

    if their here then you could remove from device manager and reboot and pray.

    would the support board not be more suitable?

    [edit]only thought of it now, i assumed ur modem wasnt workin. if it is then totally disregard my post
    /me slaps forehead[/edit]


  • Registered Users Posts: 602 ✭✭✭soma


    When ever u are using the java comms API, if you get an error message that says "can't find com1" or "com1 doesn't exist", then nine times out of ten it is a problem with picking up your installation of the comms API from Sun.

    Sometimes putting the directory on the path is sufficient (e.g. making sure C:\javacomm20-win32\commapi\ is on the path) but sometimes you just *have* to dump the relevant files into your JDK installation directory as follows....

    >>>>
    Installing the Java Communications API on JDK 1.2
    <jdk> refers to the root directory of your JDK installation. If you installed JDK in c:\jdk1.2 then replace all reference to <jdk> with c:\jdk1.2.


    Windows: place the win32com.dll in <jdk>\jre\bin directory.

    Solaris: put the libSolarisSerialParallel.so in the LD_LIBRARY_PATH.

    Place the comm.jar in <jdk>\jre\lib\ext. (possibly just in jre\lib)

    Place the javax.comm.properties in <jdk>\jre\lib .


Advertisement