SMS App (Extension from Web-based CRM Module-Telephony)

All Case Experiences in Topic format. Easy reading mode for contextual understanding. Quickie snapshot and howtos Files are linked into http://compiere.red1.org/

Postby zam » Mon Sep 18, 2006 5:18 pm

Problem sorted. I think it's my coding that has somehow affected the outstream buffer. I used back the original SimpleWrite.java. Excluding the coding for reading modem response.

Code: Select all
import java.io.*;
import java.util.*;
import javax.comm.*;

public class SimpleWrite {
static Enumeration portList;
static CommPortIdentifier portId;
static SerialPort serialPort;
static OutputStream outputStream;
static InputStream inputStream;

static String messageString = "AT"+"+"+"CMGS=\"+60176377916\",145\rtest\032";

    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("COM1")) {
                //if (portId.getName().equals("/dev/term/a")) {
                    try {
                        serialPort = (SerialPort)
                            portId.open("SimpleWriteApp", 2000);
                    } catch (PortInUseException e) {}
                    try {
                        outputStream = serialPort.getOutputStream();
                    } catch (IOException e) {}
                    try {
                        serialPort.setSerialPortParams(9600,
                            SerialPort.DATABITS_8,
                            SerialPort.STOPBITS_1,
                            SerialPort.PARITY_NONE);
                    } catch (UnsupportedCommOperationException e) {}
                    try {
                        outputStream.write(messageString.getBytes());
                    } catch (IOException e) {}
                }
            }
        }
    }
}

I sent out
Code: Select all
static String messageString = "AT"+"+"+"CMGS=\"+60176377916\",145\r\ntest\032";

Msg received by recipient
Code: Select all
0est
*0 before e is actually a 0 with a horizontal line in the middle

It means that program is able to send only the message and not the whole AT Command. But the msg is sometimes being represented by weird characters. I guess the coding that caused such situation.

Will look on that.
zam
 
Posts: 49
Joined: Mon Jul 17, 2006 9:30 am

Postby red1 » Mon Sep 18, 2006 6:53 pm

Maybe u shuld do an outputStream.flush(); before the outputStream.write;
red1
Site Admin
 
Posts: 2760
Joined: Tue Jul 06, 2004 3:01 pm
Location: Kuala Lumpur, Malaysia

Postby sureshquest » Mon Sep 18, 2006 10:55 pm

Why do u use destination type = 145

Since it is a local number it should be 129 rite? did u try with 129 ?
sureshquest
Regular
 
Posts: 69
Joined: Wed Sep 15, 2004 11:09 pm
Location: India

Postby zam » Tue Sep 19, 2006 9:22 am

sureshquest wrote:Why do u use destination type = 145

Since it is a local number it should be 129 rite? did u try with 129 ?


Just to standardize the number..whereby by setting it to 145..all numbers will have to attach the country code as well..will try the 129

Updates:
Tested 129. I dont have to attach +60 in front of the handphone number of recipient
Last edited by zam on Tue Sep 19, 2006 12:39 pm, edited 1 time in total.
zam
 
Posts: 49
Joined: Mon Jul 17, 2006 9:30 am

Postby zam » Tue Sep 19, 2006 12:36 pm

As i said yesterday, I managed to send one SMS. Using the same coding, I tested it again, and no SMS being sent out. I think that program is not giving enough time for " outputStream.write(messageString.getBytes());" to process outputStream.write.

I debug the program.The program is running from line 1 till line of outputStream.write and instantly jump back to line 1 to do the next process.

So i insert a count loop below outputStream.write:
Code: Select all
outputStream.write(messageString.getBytes());
                           int count =100;
                           while (count<100)
                           {
                              count = count-1;
                           }

Few seconds after the program is run, SMS is received.

The issues I'm facing here are:
+ If i omit the count loop, possibility of SMS being sent out is nearly 0.
+ If i insert the count loop, SMS being sent comprises of the whole AT Command and not only the message.
zam
 
Posts: 49
Joined: Mon Jul 17, 2006 9:30 am

Postby zam » Tue Sep 19, 2006 1:02 pm

