File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other JSE/JEE APIs and the fly likes Send SMS by using Serial Port Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Send SMS by using Serial Port" Watch "Send SMS by using Serial Port" New topic
Author

Send SMS by using Serial Port

yousef atya
Greenhorn

Joined: May 29, 2009
Posts: 3
hi ......, Iam trying to develop a java application that use to pass At Commands to my mobile through using Java Communication API(serial port), in any way this application should send sms message by using AT Commands , this my program:

import java.io.*;
import java.util.*;
import javax.comm.*;

public class SimpleRead implements Runnable, SerialPortEventListener {
static CommPortIdentifier portId;
static Enumeration portList;

InputStream inputStream;
SerialPort serialPort;
Thread readThread;

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("COM6")) {
// if (portId.getName().equals("/dev/term/a")) {
SimpleRead reader = new SimpleRead();
}
}
}
}

public SimpleRead() {
try {
serialPort = (SerialPort) portId.open("SimpleReadApp",0);
} catch (PortInUseException e) {System.out.println(e);}
try {
inputStream = serialPort.getInputStream();
OutputStream out=serialPort.getOutputStream();

String line="";
line="AT"+"\r\n";
out.write(line.trim().getBytes());

line="";
line="AT+CPIN?"+"\r\n";
out.write(line.trim().getBytes());

line="";
line="ATD 0599281991;"+"\r\n";
out.write(line.trim().getBytes());
} catch (IOException e) {System.out.println(e);}
// catch(InterruptedException E){E.printStackTrace();}
try {
serialPort.addEventListener(this);
} catch (TooManyListenersException e) {System.out.println(e);}
serialPort.notifyOnDataAvailable(true);
try {
serialPort.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {System.out.println(e);}
readThread = new Thread(this);
readThread.start();
}

public void run() {
try {
Thread.sleep(200);
} catch (InterruptedException e) {System.out.println(e);}
}

public void serialEvent(SerialPortEvent event) {
switch(event.getEventType()) {
case SerialPortEvent.BI:
case SerialPortEvent.OE:
case SerialPortEvent.FE:
case SerialPortEvent.PE:
case SerialPortEvent.CD:
case SerialPortEvent.CTS:
case SerialPortEvent.DSR:
case SerialPortEvent.RI:
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
break;
case SerialPortEvent.DATA_AVAILABLE:
byte[] readBuffer = new byte[10];

try {
while (inputStream.available() > 0) {
int numBytes = inputStream.read(readBuffer);
}
System.out.println(new String(readBuffer));

} catch (IOException e) {System.out.println(e);}
break;
}
}
}

there is no error in this code , but nothing happen in the mobile , what I mean when I send "ATD anyphonenumber;" nothing happen
actually this command should call any phonenumber.

can any one tell me how I can solve this problem, please help me.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

Please Use Code Tags. You can edit your post to add them.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ranganath Junpal
Ranch Hand

Joined: Aug 31, 2006
Posts: 76
Hi,

Please first check if your mobile is connected to which port and try to execute the commands using the hyperterminal or Tera term com or minicom console. If you are able to communicate with your mobile from the console then there is some problem with your program may be its not able to detect the proper port..

Do let know which os are you using..


-R
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Send SMS by using Serial Port
 
Similar Threads
help using javax.comm api
unable to read the data from serial port in rfid
send SMS by using Serial Port
how can I send the output of a servlet to a jsp page?
sending sms through gsm modem