Daemon News Ezine BSD News BSD Mall BSD Support Forum BSD Advocacy BSD Updates

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Java Communication API for FreeBSD Input Stream Problem



Hi.

I have a problem regarding the Java Communication API for FreeBSD port.

One slight difference from a normal instalation of the JDK and the Java Communication port, is that i haven't installed the JDK. i have tried severel times to install it from the ports, but i got an error. (sorry, i can't provide you the error). I tried using the linux jdk allready installed, but when i try to install the Java Communication port i got an error regarding the jndi library. Anyway, i have copied a JDK instalation binaries from another FreeBSD machine, and then the comm port compiled and installed succesfully. I've just though i should mention this.

I have search the net for a solution to this matter, posted messeges on forums, but still nothing.

I'm a newbie regarding FreeBSD, but i think that it might be a problem in the libSerial.so module. A friend of mine suggested me to send you an email, so here it goes.

I have an aplication that connects to a mobile phone via serial port. I want then to send a SMS, using at commands. The problem is that the end of the SMS is marked by the CTRL-Z character (ASCII 26). When i send this character to the OutputStream, the InputStream hungs up. It shows that there are bytes available for read, but when i try to read from the stream, it returns -1. Other AT commands
are working fine.

The code is:
...
         props.load(new FileInputStream("sms.properties"));
         portName = props.getProperty("serial_port_name");
         center = props.getProperty("message_center");
         CommPortIdentifier portID = CommPortIdentifier.getPortIdentifier(
            portName);
         SerialPort port = (SerialPort) portID.open("Alarm Server", 100);
         port.setSerialPortParams(19200,
                                  SerialPort.DATABITS_8,
                                  SerialPort.STOPBITS_1,
                                  SerialPort.PARITY_NONE);
         port.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
         in =  port.getInputStream();
         out = new BufferedOutputStream(port.getOutputStream());
         Thread.sleep(3000);
...

private static String sendMessageText(String command) throws Exception {
           byte b = 0x1A;    //CTRL-Z character
           synchronized(sincron){
                   Logger.log("Sending: "+command);
                   out.write(command.getBytes());
                   out.write(b);
                   out.flush();
                   String response = read();
                   Logger.log("Response: "+response);
                   return response;
           }
   }

   private static String sendAT(String command) throws Exception {
      synchronized (sincron) {
         Logger.log("AT: "+command);
         out.write((command+"\r\n").getBytes());
         out.flush();
         String response = read();
         Logger.log("Response: "+response);
         return response;
      }
   }

   private static String read() throws Exception {
      int n, i;
      char c;
      String answer = new String("");
      System.out.println("Reading ...");
      do {
         Thread.sleep(100);
      }
      while (!(in.available()>0));
      for (i = 0; i < 5; i++) {
         while (in.available()>0) {
            System.out.println("Available: "+in.available());
            n = in.read();
            if (n != -1) {
               c = (char) n;
               answer = answer + c;
               Thread.sleep(1);
               Thread.sleep(1);
            }else
               break
            }
         }
         Thread.sleep(100);
      }
      return answer.trim();
   }

to send the SMS i use this code:

  public static void sendSMS(String number, String text) {
      String result;
      Logger.log("Trying to send to : " + number + "\n\t\t"
      sendAT("AT+CMGS=\"" + number + "\"");
      result = sendMessageText(text);
      Logger.log("I've got: " + result);
  }


normaly, it shoud return on the InputStream OK and a message number if the SMS was succesfully sent or ERROR if there was an error

after i send the CTRL-Z, the (InputStream) in.available() returns 20, and when i try to read it reads -1

if i use minicom (equivalent with windows's hyperterminal), it works just fine.


I realy don't know what to do. I have tried everything crossed my mind, and other's minds.

If you can take a look, and suggest a solution, i would apriciate it.

Sorry if i've waisted your time with this question.

Best Regards,
Daniel Comsa