From owner-freebsd-java@FreeBSD.ORG Tue Aug 31 23:57:16 2004 Return-Path: Delivered-To: freebsd-java@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8090E16A4CF for ; Tue, 31 Aug 2004 23:57:16 +0000 (GMT) Received: from hawat.cc.ubbcluj.ro (Hawat.CC.UBBCluj.Ro [193.226.40.44]) by mx1.FreeBSD.org (Postfix) with ESMTP id B94EB43D1F for ; Tue, 31 Aug 2004 23:57:15 +0000 (GMT) (envelope-from dano@hawat.cc.ubbcluj.ro) Received: from hawat.cc.ubbcluj.ro (hawat [127.0.0.1]) by hawat.cc.ubbcluj.ro (8.13.1/8.13.1) with ESMTP id i7V9gTxR066087 for ; Tue, 31 Aug 2004 12:52:29 +0300 (EEST) (envelope-from dano@hawat.cc.ubbcluj.ro) Received: from localhost (dano@localhost)i7V9gTgV066084 for ; Tue, 31 Aug 2004 12:42:29 +0300 (EEST) (envelope-from dano@hawat.cc.ubbcluj.ro) Date: Tue, 31 Aug 2004 12:42:29 +0300 (EEST) From: Comsa Daniel To: freebsd-java@freebsd.org Message-ID: <20040831120745.L66028@hawat.cc.ubbcluj.ro> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Subject: Java Communication API for FreeBSD Input Stream Problem X-BeenThere: freebsd-java@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Porting Java to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 Aug 2004 23:57:16 -0000 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