[Rxtx] Not reading any responses

Elliott Park sandmankz at yahoo.com
Thu Mar 4 12:51:47 MST 2010


Hi, everyone. I'm new to rxtx, and I'm having a weird problem. I've been
 trying to send AT commands to my phone and read its responses. I copied
 some sample code from another forum, corrected it a bit and started 
playing around with it. At first everything worked fine. I took about a 
month off this project, during which time my computer died and I 
upgraded to Windows 7 and had to download new drivers for my phone. Ever since then, I can't read any responses, not 
even on other windows machines. I was testing the program in Netbeans, 
but I tried running it from the command line as well. Not even python 
code is working for me. And none of the examples from the main rxtx site
 work for me.My best guess is that some other program is in the way, somehow. Why would this code work a month ago and not now? 
Other programs can read data from my serial ports. Please help. I'm at a loss. The code
 I've been using is
 included below:


import gnu.io.*;
import
 java.io.*;

public class rxtxtest
{
   
 public static void
 main(String[] args)
    {

            try
            {

               
 CommPortIdentifier portIdentifier = 
CommPortIdentifier.getPortIdentifier("COM5");
                
System.out.println(portIdentifier.getName());

                
if(portIdentifier.isCurrentlyOwned())
               
 {
                    System.out.println("Port is owned");
               
 }
                else
                {
                    
System.out.println("Port is not owned");
                    try
                   

 {

                        SerialPort serialPort = (SerialPort) 
portIdentifier.open("rxtxtest", 300);
                        
System.out.println("Name: " + serialPort.getName());
                       
 int baudRate = serialPort.getBaudRate();
                        
System.out.println("BaudRate: " + Integer.toString(baudRate));
                       

 try
                        {
                            
serialPort.setSerialPortParams(baudRate, SerialPort.DATABITS_8, 
SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
                            
                            
                           

 try
                            {
                               
 OutputStream mOutputToPort = serialPort.getOutputStream();
                               
 InputStream mInputFromPort = serialPort.getInputStream();

                               
 String mValue = "AT\r"; // AT
 Command
                                
                               
 System.out.println("beginning to Write " + mValue + "\r\n");
                               
 mOutputToPort.write(mValue.getBytes());
                               

 mOutputToPort.flush();
                                
System.out.println("Waiting for Reply \r\n");
                               
 try
                                {
                                   

 Thread.sleep(500);
                                    byte mBytesIn
 [] = new byte[20];
                                    
mInputFromPort.read(mBytesIn);
                                   
 mInputFromPort.read(mBytesIn);
                                    
String value = new String(mBytesIn);
                                   
 System.out.println("Response from Serial Device: "+value);

                                   

 mOutputToPort.close();
                                    
mInputFromPort.close();
                                    
                               
 }
                                catch (InterruptedException
 ex)
                                {
                                   
 System.out.println(ex.getMessage());
                               
 }
                                  
 
                                serialPort.close();


                           
 }
                            catch(IOException ex)
                           
 {
                                System.out.println("IOException" +
 ex.getMessage());
                            }
                       
 }
                        catch (UnsupportedCommOperationException 
ex)
                        {
                            
System.out.println("UnsupportedCommOperationException " +
 ex.getMessage());
                        }
                       
 
                    }
                    
catch(PortInUseException ex)
                    {
                       
 System.out.println("Port in
 use");
                    }
                }

           
 } catch (NoSuchPortException ex)
            {
                
System.out.println("Exception: NoSuchPortException " + ex.getMessage());
           
 }
        }
  

}


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qbang.org/pipermail/rxtx/attachments/20100304/c84de455/attachment-0845.htm>


More information about the Rxtx mailing list