title: java jssc modem send msg
body: <p>I am trying to send text messages from Java/Netbeans using a cell modem based on the <a href="https://kuns-design.world.taobao.com/chip" rel="nofollow">SIM900</a>. Using TeraTerm, I verify that I can send messages using the modem with basic AT commands. The following code attempts to use <code>jssc</code> to send messages.<br>
  I do not get errors and the data appears to be written to the modem, but I never receive a text message.  For the phone number, I have tried both with an <code>+</code>, and without.<br>
  In TeraTerm, the number must be without the <code>+</code> to work. Many variations have been tried, and many <code>.println</code>'s used.  Still not making progress.<br>
  I hope someone can see the error of my ways.</p>
  
  <p>Thanks in advance. Doug</p>
  
  <pre><code>package jssc_test;
  
  import jssc.SerialPort; 
  import jssc.SerialPortException;
  import jssc.SerialPortList;
  
  public class Jssc_test {
  
      public static SerialPort serialPort=null;
  
      public static void main(String[] args) throws InterruptedException {
          try {
              String[] portNames = SerialPortList.getPortNames();
              for(int i = 0; i &lt; portNames.length; i++){
                  System.out.println(portNames[i]);
              }
  
              if(portNames.length &lt; 1){
                  System.out.println("No ports available");
                  System.exit(0);
              }
              else{
                  serialPort = new SerialPort(portNames[0]);
              }
              System.out.println("Port opened: " + serialPort.openPort());
              System.out.println("Params set: " + serialPort.setParams(9600, 8, 1, 0));
              System.out.println("\"Hello World!!!\" successfully writen to port: " + serialPort.writeBytes("Hello World!!!".getBytes()));
  
              serialPort.writeBytes(" AT+CMGF=1".getBytes());
              Thread.sleep(1000);
              System.out.println("bytes back = " + serialPort.readString());
              serialPort.writeBytes(" AT+CMGS=\"585*******\"".getBytes()); // \r = &lt;CR&gt;.  Tried both with and without '+'.  In TeraTerm, only works without +.  error if use: \r\n
              //Thread.sleep(1000);
              //System.out.println("bytes back = " + serialPort.readString());
              //serialPort.writeBytes("0x0D".getBytes()); // send &lt;CR&gt;
              Thread.sleep(1000);
              System.out.println("bytes back = " + serialPort.readString());
              serialPort.writeBytes("THIS IS A TEST from DS.".getBytes()); // placing Cntr-Z string in text did not work:  \u001A
              //serialPort.writeBytes("0x0D".getBytes()); // send &lt;CR&gt;
              serialPort.writeBytes("0x1A".getBytes()); // send &lt;ctrl&gt;Z
              Thread.sleep(1000);
              System.out.println("bytes back = " + serialPort.readString());
  
              System.out.println("Port closed: " + serialPort.closePort());
          }
          catch (SerialPortException ex){
              System.out.println(ex);
          }
      } // ******************* end main ***************
  
  } // *********************** end main class ***********************
  </code></pre>