receive message from mobile to java program

Ads

 
 

Share on Google+Share on Google+

anand sp
receive message from mobile to java program
0 Answer(s)      6 years and 8 months ago
Posted in : Java Beginners

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;
    }
}

}

Ads
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, Lisha Ahuja
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
receive a ResultSet from a stored procedure
receive a ResultSet from a stored procedure  How do I receive a ResultSet from a stored procedure
how to delete a jar file from mobile by using j2me program.
how to delete a jar file from mobile by using j2me program.  When i'll update a new version jar in mobile. Then i want to delete that old jar which is previously present in mobile. How to do
How to send message in struts on mobile - Struts
How to send message in struts on mobile  Hello Experts, How can i send messages on mobile i am working on strus application and i want to send message from jsp
send sms from pc to mobile
send sms from pc to mobile  java program to send sms from pc to mobile
How to easily send and receive recorders from database (in AJAX)?
How to easily send and receive recorders from database (in AJAX)?   Hi all, I have a question, iam working in JAVA web application and can somebody please explain or give me an example how to send and receive recorders from
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
WAS server configuration from JAVA program
WAS server configuration from JAVA program  How to get web sphere server status like heap,connection pool properties,stall counts etc. from a java applciation
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
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
Java Message Services - JMS
Java Message Services  What is Java Message Services
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
send sms from pc to mobile via gsm modem connected to pc in java
send sms from pc to mobile via gsm modem connected to pc in java  pls send me the code to send sms from pc to mobile via GSM modem programmed in JAVA
mobile banking login program
mobile banking login program  static Display dis; static Login destroy; public Login() { dis=Display .get Display(this); } public void startApp() { destroy=this; LoginScreen
error message - Java Beginners
;Hi friend, To compile and run a java program we need to install java...error message  sir, while i m trying to execute my first program(print my name)I get error message like" javac is not recognized as internal
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
sending sms from laptop to mobile
sending sms from laptop to mobile   sending sms from laptop to mobile for multi users
sending sms from laptop to mobile
sending sms from laptop to mobile   sending sms from laptop to mobile for multi users
java program to insert data into a file and count the number of words from the file???????
java program to insert data into a file and count the number of words from the file???????  java program to insert data into a file and count the number of words from the file
Connect a linux machine from linux using java program without password
Connect a linux machine from linux using java program without password  Connect a linux machine from linux using java program without password. Can anyone help me
Java Message Service(JMS)
Java Message Service(JMS)       JMS (Java Message Service) is a Java API that allows java... queue and a consumer gets messages from the queue. Only one consumer
Java Message Services
Java Message Services      ... for developing programs using it. The java message services API is a java Message oriented... to a particular queue and a consumer reads message from the queue. The point-to-point
pop up message in java
an automatic message to change the password.how is it done??the forms are done using java...pop up message in java  hii..i have developed an application in which a login and registration form is there.when the registration is done the user
Java message services
; Java Message Services In this section, you will read about the java... and offers the basics for developing programs using it. The java message services API is a java Message oriented Middleware API for sending successfully the messages
java program to read multiple files from a directory and display them on a jframe
java program to read multiple files from a directory and display them on a jframe  hi guys i want to write a java program that will read all files in a directory and display them one by on on a jframe on jpanel with specific key
how to write to java program to get the particular data from the website
how to write to java program to get the particular data from the website   i have to get the particular data by selecting the just numbers.. from the site .. how to get the ful details from the website by clicking the number

Ads

 
Advertisement null

Ads