Date: Tue, 8 Apr 2008 10:56:20 +0100 From: "Guilherme Gomes" <guilhermegrg@gmail.com> To: <freebsd-java@freebsd.org> Subject: Java Communication API for FreeBSD Input Stream Problem Message-ID: <000201c8995e$ce4c1f90$6402a8c0@laptop>
next in thread | raw e-mail | index | archive | help
Hi I've read a post about a program in Java that you're made regarding sending AT commands to a GSM phone to send SMS messages, and the trouble about sending the ctrl+z byte and after that getting no data returned. I have the exact same issue, and can't find any solution on the internet so far. Been losing a lot of hours on this. Did you managed to fix this issue ? If so, how ? I attach the text of your original message as a reminder : 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?000201c8995e$ce4c1f90$6402a8c0>