receive message from mobile to java program
i got a code to receive message....but wen i receive it its showing a string which is not readable...
if possible please edit dis code to retreive the origianl string message....
here is the code
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("COM3")) {
// if (portId.getName().equals("/dev/term/a")) {
SimpleRead reader = new SimpleRead();
}
}
}
}
public SimpleRead() {
try {
serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
} catch (PortInUseException e) {System.out.println(e);}
try {
inputStream = serialPort.getInputStream();
} catch (IOException e) {System.out.println(e);}
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(20000);
} 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[20];
try {
while (inputStream.available() > 0) {
int numBytes = inputStream.read(readBuffer);
}
System.out.print(new String(readBuffer));
} catch (IOException e) {System.out.println(e);}
break;
}
}
}
View Answers
Ads
Related Tutorials/Questions & Answers:
receive message from mobile to java program
receive message from mobile to
java program i got a code to
receive message....but wen i
receive it its showing a string which is not readable...
if possible please edit dis code to retreive the origianl string
message....
here
java program to exchange soap message
that how can I write the server side
program in order to
receive the
message...
java program to exchange soap message Hi Friends,
I want... a set of 15 parameters and
program on web server side receives this 15 parameters
Advertisements
Sending and receiving xml message using Java Program
Sending and receiving xml
message using
Java Program Hi Friends,
I want to send and
receive xml files between two
java programs using wire format... sample
program to understand.
Thanks in advance.
Regards,
Atul Patil
Sending and receiving xml message using Java Program
Sending and receiving xml
message using
Java Program Hi Friends,
I want to send and
receive xml files between two
java programs using wire format... sample
program to understand.
Thanks in advance.
Regards,
Lisha Ahuja
connect ftp from java program
connect ftp
from java program Hi,
I need to connect to the ftp and get the files through a
java program..
I wrote the following code...
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile
connect ftp from java program
connect ftp
from java program Hi,
I need to connect to the ftp and get the files through a
java program..
I wrote the following code...
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile
send sms from pc to mobile via gsm modem in java
.....
can u pls help me to retrieve
message from mobile to
java program...
import...send sms
from pc to
mobile via gsm modem in java pls send me the code to send sms
from pc to
mobile via GSM modem
programmed in
JAVA
sms from pc to mobile
sms
from pc to mobile Sir I am developing a website and i need a code to send sms on any
mobile from the wbesite.pls help me. thanx in advance
sms from pc to mobile
sms
from pc to mobile Sir I am developing a website and i need a code to send sms on any
mobile from the wbesite.pls help me. thanx in advance
Opening a browser only with body from a java program
Opening a browser only with body
from a
java program Hi all,
I got... { //attempt to use Desktop library
from JDK 1.6+
Class<?> d = Class.forName...; Have a look at the following link:
http://www.roseindia.net/tutorial/
java
Compiling and Running Java program from command line
Compiling and Running
Java program from command line - Video tutorial
that explains you all steps necessary to compile and run the
Java program from
dos... of compiling and running
java
program from command line. We have also video
how to delete a jar from mobile
how to delete a jar
from mobile After auto updating a new version of jar
from server. I want to delete the old jar
from mobile and want to install the new jar which is present in server. Can u tell me the code how to do
how to delete a jar from mobile
how to delete a jar
from mobile After auto updating a new version of jar
from server. I want to delete the old jar
from mobile and want to install the new jar which is present in server. Can u tell me the code how to do
how to delete a jar from mobile
how to delete a jar
from mobile After auto updating a new version of jar
from server. I want to delete the old jar
from mobile and want to install the new jar which is present in server. Can u tell me the code how to do
how to delete a jar from mobile
how to delete a jar
from mobile After auto updating a new version of jar
from server. I want to delete the old jar
from mobile and want to install the new jar which is present in server. Can u tell me the code how to do
how to delete a jar from mobile
how to delete a jar
from mobile After auto updating a new version of jar
from server. I want to delete the old jar
from mobile and want to install the new jar which is present in server. Can u tell me the code how to do
how to delete a jar from mobile
how to delete a jar
from mobile After auto updating a new version of jar
from server. I want to delete the old jar
from mobile and want to install the new jar which is present in server. Can u tell me the code how to do
how to delete a jar from mobile
how to delete a jar
from mobile After auto updating a new version of jar
from server. I want to delete the old jar
from mobile and want to install the new jar which is present in server. Can u tell me the code how to do
how to delete a jar from mobile
how to delete a jar
from mobile After auto updating a new version of jar
from server. I want to delete the old jar
from mobile and want to install the new jar which is present in server. Can u tell me the code how to do
how to delete a jar from mobile
how to delete a jar
from mobile After auto updating a new version of jar
from server. I want to delete the old jar
from mobile and want to install the new jar which is present in server. Can u tell me the code how to do
how to delete a jar from mobile
how to delete a jar
from mobile After auto updating a new version of jar
from server. I want to delete the old jar
from mobile and want to install the new jar which is present in server. Can u tell me the code how to do
how to delete a jar from mobile
how to delete a jar
from mobile After auto updating a new version of jar
from server. I want to delete the old jar
from mobile and want to install the new jar which is present in server. Can u tell me the code how to do