User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 401,673 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,426 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 12499 | Replies: 10
Closed Thread
Join Date: Nov 2004
Posts: 5
Reputation: atul_manaskar is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
atul_manaskar atul_manaskar is offline Offline
Newbie Poster

Help Connecting modem via java

  #1  
Nov 18th, 2004
Hi
I have a problem in connecting modem with another modem through PSTN. i want the solution in java code

i want this connection to upload file from remote pc to my local pc

i want to develope the whole application in java

plz help me out as early as possible : :-|
AddThis Social Bookmark Button
 
Join Date: Dec 2003
Location: Marin County, CA
Posts: 6,439
Reputation: DMR will become famous soon enough DMR will become famous soon enough 
Rep Power: 18
Solved Threads: 340
Colleague
DMR's Avatar
DMR DMR is offline Offline
Wombat At Large

Re: Connecting modem via java

  #2  
Nov 18th, 2004
You should really give us a more specific descripition of your needs, but overall this question sounds more suited to the Java programming forum.

Moving there now...
"May the Wombat of Happiness snuffle through your underbrush."
- Ancient Aborigine blessing


Please do not contact me by email or PM for help. We're all volunteers here, and only have so much free time to dedicate to our efforts.

However, if I've been working on a thread with you already, and seem to have "forgotten" your thread, please do send me a message. I try not to let things slip through the cracks, but it does happen sometimes.
 
Join Date: Nov 2004
Posts: 5
Reputation: atul_manaskar is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
atul_manaskar atul_manaskar is offline Offline
Newbie Poster

Re: Connecting modem via java

  #3  
Dec 20th, 2004
hi
i have connected two pcs using modem via PSTN using comm api in follwing sequences.

1) My local modem calls to the Remote modem using the ATDT 235 command
2) on remote side one program continuosly listens to the incoming call.
3) After that my local modem detects the "CONNECT 9600" response.
4) Also my remote modem detects the same response it waits for some time and start transmitting data.
5) But my local modem is unable to receive some starting bytes and after some bytes it has receive it stops the receiving bytes.
6) But when i terminate the remote program my local modem receives the whole set of bytes.

Remote modem - DLINK DFM-562E++
Local Modem - DLINK DFM-560ES

THANKS IN ADVANCE
 
Join Date: Nov 2004
Location: Netherlands
Posts: 5,693
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 195
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Connecting modem via java

  #4  
Dec 20th, 2004
Post the relevant parts of your code. Sounds like you are forgetting to flush some buffers.
 
Join Date: Nov 2004
Posts: 5
Reputation: atul_manaskar is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
atul_manaskar atul_manaskar is offline Offline
Newbie Poster

Re: Connecting modem via java

  #5  
Dec 20th, 2004
This is my Dialup.java running at server side

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

public class Dialup implements Runnable,SerialPortEventListener 
{

	static CommPortIdentifier portId;
	static Enumeration portList;

	InputStream inputStream;
	OutputStream outputStream;
	SerialPort serialPort;
	Thread dialupThread;
	String telNo;
	String dialCommand;
	String initCommand;
	String line;
	static BufferedReader bos;
	static OutputStream fos = null;
	static FileOutputStream output = null;
	static DataOutputStream dOut = null;
	boolean flag = false;
	int conCount = 0;

