9 Replies Latest reply on Feb 22, 2007 8:52 AM by 843790

    some problem Read/Write Serial Port for send SMS

      Hi I have some problem about communitaion Serial Port

      I use J2SE 5 and GPRS Modem (Motorola AT command). I need to send SMS by JAVA. But Motorola AT command need to refereance number for send Message. I can write only write to serial port but can't read from serial port. How to?

      Standard AT command of Motorola
      Test send message via AT command
      +CMGW: 119 OK at+cmss=119 +CMSS: 99 OK at+cmgd=119 OK
      when I type message will return number random (+CMGW: 119)

      This my code
      import java.io.*;
      import java.util.*;
      import javax.comm;
      public class SendSMS {
      static Enumeration portList;
      static CommPortIdentifier portId;
      static String commands[] ={"AT+CSCS=\"ASCII\"","AT+CMGW=\"0123456788\"","Hello there","AT+CMSS=141"};
      static byte newline=(byte)13;
      static byte newlinee=(byte)10;
      static SerialPort serialPort;
      static OutputStream outputStream;
      public static void main(String[] args) {
      portList = CommPortIdentifier.getPortIdentifiers();
      while (portList.hasMoreElements()) {
      portId = (CommPortIdentifier) portList.nextElement();
      if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL)
      if (portId.getName().equals("COM9")) //your comm port
      try {
      serialPort = (SerialPort)
      portId.open("SimpleWriteApp", 2000);
      } catch (PortInUseException e) {}
      try {
      //get the output stream
            outputStream = serialPort.getOutputStream();
      //write the commands string to the output stream
              for(int i=0;i<commands.length;i++)
      outputStream.write(commands[i].getBytes()); // write command
      outputStream.write(newline); //write new line

      } catch (IOException e) {}

      try {
                Thread.sleep(2000); // Be sure data is xferred before closing
                } catch (Exception e) {}

      This code can't send SMS because I don't know what number will return. It need founction for get return value.

      and I need to know about byte code for <Ctrl-Z>.

      Thank you for help me.