How To Check Window’s Opened Comm Port using Java

On my latest project, i need to connect my java application to a GSM Modem, in order to sending and receiving SMS text. But before my application connected to opened comm port, i need to check which port number is opened. So this is a small java class to check my opened comm port. Btw, im using rtxt libraries to help me communicate with the opened port.

import gnu.io.CommPortIdentifier;
import java.util.Enumeration;

public class Main {
    
    private void doSomething() {
        Enumeration portList = CommPortIdentifier.getPortIdentifiers();
        System.out.println(portList.hasMoreElements());
        while (portList.hasMoreElements()) {
            CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
            System.out.println(portId.getName());
        }
    }
    
    public static void main(String[] args) {
        Main main = new Main();
        main.doSomething();
    }
}

Dont forget to add rxtx libraries your java’s path. You can find the Window’s installation path, here.

Hope it helps other, have fun :)

Google+

No Comments

Leave a Comment

Please be polite. We appreciate that.
Your email address will not be published and required fields are marked


:-[ (B) (^) (P) (@) (O) (D) :-S ;-( (C) (&) :-$ (E) (~) (K) (I) (L) (8) :-O (T) (G) (F) :-( (H) :-) (*) :-D (N) (Y) :-P (U) (W) ;-)