Results 1 to 2 of 2
  1. #1
    maskey_dipesh is offline Member
    Join Date
    Sep 2009
    Posts
    2
    Rep Power
    0

    Default Serial port programming using modem and telephone

    Hello everyone,

    I am just trying my hands in Serial port programming using javax.comm package.

    I am sorry if I will not be able to explain you my scenario but I will try my best to explain my problem.

    I have 56k internal modem connected to my computer and its assigned with COM 6. Telephone is connected to the modem. I want to write a simple application which will hook the telephone after 2 ring and receive the message which is sent through the telephone line.

    I found few example in the internet but those examples cant hook the telephone. On the output screen it will only display as:

    RING

    RING

    RING

    RING

    On the another end, I have device which will dial to the phone number connected to my computer modem. What My device will expect is, my program needs to hook the call after 2 ring then it will send some message to my program.My program needs to hook the call after 2 ring and need to receive the message comming from device after 2 ring.

    One of the example is;

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

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

    static OutputStream outputStream;
    static InputStream inputStream;
    FileInputStream fis = null;
    SerialPort serialPort;
    Thread readThread;
    int ch;

    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")) {
    System.out.println("checked");
    // 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);
    serialPort.notifyOnCarrierDetect(true);
    serialPort.notifyOnDataAvailable(true);
    serialPort.notifyOnBreakInterrupt(true);
    serialPort.notifyOnCTS(true);
    serialPort.notifyOnDSR(true);
    serialPort.notifyOnFramingError(true);
    serialPort.notifyOnOutputEmpty(true);
    serialPort.notifyOnOverrunError(true);
    serialPort.notifyOnParityError(true);
    serialPort.notifyOnRingIndicator(true);
    try {
    serialPort.setSerialPortParams(9600,SerialPort.DAT ABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NO NE);
    } catch (UnsupportedCommOperationException e) {System.out.println(e);}
    readThread = new Thread(this);
    readThread.start();
    }

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

    public void serialEvent(SerialPortEvent event) {
    switch(event.getEventType()) {
    case SerialPortEvent.BI:

    System.out.println("Break Interrupt");
    break;
    case SerialPortEvent.OE:
    case SerialPortEvent.FE:
    case SerialPortEvent.PE:

    case SerialPortEvent.CTS:

    case SerialPortEvent.DSR:
    case SerialPortEvent.RI:



    System.out.println("Pick up the receiver.");
    if( event.getNewValue() )
    {
    System.out.println("Ring Indicator On");
    }
    else
    {
    System.out.println("Ring Indicator Off");
    }
    break;
    case SerialPortEvent.CD:

    if( event.getNewValue() )
    {
    System.out.println("Connected");

    }
    else
    {
    System.out.println("Disconnected");
    System.exit(0);
    }
    break;

    case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
    break;
    case SerialPortEvent.DATA_AVAILABLE:
    try {
    // outputStream.write("ata".getBytes());
    byte[] readBuffer = new byte[5048];


    while (inputStream.available() > 0) {
    // outputStream.write("ata".getBytes()); // to hook the phone
    // System.out.println("ram");
    int numBytes = inputStream.read(readBuffer);
    }

    System.out.print(new String(readBuffer));
    outputStream.write("ata".getBytes());

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

    It would be very helpful if anyone can help me in this issue.
    Thanks in advance.

  2. #2
    maskey_dipesh is offline Member
    Join Date
    Sep 2009
    Posts
    2
    Rep Power
    0

    Default still waiting for help

    guys,
    I am still waiting for the help.
    can anybody suggest me please.

Similar Threads

  1. Reading from Serial port!
    By Dogge in forum New To Java
    Replies: 2
    Last Post: 12-01-2010, 03:21 AM
  2. Serial Port
    By radhika in forum New To Java
    Replies: 5
    Last Post: 11-06-2009, 10:40 AM
  3. Replies: 4
    Last Post: 02-28-2009, 08:39 PM
  4. Accessing Serial port using JDK 1.6
    By hasani6leap in forum Advanced Java
    Replies: 5
    Last Post: 01-24-2009, 03:23 AM
  5. serial port
    By musiigedeo in forum Advanced Java
    Replies: 0
    Last Post: 07-23-2007, 04:52 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
  •