Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Serail Port Programming regarding phone line hook

  1. #1
    Junior Member
    Join Date
    Sep 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up Serail Port Programming regarding phone line hook

    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.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(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.
    Last edited by Freaky Chris; September 2nd, 2009 at 07:52 AM. Reason: Added code tags


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Serail Port Programming regarding phone line hook

    Hello maskey_dipesh.

    Welcome to the Java Programming Forums.

    I have no experience with serial port programming. Hopefully someone else can help you soon.

    JAVA: Serial Port access with javax.comm or rxtx on Windows, Linux etc.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  3. #3
    Junior Member
    Join Date
    Sep 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Serail Port Programming regarding phone line hook

    Dear JavaPF,
    Thank for your information
    I am still waiting response from others. Hope somebody can help me.

Similar Threads

  1. [SOLVED] how to get phone time and date
    By mahdi in forum Java ME (Mobile Edition)
    Replies: 2
    Last Post: August 26th, 2009, 11:15 AM
  2. hey - Mobile phone drinking game
    By pazzy in forum Java ME (Mobile Edition)
    Replies: 9
    Last Post: August 4th, 2009, 09:41 AM
  3. How to create a system wide mouse or keyboard hook?
    By Freaky Chris in forum Java Native Interface
    Replies: 17
    Last Post: June 17th, 2009, 01:06 PM
  4. Reading a file line by line using the Scanner class
    By JavaPF in forum File Input/Output Tutorials
    Replies: 0
    Last Post: April 17th, 2009, 07:34 AM
  5. How to Read a file line by line using BufferedReader?
    By JavaPF in forum File Input/Output Tutorials
    Replies: 0
    Last Post: May 19th, 2008, 06:32 AM