Results 1 to 4 of 4
  1. #1
    glassball is offline Member
    Join Date
    Jan 2009
    Posts
    2
    Rep Power
    0

    Smile how to connect to sms modem?

    Hello,everyone here!
    I'm from China.
    Recently I hava been studying java on connecting to short message modem.
    I've download comm.jar from SUN Corporation website.
    I've got connected to the com terminal, but I haven't got connected to the modem.In addition,I can use the modem through the Hyper Terminal.
    If any one knows how to get connected with the modem,please tell me!Thank you very much!
    I'm wating for your reply.
    My E-Mail is: greencityvip@sinal.com
    The following is the codes:
    import java.util.*;
    import javax.comm.*;
    import java.io.*;
    public class com_read implements Runnable,SerialPortEventListener
    {
    static CommPortIdentifier portid;
    static Enumeration portlist;
    InputStream input;
    SerialPort serialport;


    public com_read()
    {
    try
    {
    serialport=(SerialPort)portid.open("SimpleReadApp" , 2000);
    }
    catch (PortInUseException e)
    {
    e.printStackTrace();
    }
    try
    {
    input=serialport.getInputStream();
    }
    catch (IOException e)
    {
    e.printStackTrace();
    }
    try
    {

    serialport.notifyOnDataAvailable(true);
    serialport.notifyOnBreakInterrupt(true);
    serialport.addEventListener(this);


    System.out.println("addlistener");
    }
    catch (TooManyListenersException e)
    {
    serialport.notifyOnDataAvailable(true);
    }
    try
    {
    serialport.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
    serialport.setFlowControlMode(SerialPort.FLOWCONTR OL_RTSCTS_IN | SerialPort.FLOWCONTROL_RTSCTS_OUT);
    //System.out.println(SerialPort.FLOWCONTROL_RTSCTS_O UT);
    //serialport.setDTR(true);

    }
    catch (UnsupportedCommOperationException e)
    {
    e.printStackTrace();
    }
    Thread thread=new Thread(this);
    thread.start();
    }


    public void run()
    {
    try
    {
    Thread.sleep(2000);
    }
    catch (InterruptedException e)
    {
    e.printStackTrace();
    }
    }


    public void serialEvent(SerialPortEvent event)
    {
    System.out.println("connecting");
    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:
    System.out.println("connecting");
    byte[] readBuffer = new byte[20];
    int numBytes=0;
    String readstr="";
    try
    {
    while (input.available() > 0)
    {
    numBytes = input.read(readBuffer);
    }
    String str=new String(readBuffer);
    for (int i=0;i<numBytes;i++)
    {
    //readstr=readstr+
    System.out.println(i);
    }
    System.out.print(new String(readBuffer));
    }
    catch (IOException e)
    {
    e.printStackTrace();
    }
    break;
    }
    }

    public static void main(String [] args)
    {
    portlist = CommPortIdentifier.getPortIdentifiers();


    while (portlist.hasMoreElements())
    {
    portid = (CommPortIdentifier) portlist.nextElement();
    if (portid.getPortType() == CommPortIdentifier.PORT_SERIAL)
    {
    System.out.println(portid.getName());
    if (portid.getName().equals("COM1"))
    {
    System.out.println("get com1");
    com_read reader = new com_read();
    }
    }
    }
    }


    }


    Zhou Qiang

  2. #2
    glassball is offline Member
    Join Date
    Jan 2009
    Posts
    2
    Rep Power
    0

    Default

    The E-Mail address above is invalid.
    It should be : greencityvip@sina.com

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    First of all, please you a dark color when you posting a code segment next time. The color you've selected is really hard to read. And also use code tags. Read the FAQ page for more details.

    More important thing is, this is a forum. You must try something and if you stuck with something please your question more clearly. This is not a code bank to do your projects. Lots of members are here ready to help you, but not in this way. :)

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,244
    Rep Power
    19

Similar Threads

  1. JMF: Cannot connect to device
    By jonsamwell in forum New To Java
    Replies: 2
    Last Post: 06-10-2011, 07:20 PM
  2. x modem protocol
    By jithan in forum New To Java
    Replies: 0
    Last Post: 08-21-2008, 10:43 AM
  3. how connect
    By herfnai in forum JDBC
    Replies: 1
    Last Post: 08-18-2008, 06:34 AM
  4. connect two applet
    By dg_iiita in forum Java Applets
    Replies: 0
    Last Post: 02-15-2008, 01:59 PM
  5. connect to MSDE
    By leonard in forum JDBC
    Replies: 1
    Last Post: 08-06-2007, 04:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •