Problem to listout the ports in javax.comm package

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rajujrk
    New Member
    • Aug 2008
    • 107

    #1

    Problem to listout the ports in javax.comm package

    hi, currently i am doing the project to send the sms from PC to Mobile and vice versa using GSM modem. I successfully done this process in Hyperterminal.

    First i connect the GSM modem in COM1 port

    then set the baud rate to 9600

    and execute the AT commands in hyperterminal and its works fine..

    But my problem is that to do the similar process in java..

    javax.comm package is used to interact with the ports..

    I used the below code

    Code:
            portList = CommPortIdentifier.getPortIdentifiers();
    
            while (portList.hasMoreElements()) {
                portId = (CommPortIdentifier) portList.nextElement();
                if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
                    if (portId.getName().equals("COM1")) {
                    //if (portId.getName().equals("/dev/term/a")) {
                        try {
                            serialPort = (SerialPort)
                                portId.open("SimpleWriteApp", 2000);
                        } catch (PortInUseException e) {}
                        try {
                            outputStream = serialPort.getOutputStream();
                        } catch (IOException e) {}
                        try {
                            serialPort.setSerialPortParams(9600,
                                SerialPort.DATABITS_8,
                                SerialPort.STOPBITS_1,
                                SerialPort.PARITY_NONE);
                        } catch (UnsupportedCommOperationException e) {}
                        try {
                            outputStream.write(messageString.getBytes());
                        } catch (IOException e) {}
                    }
                }
    But the problem is that results the port count is 0(Null).
    Please i need the solution.. Its Urgent..

    Thanks in Advance..
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Note that saying "It's urgent" doesn't help you much: it may be urgent to you but
    it isn't urgent to us and we won't hurry and treat you in a priviledged way because
    you mentioned your urgency; you'd better had started your project a bit earlier.

    w.r.t. your question: Sun's comm package only handles parallel and serial ports;
    it doesn't understand, nor recognizes any usb ports.

    kind regards,

    Jos

    Comment

    • rajujrk
      New Member
      • Aug 2008
      • 107

      #3
      Originally posted by JosAH
      Note that saying "It's urgent" doesn't help you much: it may be urgent to you but
      it isn't urgent to us and we won't hurry and treat you in a priviledged way because
      you mentioned your urgency; you'd better had started your project a bit earlier.

      w.r.t. your question: Sun's comm package only handles parallel and serial ports;
      it doesn't understand, nor recognizes any usb ports.

      kind regards,

      Jos
      But Even it didn't list out the PARALLEL and SERIAL ports

      Why?

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        What happens when you append a line (after line #4) like this:

        Code:
        System.out.println(portID.getName());
        Is anything printed at all?

        kind regards,

        Jos

        Comment

        • rajujrk
          New Member
          • Aug 2008
          • 107

          #5
          Originally posted by JosAH
          What happens when you append a line (after line #4) like this:

          Code:
          System.out.println(portID.getName());
          Is anything printed at all?

          kind regards,

          Jos

          AFter the Below Statement
          Code:
          portList = CommPortIdentifier.getPortIdentifiers();
          the getPortIdentifi ers() method return no values . So the below while says always false
          Code:
                  while (portList.hasMoreElements()) { 
                
                   }
          What happened in the getPortIdentifi ers() Method?

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by rajujrk
            What happened in the getPortIdentifi ers() Method?
            Did you properly install all three files? i.e. the jar in the lib/ext directory, the dll
            in the bin directory and the .properties file in the lib directory.

            kind regards,

            Jos

            Comment

            • rajujrk
              New Member
              • Aug 2008
              • 107

              #7
              Originally posted by JosAH
              Did you properly install all three files? i.e. the jar in the lib/ext directory, the dll
              in the bin directory and the .properties file in the lib directory.

              kind regards,

              Jos
              ya, i installed it in lib/ext

              I include the following files

              1. comm.jar
              2. javax.comm.prop erties

              What is the third file?

              I have another file as win32.dll

              Comment

              • JosAH
                Recognized Expert MVP
                • Mar 2007
                • 11453

                #8
                Store that .properties file in /lib instead. So:

                1) the .jar in /lib/ext
                2) the .properties in /lib
                3) the .dll in /bin

                Also read their installation notes.

                kind regards,

                Jos

                Comment

                • rajujrk
                  New Member
                  • Aug 2008
                  • 107

                  #9
                  Originally posted by JosAH
                  Store that .properties file in /lib instead. So:

                  1) the .jar in /lib/ext
                  2) the .properties in /lib
                  3) the .dll in /bin

                  Also read their installation notes.

                  kind regards,

                  Jos

                  Ya its working fine now..

                  I put .properties file in lib/ext

                  i change its loc to lib

                  Now its works fine

                  Thank you..

                  Comment

                  • Bharti Goel
                    New Member
                    • Dec 2011
                    • 1

                    #10
                    hi,

                    I am trying to do this same task. For me it is recognizing the ports but not sending the sms. It works fine via hyperterminal. Is it possible for you to send me your code?

                    Thanks a lot.

                    regards
                    Bharti

                    Comment

                    Working...