red1 wrote:Maybe u shuld do an outputStream.flush(); before the outputStream.write;


Nothing differs when I insert outputStream.flush()
zam
 
Posts: 49
Joined: Mon Jul 17, 2006 9:30 am

Postby sureshquest » Tue Sep 19, 2006 1:20 pm

zam wrote:As i said yesterday, I managed to send one SMS. Using the same coding, I tested it again, and no SMS being sent out. I think that program is not giving enough time for " outputStream.write(messageString.getBytes());" to process outputStream.write.

I debug the program.The program is running from line 1 till line of outputStream.write and instantly jump back to line 1 to do the next process.

So i insert a count loop below outputStream.write:
Code: Select all
outputStream.write(messageString.getBytes());
                           int count =100;
                           while (count<100)
                           {
                              count = count-1;
                           }

Few seconds after the program is run, SMS is received.

The issues I'm facing here are:
+ If i omit the count loop, possibility of SMS being sent out is nearly 0.
+ If i insert the count loop, SMS being sent comprises of the whole AT Command and not only the message.


1. Close the output stream after u write ur data.
2. If u need delay , use Thread.sleep, do not use while loop it is not a good practice.
sureshquest
Regular
 
Posts: 69
Joined: Wed Sep 15, 2004 11:09 pm
Location: India

Postby zam » Tue Sep 19, 2006 3:25 pm

I edited the code like below. Nothing seems to change. Message being sent is still the whole AT Command.
Code: Select all

try
{
     //outputStream.flush();
    outputStream.write(messageString.getBytes());
                          
    try
    {
       Thread.sleep(1000); 
    }
    catch(InterruptedException e)
   {
      //System.out.println("Thread");
   }
  outputStream.close();
}
zam
 
Posts: 49
Joined: Mon Jul 17, 2006 9:30 am

Postby sureshquest » Tue Sep 19, 2006 3:58 pm

Did u try write as 2 different statements?

1. Do a writeln for "AT"+"+"+"CMGS=\"+60176377916\",145"
2. Do a write for "test\032"

May be u need to put a Thread.sleep in between ur writes.
sureshquest
Regular
 
Posts: 69
Joined: Wed Sep 15, 2004 11:09 pm
Location: India

Postby zam » Tue Sep 19, 2006 4:05 pm

http://www.experts-exchange.com/Programming/Wireless_Programming/GSM/Q_20856444.html
http://discussion.forum.nokia.com/forum/showthread.php?t=54511
http://discussion.forum.nokia.com/forum/archive/index.php/t-25863.html

Based on some readings on the links above, I edited the code like below.

I initialized the AT Command strings as
Code: Select all
static String messageString = "AT"+"+"+"CMGS=\"0176377916\",129\r";
static String messageString2 = "\0test\032";

I put Thread.sleep in between the outputStream of both messageStrings. This is to give extra time for the first messageString to respond. If in hyperterminal, the insertion of the first messageString will be resulted with ">" character. On seeing the ">" then only message is inserted.
Code: Select all
                    try {
                            //outputStream.flush();
                           outputStream.write(messageString.getBytes());
                           try
                           {
                              Thread.sleep(1000); 
                           }
                           catch(InterruptedException e)
                           {
                              //System.out.println("Thread");
                           }
                           outputStream.write(messageString2.getBytes());
                          
                           try
                           {
                              Thread.sleep(1000); 
                           }
                           catch(InterruptedException e)
                           {
                              //System.out.println("Thread");
                           }
                           outputStream.close();
                       }


As for now, the problem has been solved.
zam
 
Posts: 49
Joined: Mon Jul 17, 2006 9:30 am

Postby zam » Wed Sep 20, 2006 12:28 pm

Problem : SimpleRead.java is not running properly. The process is terminated once being run.

Solution:
I found out that the reason for SimpleRead to be terminated is COM port is not properly closed from previous execution of SimpleRead or SimpleWrite, though I did stop all programs that might be using COM port before testing SimpleRead. So to overcome the incomplete close of port, I just closed the eclipse and open it back.

Problem Solved