	public static void main(String[] args) 
	{
		try
		{
			fos = new FileOutputStream("dem.txt",true);
			bos = new BufferedReader(new FileReader("dem.txt"));
			output = new FileOutputStream("abc.txt",true);
			dOut = new DataOutputStream(output);
		}catch(Exception e)
		{}

		if( args.length != 1 ) 
		{
			System.err.println("Usage: Dialup ");
			return;
		}
		portList = CommPortIdentifier.getPortIdentifiers();

		while (portList.hasMoreElements()) 
		{
			portId = (CommPortIdentifier) portList.nextElement();
			if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) 
			{
				if (portId.getName().equals("COM1")) 
				{
					Dialup dialer = new Dialup(args[0]);
				}
			}
		}

	}

	public Dialup(String telNo) 
	{
//		this.dialCommand = "&F&K3%E2%C0W2\\N3+MS=12,1,28000,46667";
		this.telNo = telNo;
		this.dialCommand = "ATDT"+telNo+"\r";
		initCommand = "&F&K3%E2%C0W2\\N3+MS=12,1,28000,46667\r";
//		this.dialCommand = "AT&C0&W0\r";
//		this.dialCommand = "ATO0";
//		this.dialCommand = "ATO0";
		try 
		{
			serialPort = (SerialPort) portId.open("DialUp", 2000);
		}
		catch (PortInUseException e) 
		{
		}

		try 
		{
			inputStream = serialPort.getInputStream();
			outputStream = serialPort.getOutputStream();
		}
		catch (IOException e) 
		{
			System.out.println(" Hell " + e);
		}

		try 
		{
			serialPort.addEventListener(this);
		}
		catch (TooManyListenersException e) {
		}
	
	
	portList = CommPortIdentifier.getPortIdentifiers();
		while (portList.hasMoreElements()) 
		{
			portId = (CommPortIdentifier) portList.nextElement();

			if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) 
			{

				if (portId.getName().equals("COM1")) 
				{
//					System.out.println(getInputBufferSize());
//					try 
//					{
						//serialPort = (SerialPort) portId.open("writereadApp", 2100);
						//System.out.println("Opened the port for writing: " + portId.getName());
//					}
//					catch (PortInUseException e) {System.out.println("IN USE ----  " + e);}			

					try 
					{
						serialPort.setSerialPortParams(9600,
						SerialPort.DATABITS_8,
						SerialPort.STOPBITS_1,
						SerialPort.PARITY_NONE);
					}
					catch (UnsupportedCommOperationException e) 
						{
							System.out.println("UnsupportedCommOperationException, Could not write to the port: " + e);
						}
					try 
					{
						outputStream = serialPort.getOutputStream();
						inputStream = serialPort.getInputStream();
					} 
					catch (IOException e) {System.out.print(e);}

/*					try 
					{
						serialPort.addEventListener(this);
					} 
					catch (TooManyListenersException e) {System.out.println("TOOO " + 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);
				}

			}
		}
		dialupThread = new Thread(this);
		dialupThread.start();
	}

	public void run() 
	{
		while(true)
		{
			if(conCount == 0) 
			{
				try 
				{
					if( !serialPort.isCD() ) 
					{
	//					outputStream.write(initCommand.getBytes());
						System.err.println("Try to connect ...");
						outputStream.write(dialCommand.getBytes());
					}
					Thread.sleep(60000);
					/*for(int i=0; i < 10; i++)
					{
						outputStream.write("Ram".getBytes());
						System.out.print("Ram");
					}*/
				}
				catch(Exception ex) 
				{
					System.err.println("Failed to write message");
				}
			}
		}
	}

	public void serialEvent(SerialPortEvent event) 
	{
	switch(event.getEventType()) 
	{
		case SerialPortEvent.OE:
		case SerialPortEvent.FE:
		case SerialPortEvent.PE:
		case SerialPortEvent.DSR:
			System.out.println("Data Set Ready.");
			break;
		case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
			System.out.println("Ignored event");
			break;

		case SerialPortEvent.BI:
			System.out.println("Break Interrupt");
			break;

		case SerialPortEvent.CTS:
			System.out.println("Clear to send");
			break;


		case SerialPortEvent.RI:
			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");
				conCount = conCount + 1;
				flag = true;
			}
			else 
			{
				System.out.println("Disconnected");
			}
			break;

		case SerialPortEvent.DATA_AVAILABLE:
			handleData();	
			break;
		}
	}

	public void handleData()
	{
		try
		{
			int avail = inputStream.available();
			byte[] response = new byte[avail];
			StringBuffer strbuf = new StringBuffer();
			inputStream.read(response, 0, avail);
			for (int i = 0; i < avail; i++) 
			{
				if(!flag)
				{
					fos.write((char)response[i]);
				}
			}
/*						while((line = bos.readLine())!=null)
			{
				if(line.equals("CONNECT 9600"))
				{
					flag = true;
					dOut.flush();								
				}
			}
*/			if(flag)
			{
				inputStream.read(response, 0, avail);
				for (int i = 0; i < avail; i++) 
				{
					Thread.sleep(5);
					output.write((char)response[i]);
					System.out.print((char)response[i]);
				}
			}
		}catch(IOException ie1){System.out.println("File " +ie1);}
		catch(InterruptedException in){System.out.println("Interrupt " +in);}

	}
}


this is my client side code
import java.io.*;
import java.util.*;
import javax.comm.*;
public class ReadDemo1 implements SerialPortEventListener 
{
	static Enumeration portList;
	static CommPortIdentifier portId; 
	static String output = "";
	SerialPort serialPort;
	static OutputStream outputStream;
	static InputStream inputStream;
	static String dialCommand;
	Thread readThread;
	int temp = 0;

	//*************************
	StringBuffer inputBuffer = new StringBuffer();
	DataOutputStream dout = null;
	OutputStream fos = null;
	String line;
	int ch;
	BufferedReader bos = null;
	int newData = 0;
	boolean writeFlag = false;
	FileInputStream fis = null;

	public static void main(String[] args)
	{


		int ch;
		InputStream fis;
		byte[] size = null;
		int count = 0;

		ReadDemo1 readObject = new ReadDemo1();
/*		try
		{
//			outputStream.write("ATM0L1S0=1&D2&C1S2=36S95=46&Q5\r".getBytes());
			outputStream.write("AT\\K0\r".getBytes());
		}catch(IOException ioe)
		{
			System.out.println("IOException" + ioe);
		}
*/
	}

	void Write(byte[] commandToSend)
	{
	try 
	{
		outputStream.write(commandToSend);
		System.out.println("Successfully Written: " + commandToSend);
	} 
	catch (IOException e) {System.out.println("IO Exception Occured: " + e);}
}
void closePort() 
{
	serialPort.close();
	System.out.print("Serial port closed.");
}


public ReadDemo1() 
{

	portList = CommPortIdentifier.getPortIdentifiers();
	while (portList.hasMoreElements()) 
	{
		portId = (CommPortIdentifier) portList.nextElement();

		if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) 
		{

			if (portId.getName().equals("COM1")) 
			{
				try 
				{
					serialPort = (SerialPort) portId.open("writereadApp", 2000);
					System.out.println("Opened the port for writing: " + portId.getName());
				}
				catch (PortInUseException e) {System.out.print(e);}			

				try 
				{
					serialPort.setSerialPortParams(9600,
					SerialPort.DATABITS_8,
					SerialPort.STOPBITS_1,
					SerialPort.PARITY_NONE);
				}
				catch (UnsupportedCommOperationException e) {System.out.println("UnsupportedCommOperationException, Could not write to the port: " + e);}
				try 
				{
					outputStream = serialPort.getOutputStream();
					inputStream = serialPort.getInputStream();
				} 
				catch (IOException e) {System.out.print(e);}

				try 
				{
					serialPort.addEventListener(this);
				} 
				catch (TooManyListenersException e) {System.out.print(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);
			}
		}
	}
}


	
	public void serialEvent(SerialPortEvent event) 
	{
		switch(event.getEventType()) 
		{
			case SerialPortEvent.DATA_AVAILABLE:
				handleData();	
				break;
			case SerialPortEvent.OE:
			case SerialPortEvent.FE:
			case SerialPortEvent.PE:
			case SerialPortEvent.DSR:
				System.out.println("Data set ready.");
				break;
			case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
				System.out.println("Ignored event");
				break;
			case SerialPortEvent.BI:
				System.out.println("Break Interrupt");
				break;
			case SerialPortEvent.CTS:
				System.out.println("Clear to send");
				break;
			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");
					try
					{
						Thread.sleep(120000);
						while((ch = fis.read()) != -1)
						{
							outputStream.write(ch);
		//								Thread.sleep(15);
							System.out.print((char)ch);
						}
										
						Thread.sleep(180000);					
					}catch(Exception e)
					{
						System.out.println(e);
					}
				}
				else 
				{
					System.out.println("Disconnected");
					System.exit(0);
				}
				break;
		}
	}
	public void handleData()
	{
//		System.out.println(writeFlag);
		System.out.print("Inside serial event");
		try
		{
			fis = new FileInputStream("abc.txt");
		}catch(FileNotFoundException fne) 
		{
			System.out.println("File Does not exists.");
		}
		try
		{
			fos = new FileOutputStream("rmn.txt",true);
			bos = new BufferedReader(new FileReader("rmn.txt"));
			dout = new DataOutputStream(fos);
			int avail = inputStream.available();
			byte[] response = new byte[avail];
			StringBuffer strbuf = new StringBuffer();
			inputStream.read(response, 0, avail);
			for (int i = 0; i < avail; i++) 
			{
				fos.write((char)response[i]);
			}
			if(!writeFlag)
			{
				while((line = bos.readLine())!=null)
				{
				//	dout.flush();
					if(line.equals("CONNECT 9600/ARQ"))
					{
						writeFlag = true;
						System.out.println("connect");
					}
				}
			}
			if(writeFlag)
			{

			}
		}catch(IOException ie1){System.out.println("File " +ie1);}
//		catch(InterruptedException ie1){System.out.println("File " +ie1);}
	}
}
 
Join Date: Nov 2004
Location: Netherlands
Posts: 5,693
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 195
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Connecting modem via java

  #6  
Dec 21st, 2004
Like I suspected you're not flushing any of your Streams, that's BAD.
I've not checked if you're properly closing them, look for that as well.
 
Join Date: Nov 2004
Posts: 5
Reputation: atul_manaskar is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
atul_manaskar atul_manaskar is offline Offline
Newbie Poster

Re: Connecting modem via java

  #7  
Dec 21st, 2004
hi
can u plz tell me the sequence in which after the modem get connected i should flush the streams while transferring data from one end to other.

Modem stop receiving bytes after the follwing events
Data set Ready
Break Interrupt
 
Join Date: Mar 2005
Posts: 1
Reputation: danny_ is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
danny_ danny_ is offline Offline
Newbie Poster

Re: Connecting modem via java

  #8  
Mar 16th, 2005
Originally Posted by atul_manaskar
hi
can u plz tell me the sequence in which after the modem get connected i should flush the streams while transferring data from one end to other.

Modem stop receiving bytes after the follwing events
Data set Ready
Break Interrupt

hi,

did you have any luck finding the problem? (i've looked over the code, but i'm not familiar enough with javax.comm to find anything new)
 
Join Date: Mar 2006
Posts: 11
Reputation: nawal is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
nawal nawal is offline Offline
Newbie Poster

Re: Connecting modem via java

  #9  
Mar 12th, 2006
hi
I have problem into program previous.
I can connection between two pc with modem using program
previous but , I cannot upload file from pc to pc

please necessary
 
Join Date: Dec 2003
Location: Marin County, CA
Posts: 6,439
Reputation: DMR will become famous soon enough DMR will become famous soon enough 
Rep Power: 18
Solved Threads: 340
Colleague
DMR's Avatar
DMR DMR is offline Offline
Wombat At Large

Re: Connecting modem via java

  #10  
Mar 12th, 2006
Hi nawal,


We ask that members not tag their questions on to a thread previously started by another member (regardless of how similar your problem might seem). Not only does it divert the focus of the thread away from the original poster's problem, but it also makes it less likely that you yourself will get the individual attention that you need.

Please start your own thread and post your question there. When you do, please try to give us as much specific info as possible regarding the problem (exact error messages, system specs, etc.).

For a full description of our posting guidelines and general rules of conduct, please see this page:

http://www.daniweb.com/techtalkforum...niweb_policies

Thanks for understanding.
"May the Wombat of Happiness snuffle through your underbrush."
- Ancient Aborigine blessing


Please do not contact me by email or PM for help. We're all volunteers here, and only have so much free time to dedicate to our efforts.

However, if I've been working on a thread with you already, and seem to have "forgotten" your thread, please do send me a message. I try not to let things slip through the cracks, but it does happen sometimes.
 
Closed Thread

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 7:24 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC