Results 1 to 4 of 4
Thread: how to connect to sms modem?
- 01-10-2009, 08:24 AM #1
Member
- Join Date
- Jan 2009
- Posts
- 2
- Rep Power
- 0
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
- 01-10-2009, 08:29 AM #2
Member
- Join Date
- Jan 2009
- Posts
- 2
- Rep Power
- 0
The E-Mail address above is invalid.
It should be : greencityvip@sina.com
- 01-10-2009, 09:03 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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. :)
- 01-10-2009, 08:33 PM #4
Reposted here:
http://www.java-forums.org/networkin...sms-modem.html
Cross posted here:
Java Programming - how to connect to a sms modem with JAVA?
db
Similar Threads
-
JMF: Cannot connect to device
By jonsamwell in forum New To JavaReplies: 2Last Post: 06-10-2011, 07:20 PM -
x modem protocol
By jithan in forum New To JavaReplies: 0Last Post: 08-21-2008, 10:43 AM -
how connect
By herfnai in forum JDBCReplies: 1Last Post: 08-18-2008, 06:34 AM -
connect two applet
By dg_iiita in forum Java AppletsReplies: 0Last Post: 02-15-2008, 01:59 PM -
connect to MSDE
By leonard in forum JDBCReplies: 1Last Post: 08-06-2007, 04:37 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks