how to read virtual port in java

how to find the virtual port in java

Page 1 of 1

4 Replies - 3279 Views - Last Post: 16 December 2010 - 05:25 PM Rate Topic: -----

#1 deartahir  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 41
  • Joined: 28-February 10

how to read virtual port in java

Posted 15 December 2010 - 08:25 AM

I want to read and write to virtual com port that is dynamically created by CP2101 driver when i connect a device through USB To UART Bridge to my system.the problem is that with rxtx API we can not find that which com port is assigned to the connected device.only we can manually set the port(say "COM1").in my case virtual port is automatically created so any idea to read that virtual port will be appreciated.actually i want to know which device is connected to serial port.

portList = CommPortIdentifier.getPortIdentifiers();
        System.out.println("portList... " + portList);
        while (portList.hasMoreElements()) {
                portId = (CommPortIdentifier) portList.nextElement();
                if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
                        System.out.println("port identified is Serial.. "
                                        + portId.getPortType());
                        if (portId.getName().equals("COM2"))// you see we manually assigned COM2 but i want that whic port is dynamically allocated to device.  


 {
                                System.out.println("port identified is COM2.. "
                                                + portId.getName());


Is This A Good Question/Topic? 0
  • +

Replies To: how to read virtual port in java

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: how to read virtual port in java

Posted 15 December 2010 - 06:30 PM

Not an easy task
Could you make a list of all the COM port first
then connect your USB devices
than make a new list ignoring the ones that where there before ?

Don't know any way to pool a COM port to know what is connected at the other end
Was This Post Helpful? 0
  • +
  • -

#3 deartahir  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 41
  • Joined: 28-February 10

Re: how to read virtual port in java

Posted 16 December 2010 - 07:27 AM

what you think if I read registry HKLM..USB.. folder or should I use JNA to communicate with native code I mean dll of driver.
Was This Post Helpful? 0
  • +
  • -

#4 deartahir  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 41
  • Joined: 28-February 10

Re: how to read virtual port in java

Posted 16 December 2010 - 02:26 PM

View Postpbl, on 15 December 2010 - 05:30 PM, said:

what you think if I read registry HKLM..USB.. folder or should I use JNA to communicate with native code I mean dll of driver.

Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: how to read virtual port in java

Posted 16 December 2010 - 05:25 PM

View Postdeartahir, on 16 December 2010 - 08:27 AM, said:

what you think if I read registry HKLM..USB.. folder or should I use JNA to communicate with native code I mean dll of driver.

If you want to use Java, would be simple to have a simple C program that interrogate the driver and store the port number in a file.
Your pure Java program can then read that file and proceed with the port number read.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1