• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting available ports using Javax.comm

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends,
I was trying to get the available port using the following sample program.But I couldnt get any output.
can u help me?
Program;

import java.io.*;
import java.util.*;
import javax.comm.*;
public class SimpleWrite {
static Enumeration portList;
static CommPortIdentifier portId;
static String messageString = "Hello, world!\n";
static SerialPort serialPort;
static OutputStream outputStream;
public static void main(String[] args) throws NoSuchPortException
{

portList = CommPortIdentifier.getPortIdentifiers();

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

if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL)
{
// if (portId.getName().equals("COM1")) {
if (portId.getName().equals("/dev/term/a"))
{
try {
serialPort = (SerialPort)
portId.open("SimpleWriteApp", 2000);
} catch (PortInUseException e) {}
try {
outputStream = serialPort.getOutputStream();
} catch (IOException e) {}
try {
serialPort.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {}
try {
outputStream.write(messageString.getBytes());
} catch (IOException e) {}
}
}
}
}
}
===============

I am getting the following error.(It tells there is no elements in the Enumeration)
Error loading win32com: java.lang.UnsatisfiedLinkError: no win32com in java.library.path
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Error loading win32com: java.lang.UnsatisfiedLinkError: no win32com in java.library.path
Sounds like you either have your DLL located in the wrong directory or you do not have it in the correct path. Have yo installed the comapi properly?
Check that your Dll are located inside;
javax.comm DLL in the lib directory inside the jdk directory
win32.comm DLL in the bin directory inside the jdk directory
Then depending on your compiler you will need to set the paths for all required libraries.
------------------
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I followed Jamie Young's instructions and it worked. However here is something I felt to add:

1) In order for the Java communications API to find ports the file
javax.comm.properties must be in the correct place. The preferred location
is in <jdk>/lib. In case you are using just a JRE installation, then it should be in <jre>/lib directory.

2) The win32comm.dll should be placed in the <jdk>/bin directory (as suggested by Jamie) or in case you
just have a JRE installation then it should be placed in the <jre>/bin directory.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Get Available COM ports using Java comm API
Get Available COM ports in Java

 
First, you drop a couch from the plane, THEN you surf it. Here, take this tiny ad with you:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic