Results 1 to 3 of 3
- 04-27-2011, 07:50 PM #1
Automatically detect which COM port is connected to a USB GSM Modem using java
I wrote a Java application that reads and sends SMS messages from a USB GSM modem. I'm using SMSLib (which uses JavaCommAPI), and it runs on Windows. I need to pass in the COM PORT, that the modem appears to be connected to. Now in my application am giving hardcoded value for the COM port number which is not user friendly coz the com port depend on the machine the application is run on.
Any ideas on how i can do this will be highly appreciated
cheerz!!We Learn Through Mistakes..,
Manfizy:rolleyes:
- 04-28-2011, 08:10 PM #2
Well guyz, i found a solution. Those interested, check out the code below
Java Code:package com.cubepro.util; import java.util.Collection; import java.util.Collections; import java.util.Enumeration; import java.util.Formatter; import org.apache.log4j.Logger; import org.smslib.helper.CommPortIdentifier; import com.cubepro.general.CommonConstants; import com.cubepro.util.SendMessage; public class CommPortTester { private static final String _NO_DEVICE_FOUND = " no device found"; private final static Formatter _formatter = new Formatter(System.out); private static Logger log = Logger.getLogger(CommPortTester.class); static CommPortIdentifier portId; static Enumeration<CommPortIdentifier> portList; static int bauds[] = { 9600, 14400, 19200, 28800, 33600, 38400, 56000, 57600, 115200 }; public static final String MAINCLASS = "org.smslib.Service"; public CommPortTester() throws Exception { Class.forName(MAINCLASS); } /** * Wrapper around {@link CommPortIdentifier#getPortIdentifiers()} to be * avoid unchecked warnings. */ private static Enumeration<CommPortIdentifier> getCleanPortIdentifiers() { return CommPortIdentifier.getPortIdentifiers(); } public String testAndQualifyPort() throws Exception { String status = CommonConstants.MODEM_STATUS_ERROR; SendMessage sendMessage = new SendMessage(); log.debug("\nSearching for devices..."); portList = getCleanPortIdentifiers(); while (portList.hasMoreElements()) { portId = portList.nextElement(); if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) { _formatter.format("%nFound port: %-5s%n", portId.getName()); try { if(portId.getName() boolean comPortSuccess = sendMessage.doIt(portId.getName()); if(comPortSuccess == true){ return portId.getName(); } } catch (final Exception e) { log.debug(" Modem error occured -",e); } } } log.debug("\nTest complete."); return status; } public static void main(String[]args){ try{ CommPortTester tester = new CommPortTester(); tester.testAndQualifyPort(); }catch(Exception e){ e.printStackTrace(); } } }We Learn Through Mistakes..,
Manfizy:rolleyes:
- 11-30-2011, 07:36 AM #3
Member
- Join Date
- Nov 2011
- Posts
- 1
- Rep Power
- 0
Re: Automatically detect which COM port is connected to a USB GSM Modem using java
Hello Manfizy.
I came across this forum looking for a way to write a java app to send/receive sms messages through a USB GSM modem. Would you be kind to guide me on how to
go about it. I would really appreciate your help. Thanks in advance
Similar Threads
-
Detect USB port signal
By mine0926 in forum Advanced JavaReplies: 4Last Post: 01-28-2011, 05:37 AM -
how to detect signal strength of modem?
By boyaxnxtdoor in forum NetBeansReplies: 1Last Post: 01-25-2011, 03:11 PM -
seek device connected to usb port
By kievari in forum Advanced JavaReplies: 2Last Post: 08-27-2010, 11:18 PM -
Serial port programming using modem and telephone
By maskey_dipesh in forum Advanced JavaReplies: 1Last Post: 09-03-2009, 11:53 AM -
throw java to connect to serial port and Send AT Commands to dial up modem
By jfouadazem in forum Advanced JavaReplies: 4Last Post: 02-28-2009, 08:39 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks