Can anyone solve this prob ...Prob is when I search for ports on my
system..I m getting some extra ports COM 16 17 although those doesnt
exists on the hardware manage window...only COM19 exists on Manage
Window


Native lib Version = RXTX-2.1-7
Java lib Version   = RXTX-2.1-7
Found port: COM1
        Trying at 19200...  Nobody here!
        Trying at 57600...  Nobody here!
Found port: COM16
        Trying at 19200...  Getting Info...  Found: AT+CGMMAAC-1052042-
BV
        Trying at 57600...  Getting Info...  Found: AT+CGMMAAC-1052042-
BV
Found port: COM17
        Trying at 19200...  Getting Info...  Found: AT+CGMMAAC-1052042-
BV
        Trying at 57600...  Getting Info...  Found: AT+CGMMAAC-1052042-
BV
Found port: COM18
        Trying at 19200...  Nobody here!
        Trying at 57600...  Nobody here!
Found port: COM19
        Trying at 19200...  Getting Info...  Found: AT+CGMMAAC-1052042-
BV
        Trying at 57600...  Getting Info...  Found: AT+CGMMAAC-1052042-
BV
BUILD SUCCESSFUL (total time: 44 seconds)



Here is the prog....

public class CommTest
{
        static CommPortIdentifier portId;
        static Enumeration portList;
        static int bauds[] = { 19200, 57600 };

    private Logger logger;

    public CommTest()
    {
        logger = Logger.getLogger(this.getClass());
    }
    public static void main(String args[])
    {
        CommTest ct = new CommTest();
        ct.testComPort();
    }
        public String testComPort_()
        {
                //System.out.println("testcommport \n");
        String status = "";
        boolean done = false;
        try{
        portList = CommPortIdentifier.getPortIdentifiers();
                while (portList.hasMoreElements())
                {
                        done=false;
            portId = (CommPortIdentifier) portList.nextElement();
                        if (portId.getPortType() == 
CommPortIdentifier.PORT_SERIAL)
                        {
                                System.out.println("Found port: " + 
portId.getName());
                                for (int i = 0; i < bauds.length; i++)
                                {
                                        System.out.print("      Trying at " + 
bauds[i] + "...");
                                        try
                                        {
                                                SerialPort serialPort;
                                                InputStream inStream;
                                                OutputStream outStream;
                                                int c;
                                                String response;
                                                serialPort = (SerialPort) 
portId.open("SMSLibCommTester", 1971);
                                                
serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_RTSCTS_IN);
                                                
serialPort.setSerialPortParams(bauds[i], SerialPort.DATABITS_8,
SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
                                                inStream = 
serialPort.getInputStream();
                                                outStream = 
serialPort.getOutputStream();
                                                
serialPort.enableReceiveTimeout(1000);
                                                c = inStream.read();
                                                while (c != -1)
                                                        c = inStream.read();
                        //System.out.println("------ c : "+c);
                                                outStream.write('A');
                                                outStream.write('T');
                                                outStream.write('\r');
                                                try
                                                {
                                                        Thread.sleep(1000);
                                                }
                                                catch (Exception e)
                                                {
                            logger.fatal(e.getMessage());
                                                }
                                                response = "";
                                                c = inStream.read();
                       // System.out.println("++++++++ c : "+c);
                                                while (c != -1)
                                                {
                                                        response += (char) c;
                                                        c = inStream.read();
                           // System.out.println("********* c : "+
(char)c);
                                                }
                        //System.out.println("\n\n\n response : "+
response.indexOf("OK"));
                                                if (response.indexOf("OK") >= 0)
                                                {
                                                        try
                                                        {
                                                                
System.out.print("  Getting Info...");
                                                                
outStream.write('A');
                                                                
outStream.write('T');
                                                                
outStream.write('+');
                                                                
outStream.write('C');
                                                                
outStream.write('B');
                                                                
outStream.write('M');
                                                                
outStream.write('M');
                                                                
outStream.write('\r');
                                                                response = "";
                                                                c = 
inStream.read();
                                                                while (c != -1)
                                                                {
                                                                        
response += (char) c;
                                                                        c = 
inStream.read();
                                    //System.out.println("##########
c : "+(char)c);
                                                                }
                                                                
System.out.println("  Found: " + response.replaceAll("\\s+OK\\s
+", "").replaceAll("\n", "").replaceAll("\r", ""));
                                done=true;
                                                        }
                                                        catch (Exception e)
                                                        {
                                                                
System.out.println("  Nobody here!");
                                logger.fatal(e.getMessage());
                                                        }
                                                }
                                                else System.out.println("  
Nobody
here!");
                                                serialPort.close();
                                        }
                                        catch (Exception e)
                                        {
                                                System.out.println("  Nobody 
here!");
                        logger.fatal(e.getMessage());
                                        }
                                }

                        }

            if(done==true) //status = status+"@"+ portId.getName();
                status = portId.getName();
                }// port iteration

        }// end of try
        catch(Exception e)
        {
            e.printStackTrace();
        }
        return status;
        }
    public String testComPort()
        {
                //System.out.println("testcommport \n");
        String status = "";
        boolean done = false;
        try{
        portList = CommPortIdentifier.getPortIdentifiers();
                while (portList.hasMoreElements())
                {
                        done=false;
            portId = (CommPortIdentifier) portList.nextElement();
                        if (portId.getPortType() == 
CommPortIdentifier.PORT_SERIAL)
                        {
                                System.out.println("Found port: " + 
portId.getName());
                                for (int i = 0; i < bauds.length; i++)
                                {
                                        System.out.print("      Trying at " + 
bauds[i] + "...");
                                        try
                                        {
                                                SerialPort serialPort;
                                                InputStream inStream;
                                                OutputStream outStream;
                                                int c;
                                                String response;
                                                serialPort = (SerialPort) 
portId.open("SMSLibCommTester", 1971);
                                                
serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_RTSCTS_IN);
                                                
serialPort.setSerialPortParams(bauds[i], SerialPort.DATABITS_8,
SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
                                                inStream = 
serialPort.getInputStream();
                                                outStream = 
serialPort.getOutputStream();
                                                
serialPort.enableReceiveTimeout(1000);
                                                c = inStream.read();
                                                while (c != -1)
                                                        c = inStream.read();
                        //System.out.println("------ c : "+c);
                                                outStream.write('A');
                                                outStream.write('T');
                                                outStream.write('\r');
                                                try
                                                {
                                                        Thread.sleep(1000);
                                                }
                                                catch (Exception e)
                                                {
                            logger.fatal(e.getMessage());
                                                }
                                                response = "";
                                                c = inStream.read();
                       // System.out.println("++++++++ c : "+c);
                                                while (c != -1)
                                                {
                                                        response += (char) c;
                                                        c = inStream.read();
                           // System.out.println("********* c : "+
(char)c);
                                                }
                        //System.out.println("\n\n\n response : "+
response.indexOf("OK"));
                                                if (response.indexOf("OK") >= 0)
                                                {
                                                        try
                                                        {
                                                                
System.out.print("  Getting Info...");
                                                                
outStream.write('A');
                                                                
outStream.write('T');
                                                                
outStream.write('+');
                                                                
outStream.write('C');
                                                                
outStream.write('G');
                                                                
outStream.write('M');
                                                                
outStream.write('M');
                                                                
outStream.write('\r');
                                                                response = "";
                                                                c = 
inStream.read();
                                                                while (c != -1)
                                                                {
                                                                        
response += (char) c;
                                                                        c = 
inStream.read();
                                    //System.out.println("##########
c : "+(char)c);
                                                                }
                                                                
System.out.println("  Found: " + response.replaceAll("\\s+OK\\s
+", "").replaceAll("\n", "").replaceAll("\r", ""));
                                done=true;
                                                        }
                                                        catch (Exception e)
                                                        {
                                                                
System.out.println("  Nobody here!");
                                logger.fatal(e.getMessage());
                                                        }
                                                }
                                                else System.out.println("  
Nobody here!");
                                                serialPort.close();
                                        }
                                        catch (Exception e)
                                        {
                                                System.out.println("  Nobody 
here!");
                        logger.fatal(e.getMessage());
                                        }
                                }

                        }

            if(done==true) //status = status+"@"+ portId.getName();
                status = portId.getName();
                }// port iteration

        }// end of try
        catch(Exception e)
        {
            e.printStackTrace();
        }
        return status;
        }

-- 
You received this message because you are subscribed to the Google Groups 
"SMSLib User Group" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/smslib?hl=en.

Reply via email to