Extra reading on SimpleWrite and SimpleRead:
http://www.experts-exchange.com/Program ... 12763.html
zam
 
Posts: 49
Joined: Mon Jul 17, 2006 9:30 am

Postby zam » Thu Sep 21, 2006 2:17 pm

I'm able to run SimpleRead. The port is listening but I do not know how will the program detect for incoming SMS. As when I send a message, nothing happens.
zam
 
Posts: 49
Joined: Mon Jul 17, 2006 9:30 am

Postby sureshquest » Thu Sep 21, 2006 2:38 pm

Can u receive sms using Hyperterminal in the first place ?
sureshquest
Regular
 
Posts: 69
Joined: Wed Sep 15, 2004 11:09 pm
Location: India

Postby zam » Thu Sep 21, 2006 4:08 pm

sureshquest wrote:Can u receive sms using Hyperterminal in the first place ?


i'm using AT+CMGL="REC UNREAD" to check for new msges. I can view them in a list. Besides CMGL, i used CMGR to read a particular msg.How do I make the hyperterminal as a listener like SimpleRead?
zam
 
Posts: 49
Joined: Mon Jul 17, 2006 9:30 am

Postby sureshquest » Thu Sep 21, 2006 6:28 pm

So did u do the CMGL command from the java as well?
sureshquest
Regular
 
Posts: 69
Joined: Wed Sep 15, 2004 11:09 pm
Location: India

Postby zam » Fri Sep 22, 2006 9:14 am

sureshquest wrote:So did u do the CMGL command from the java as well?

No, I did not.

This is the whole coding of SimpleRead. Please excuse the System.out.println. I just put them to help me in debugging the code.
Code: Select all
public class SimpleRead implements Runnable, SerialPortEventListener {
    static CommPortIdentifier portId;
    static Enumeration portList;

    InputStream inputStream;
    SerialPort serialPort;
    Thread readThread;
    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("COM1")) {
                  System.out.println("COM1");
                    SimpleRead reader = new SimpleRead();
                }
            }
        }
    }

    public SimpleRead() {
        try
        {
            serialPort = (SerialPort) portId.open("", 2000);
        }
        catch (PortInUseException e)
        {
           System.out.println("Port already in used");
        }
        try
        {
            inputStream = serialPort.getInputStream();
        }
        catch (IOException e)
        {
           System.out.println("inputStream");   
        }
       try
       {
            serialPort.addEventListener(this);
       }
       catch (TooManyListenersException e)
       {
          System.out.println("TooManyListenersException");
       }
       
       serialPort.notifyOnDataAvailable(true);
        try
        {
                serialPort.setSerialPortParams(9600,
                SerialPort.DATABITS_8,
                SerialPort.STOPBITS_1,
                SerialPort.PARITY_NONE);
        }
        catch (UnsupportedCommOperationException e)
        {
           System.out.println("UnsupportedCommOperationException");
        }
        readThread = new Thread(this);
        readThread.start();
    }

    public void run() {
       System.out.println("Ready to Read");
       try {
            Thread.sleep(20000);
        } catch (InterruptedException e) {}
    }

    public void serialEvent(SerialPortEvent event) {
        switch(event.getEventType()) {
        case SerialPortEvent.BI:
           System.err.println("Break Interrupt");
        case SerialPortEvent.OE:
           System.err.println("OE");
        case SerialPortEvent.FE:
           System.err.println("FE");
        case SerialPortEvent.PE:
           System.err.println("PE");
        case SerialPortEvent.CD:
           System.err.println("CD");
        case SerialPortEvent.CTS:
           System.err.println("Clear To Send");
        case SerialPortEvent.DSR:
           System.err.println("Data Set Ready");
        case SerialPortEvent.RI:
           System.err.println("Ring Indicator");
        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));
                System.out.print("Reading");
            } catch (IOException e)
            {
               System.out.println("IOException");
            }
            break;
        }
    }
}


Doesn't this portion of code help me in defining the available incoming SMS that being sent to me? If not, what will System.out.print(new String(readBuffer)); produce in the console?
Code: Select all
try {
                while (inputStream.available() > 0) {
                    int numBytes = inputStream.read(readBuffer);
                }
                System.out.print(new String(readBuffer));
            } catch (IOException e)
            {
               System.out.println("IOException");
            }
zam
 
Posts: 49
Joined: Mon Jul 17, 2006 9:30 am

Postby sureshquest » Fri Sep 22, 2006 11:06 am

I dont think there is any mechanism in GSM phones to automatically notify the attached COM ports.

SimpleWrite and SimpleRead is just example for how to write into COM port and how to read from COM port.

May be u don't need a Listener at all, u can just play with outputStream and InputStream.

Just send the CMGL command from ur simplewrite and get the inputstream and see what data comes thru that. Just enhance ur simplewrite and work on that. i dont think u really need to do a listener, there is no auto notification there. The only way is to poll the phone thru the COM port using CMGL command.
sureshquest
Regular
 
Posts: 69
Joined: Wed Sep 15, 2004 11:09 pm
Location: India

Postby zam » Fri Sep 22, 2006 11:19 am

sureshquest wrote:I dont think there is any mechanism in GSM phones to automatically notify the attached COM ports.

SimpleWrite and SimpleRead is just example for how to write into COM port and how to read from COM port.

May be u don't need a Listener at all, u can just play with outputStream and InputStream.

Just send the CMGL command from ur simplewrite and get the inputstream and see what data comes thru that. Just enhance ur simplewrite and work on that. i dont think u really need to do a listener, there is no auto notification there. The only way is to poll the phone thru the COM port using CMGL command.


if that's the case then i'll have to make the program keep on running while comparing the CMGL="REC UNREAD" right? As in VB, we normally use timer.
zam
 
Posts: 49
Joined: Mon Jul 17, 2006 9:30 am

Postby sureshquest » Fri Sep 22, 2006 11:21 am

Tht is correct
sureshquest
Regular
 
Posts: 69
Joined: Wed Sep 15, 2004 11:09 pm
Location: India

Postby zam » Fri Sep 22, 2006 5:38 pm

This is how i do to display the incoming SMS. And below is the outcome. But SMS-es being displayed will be based on the sleep time given. The longer the sleep time, more SMS will be displayed. So as what I used to do in VB, I'll have to split all the outcome by making +CMGL: as the delimeter.

Or better still if I can detect how many SMS-es are there in the list. Then it is easier for me to detect it by the index number fixed to each SMS.

Code: Select all
           try
                    {
                            outputStream.write(cmgl.getBytes());
                          
                           try
                           {
                              Thread.sleep(100);
                           }
                           catch(InterruptedException e){}
                           serialPort.getInputStream();
                           int n, i;
                           char c;
                          
                           String answer = new String("");
                           System.out.println("Reading ...");
                           try
                           {
                              Thread.sleep(1000);
                           }
                           catch(InterruptedException e){}
                           //while (!( serialPort.getInputStream().available()>0));
                           for (i = 0; i < 5; i++) {
                              while (serialPort.getInputStream().available()>0)
                              {
                                 n =  serialPort.getInputStream().read();
                                 if (n != -1) {
                                    c = (char) n;
                                    answer = answer + c;
                                  }else
                                    break;
                                 }
                              }
                           System.out.println(answer);
                           try
                           {
                              Thread.sleep(1000);
                           }
                           catch(InterruptedException e){}
                    }
                    catch(IOException e){}
                   


Code: Select all
+CMGL: 1,"REC READ","+60129365432",,"06/09/17,23:39:34+32"
If i x b the 1st person, let me b the last person to wish u happy birthday. Happy birthday zam. ;-)
+CMGL: 2,"REC READ","+60192824722",,"06/09/03,23:52:26+32"
?@ @  @ZAM, where r u? nizam here! i need some help! now, i'm in india! my hp doesnt hv roaming, dnt call it will reverse chrge! can u buy me some prepaid? i'll
+CMGL: 3,"REC READ","+353857171441",,"06/09/17,18:09:13+04"
Assalamualaikum,happy birthday!smoga dipanjangkn umor dlm keimanan,jadi anak yg solehah,dipertemukn jodoh yg baik,=D Doakn alang slalu yek!
+CMGL: 6,"REC READ","+60192824722",,"06/09/03,23:52:29+32"
?@ @ ­@ payback. here, this is my number. i'm using prepaid.
+CMGL: 8,"REC READ","+60166323610",,"06/09/21,23:09:43+08"
Zam kw blk kul 10 td.Nk siapkan keje esok xda rush2 sgt.Zam jom la half day esok.Gi matta hehe
+CMGL: 10,"REC READ","+60192824722",,"06/09/04,00:00:24+32"
its ok if u can't help me! anything, just sms, do


Tasks:
1) To do the splitting process
2) To do timer
zam
 
Posts: 49
Joined: Mon Jul 17, 2006 9:30 am

Postby zam » Mon Sep 25, 2006 1:19 pm

I'm trying to do a timer. Shamsul said timer in VB is different from timer in JAVA. He mentioned something on multithread and Runnable. Below is a sample of simplewrite n simpleread that implements Runnable
http://www.experts-exchange.com/Programming/Wireless_Programming/GSM/Q_20612763.html
Code: Select all
import java.io.*;
import java.util.*;
import javax.comm.*;

public class SimpleRead implements Runnable, SerialPortEventListener {
    static CommPortIdentifier portId;
    static Enumeration portList;
     static OutputStream outputStream;
    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"))
                 {
                    SimpleRead reader = new SimpleRead();
                 }
             }
         }
     }
    public SimpleRead() {
    try {
            serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
        } catch (PortInUseException e)
         {
          System.out.println("Port Already in Use");
          return;
          }
          try {
               serialPort.setSerialPortParams(9600,
                SerialPort.DATABITS_8,
                SerialPort.STOPBITS_1,
                SerialPort.PARITY_NONE);
        } catch (UnsupportedCommOperationException e) {}
        try
          {
               outputStream = serialPort.getOutputStream();
        } catch (IOException e) {}
          try {
            inputStream = serialPort.getInputStream();
        } catch (IOException e) {}
     try {
            serialPort.addEventListener(this);
     } catch (TooManyListenersException e) {}
          serialPort.notifyOnDataAvailable(true);
        readThread = new Thread(this);
        readThread.setDaemon(true);
        readThread.start();
    }
    public void run()
    {
             System.out.println("Ready to Read");
             SimpleWrite sw1= new SimpleWrite(outputStream);
           while(true)
            {
               try {
               
                    Thread.sleep(2000);
                  } catch (InterruptedException e) {
                              serialPort.close();
                    }
           }
     }
    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[220];
            try {
                while (inputStream.available()>0) {
                    int numBytes = inputStream.read(readBuffer);
                }
                    String str= new String(readBuffer);

                    if(str.indexOf("OK")!=-1 )
                         System.out.println("ok is there");
                    if(str.indexOf(">")!=-1 )
                         System.out.println("now enter the message");
                    if(str.indexOf("ERROR")!=-1 )
                         System.out.println("ERROR is there");
                    if(str.indexOf("CMGS")!=-1 )
                         System.out.println("message Sent");
                    if(str.indexOf("CMT") !=-1)
                    {
                              System.out.println("Message Recieved --- >" );
                              System.out.println(new String(readBuffer));
                    }
                   
            } catch (IOException e) {}
               
            break;
        }
    }
}

class SimpleWrite implements Runnable
{
     static String messageString = "ATE0\r";
     static String messageString1 = "AT+CMGF=1\r";
     static String messageString2 = "AT+CSCA=\"+919825001002\"\r";
     static String messageString33 = "AT+CNMI=1,2,0,0,0\r";
     static OutputStream outputStream;
     Thread t;
     SimpleWrite(OutputStream outputStream)
     {
           System.out.println("in the main constructor");
           this.outputStream=outputStream;
           t=new Thread(this);
           t.run();
      }
      public void run()
      {
         try {
              Thread.sleep(1000);
               outputStream.write(messageString.getBytes());
             Thread.sleep(500);
             outputStream.write(messageString1.getBytes());
             Thread.sleep(500);
             outputStream.write(messageString2.getBytes());
             Thread.sleep(10000);
              outputStream.write(messageString33.getBytes());
           }catch(IOException e) {System.out.println(e);}
           catch(InterruptedException e) {}
           while(true)
       {
           
             Thread.sleep(1000);
          } catch (Exception e) {System.out.println(e);}
      }
zam
 
Posts: 49
Joined: Mon Jul 17, 2006 9:30 am

Postby sureshquest » Mon Sep 25, 2006 2:05 pm

In java the timer is simple, just create a thread and loop tht forever and put a sleep inside periodically.
sureshquest
Regular
 
Posts: 69
Joined: Wed Sep 15, 2004 11:09 pm
Location: India

Postby sbahrin » Mon Sep 25, 2006 6:25 pm

I got the original SimpleRead source from zam. Here they are, and below it I want to explain what this codes are doing, before we can continue to the problem zam had.

Code: Select all
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("/dev/term/a")) {
                    SimpleRead reader = new SimpleRead();
                }
            }
        }
    }

    public SimpleRead() {
        try {
            serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
        } catch (PortInUseException e) {}
        try {
            inputStream = serialPort.getInputStream();
        } catch (IOException e) {}
        try {
            serialPort.addEventListener(this);
        } catch (TooManyListenersException e) {}
        serialPort.notifyOnDataAvailable(true);
        try {
            serialPort.setSerialPortParams(9600,
            SerialPort.DATABITS_8,
            SerialPort.STOPBITS_1,
            SerialPort.PARITY_NONE);
        } catch (UnsupportedCommOperationException e) {}
        readThread = new Thread(this);
        readThread.start();
    }

    public void run() {
        try {
            Thread.sleep(20000);
        } catch (InterruptedException 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) {}
            break;
        }
    }
   
}


Here are my explaination (or translation) -

SimpleRead is a class that implements SerialPortEventListener Therefore this class must override a method serialEvent(SerialPortEvent)

For every port in portList that has a name "/dev/term/a", a new SimpleRead object will be created. All these SimpleRead objects will be created almost at the same time, but one after the other, and all of them are keep alive together (running at the same time in their own process space) but shall ended after 20 seconds.

Object serialPort use this class SimpleRead as the EventListener. Therefore if it receives any SerialPortEvent it will invoke the method serialEvent(SerialPortEvent) of the class SimpleRead.

When method serialEvent is invoked, it will check on the type of SerialPortEvent. If the event is of the type DATA_AVAILABLE then it will read the inputstream and print it.
sbahrin
Regular
 
Posts: 81
Joined: Fri Dec 17, 2004 6:47 pm
Location: Malaysia

Postby zam » Tue Sep 26, 2006 10:10 am

sbahrin wrote:
Code: Select all
   
    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) {}
            break;
        }
    }
   
}




I'm able to run it and SimpleRead is using COM port to listen. But nothing happens. I do not know what type of "inputStream" that will be displayed on the console.

As for the SMS process, in order to read a msg, I need to write an AT command to the COM port (AT+CMGR or AT+CMGL="REC UNREAD").

As suggested by suresh, just modify the SimpleWrite. I have no problem in writing AT command to COM port. It is just that i need to code a "timer" so that the program will keep on looping to check for new SMS.

How do I go about it?
zam
 
Posts: 49
Joined: Mon Jul 17, 2006 9:30 am

Postby red1 » Tue Sep 26, 2006 10:33 am

Since Sam wana help in figuring out the timer, I think i and Zam figure out the RequestProcessor engine in Compiere.

I will show how to debug the source and locate the spot where Compiere sends out notice/email during Request submit. That is where we also do the SMS write.

That also mean we change the field or validation list in User window to accept also SMS besides those two methods.

Hopefully by then someone helps on the timer and we then figure out the Input or Read part where receiving users reply back to sms sent out by RequestProcessor.
red1
Site Admin
 
Posts: 2760
Joined: Tue Jul 06, 2004 3:01 pm
Location: Kuala Lumpur, Malaysia

PreviousNext

Return to Compiere Case Workshop

Who is online

Users browsing this forum: No registered users and 1 guest

cron