Java Communication API for FreeBSD Input Stream Problem

Comsa Daniel dano at
Tue Aug 31 16:57:16 PDT 2004


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 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(""));
          portName = props.getProperty("serial_port_name");
          center = props.getProperty("message_center");
          CommPortIdentifier portID = CommPortIdentifier.getPortIdentifier(
          SerialPort port = (SerialPort)"Alarm Server", 100);
          in =  port.getInputStream();
          out = new BufferedOutputStream(port.getOutputStream());

    private static String sendMessageText(String command) throws Exception 
            byte b = 0x1A;    //CTRL-Z character
                    Logger.log("Sending: "+command);
                    String response = read();
                    Logger.log("Response: "+response);
                    return response;

    private static String sendAT(String command) throws Exception {
       synchronized (sincron) {
          Logger.log("AT: "+command);
          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 {
       while (!(in.available()>0));
       for (i = 0; i < 5; i++) {
          while (in.available()>0) {
             System.out.println("Available: "+in.available());
             n =;
             if (n != -1) {
                c = (char) n;
                answer = answer + c;
       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 

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

More information about the freebsd-java mailing list