File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Java Comm API... Please respond Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java Comm API... Please respond " Watch "Java Comm API... Please respond " New topic
Author

Java Comm API... Please respond

Trelan Hylton
Greenhorn

Joined: Apr 15, 2003
Posts: 27
I AM NEW TO THE JAVA COMMUNICATIONS API . I FOLLOWED THE INSTRUCTIONS GIVEN ON INSTALLING THE JAVAX.COMM API AND RUNNING PROGRAMS. THESE INSTRUCTIONS ARE AS FOLLOWS :
"Installing the Java Communications API on JDK 1.2 (RC1)
<jdk> refers to the root directory of your JDK installation. If you installed JDK in c:\jdk1.2 then replace all reference to <jdk> with c:\jdk1.2.

Windows: place the win32com.dll in <jdk>\jre\bin directory.
Solaris: put the libSolarisSerialParallel.so in the LD_LIBRARY_PATH.
Place the comm.jar in <jdk>\jre\lib\ext.
Place the javax.comm.properties in <jdk>\jre\lib .
Do not alter the CLASSPATH.
--------------------------------------------------------------------------------
Running the Java Communications API on JDK 1.2 (RC1)
Once you have installed the Java communications API you should be able to run applications that take advantage of the Java communications API without further modifications. Use the -cp option to java to indicate the location of the class or jar files for your application:
java -cp c:\myapp\myapp.jar MyApp
"
IT DOESN'T WORK. I AM ON WINDOWS 2000 WHAT SHOULD I DO?


JH
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
Would you please not use all caps? It's hard to talk when someone shouts in your ear. What doesn't work?
Trelan Hylton
Greenhorn

Joined: Apr 15, 2003
Posts: 27
sorry about the caps. I cannot seem to get the runtime environment path correct. it compiles but it will not run. all sorts of exception given. i even tried setting the path in autoexec.bat.
the path i set is this "c:\j2sdk1.4.1_02\lib\comm.jar"
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
It looks like you didn't do this if your comm.jar is in "c:\j2sdk1.4.1_02\lib\comm.jar":
Place the comm.jar in <jdk>\jre\lib\ext.
And you don't put jar files in your path.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Trelan Hylton
Greenhorn

Joined: Apr 15, 2003
Posts: 27
i did that as well as an alternate to what i did before "c:\j2sdk1.4.1_02\jre\lib\ext\comm.jar" should i do both? i placed the files where i was instructed to place them.
what do you mean by putting jar in the file path?
btw i am trying to run SimpleRead.java
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
jar files do not go on the Path.
Trelan Hylton
Greenhorn

Joined: Apr 15, 2003
Posts: 27
when i try to run SimpleRead.class where the source code is as follows:
import java.io.*;
import java.util.*;
import javax.comm.*;
public class SimpleRead implements Runnable, SerialPortEventListener {
static CommPortIdentifier portId;
static Enumeration portList;
InputStream inputStream;
SerialPort serialPort;
Thread readThread;
public static void main(String[] args) {
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")) {
SimpleRead reader = new SimpleRead();
}
}
}
}
public SimpleRead() {
try {
serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
} catch (PortInUseException e) {}
try {
inputStream = serialPort.getInputStream();
} catch (IOException e) {}
try {
serialPort.addEventListener(this);
} catch (TooManyListenersException e) {}
serialPort.notifyOnDataAvailable(true);
try {
serialPort.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {}
readThread = new Thread(this);
readThread.start();
}
public void run() {
try {
Thread.sleep(20000);
} catch (InterruptedException e) {}
}
public void serialEvent(SerialPortEvent event) {
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:
byte[] readBuffer = new byte[20];
try {
while (inputStream.available() > 0) {
int numBytes = inputStream.read(readBuffer);
}
System.out.print(new String(readBuffer));
} catch (IOException e) {}
break;
}
}
}

i get a NoClassDefFoundError exception for javax.comm.SerialPortEventListener
i have tried so hard to place the files in the corect stated locations but setting the classpath is hell. could they someone give me a real example of their classpath environment variable in regards to the java comm api?
[ April 29, 2003: Message edited by: Trelan Hylton ]
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
There should be no need to set the CLASSPATH if you followed the proper procedure. I just installed the COMM API here and everything works fine. You may have installed using the older 1.1.6 instructions. Look in the directory where you unzipped the compressed download. Open the file jdk1.2.html and follow those instructions. If you installed by the instructions from the link found in Readme.html, you may have to undo all of that.


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Trelan Hylton
Greenhorn

Joined: Apr 15, 2003
Posts: 27
Thanx. let's hope that works!
Trelan Hylton
Greenhorn

Joined: Apr 15, 2003
Posts: 27
it didn't work. i am losing my mind... very frustrating.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
OK Trelan, let's go thru this step by step. Once you install the COMM API, what exactly are you trying to do?
Trelan Hylton
Greenhorn

Joined: Apr 15, 2003
Posts: 27
Micheal i am trying to read data from a serial port on the computer that was left there by a telephony system. this data is needed to generate reports on inbound calls to the system.
I am trying to use java to read this port but so far i have been unable to even install the java api that would allow me to.
I am at a loss as to how to solve this problem. i have placed the comm.jar in the c:\j2sdk1.4.1_02\jre\lib\ext directory. i have placed javax.comm.properties in the c:\j2sdk1.4.1_02\jre\lib directory. i have placed win32com.dll in the c:\j2sdk1.4.1_02\jre\bin directory and then tried to run the samples such as SimpleRead and SimpleWrite and they produce runtime errors saying that classes in the javax.comm package does not exist.
I have retstarted the machine yet it does not work. i have windows 2000 at home like the computer here at work and the one at home works perfectly. i even tried to place the win32com.dll in the c:\j2sdk1.4.1_02\bin directory, both the comm.jar and the javax.comm.properties in the c:\j2sdk1.4.1_02\lib directory, set the classpath as c:\j2sdk1.4.1_02\lib\comm.jar yet it does not work. does
this not work with computers on a network?
nothing makes sence anymore.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
does this not work with computers on a network?
That's not the problem, because it works fine on my machine here, also Win 2000 and networked. Are you getting a NoClassDefFoundError error? Can you compile using some class in the javax.comm package? Do you have administrative privaleges on the machine? Not sure if that makes a difference but let's explore all the possibilities.
Trelan Hylton
Greenhorn

Joined: Apr 15, 2003
Posts: 27
Are you getting a NoClassDefFoundError error? Can you compile using some class in the javax.comm package? Do you have administrative privaleges on the machine?
Yes I am getting a NoClassDefFoundError: javax/comm/UnsupportedCommOperationException when i try to run SimpleWrite for example. no i dont have administrative privaleges on the machine so i get the administrator to sign in and there are the same problems. I can compile the classes, just not able to run them however.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Treylan,
Umm, interesting. Which port are you trying to write to and what is attached to it? I just did ran SimpleWrite but had to change the line if (portId.getName().equals("/dev/term/a")) { to if (portId.getName().equals("COM2")) {. I have an external modem attached there and it works fine. TD and TR flicker briefly on the modem panel. If I try to write to COM1, I get an NullPointerException at the line outputStream = serialPort.getOutputStream(); since there is nothing attached to COM1. I suppose you've read the docs on UnsupportedCommOperationException:
Thrown when a driver doesn't allow the specified operation.
It would seem to be some sort of driver problem.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Is the exception being thrown at serialPort.setSerialPortParams()? It could be that whatever device you have attached won't allow certain hardware settings.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Is the exception being thrown at serialPort.setSerialPortParams()?
That was a stupid question. That's obviously where it is happening, which tells me that the device doesn't support changing the hardware settings or maybe it's owned by System, in which case not even administrative privaleges will get you in.
Trelan Hylton
Greenhorn

Joined: Apr 15, 2003
Posts: 27
I tried with SimpleRead and BlackBox if it is not one exception it is another and it is the same with the two computers that i have tried on this network. the exception i refered to earlier is simply one of some. even trying to list the ports on the system gives error.
the data is being logged to com 1
this is an example of that data that is being dumped there
-------- 04/23/03 15:42:42 LINE = 0004 STN = 232
00:00:00 OUTGOING CALL
DIGITS DIALED 9239945
00:00:04 CALL RELEASED
-------- 04/23/03 15:45:07 LINE = 0004 STN = 244
00:00:00 OUTGOING CALL
00:01:46 HOLD
00:02:00 UNHOLD
DIGITS DIALED 17769368
00:04:45 CALL RELEASED
-------- 04/23/03 15:45:59 LINE = 0003 STN = 237
00:00:00 OUTGOING CALL
DIGITS DIALED 9687560
00:03:54 CALL RELEASED
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
What sort of device is attached? Is that some sort of PBX?
Trelan Hylton
Greenhorn

Joined: Apr 15, 2003
Posts: 27
yes a pbx.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
My experience with serial communications involves simple modems and, back in the 80s the occasional interrupt service routine (handshake) for plotters. I'm afraid, that without being right there or having access to a similar PBX, that I won't be able to help you. I seriously don't think the problem lies with the javax.comm package but with some idiosynchrosies with the PBX itself or its drivers. Can you effectively communicate with it using the native Windows communications API? As distasteful as such things are, you may need to read completely thru all the documentation you have on the PBX and perhaps contact the manufacturer for suggestions. One thing to consider about javax.comm is that if there are any other listeners on a particular COM port, it will throw an NPE if you try to grab either input or output stream to the port. If you can think of anything else that might shed some more light on this, let us know.
Trelan Hylton
Greenhorn

Joined: Apr 15, 2003
Posts: 27
I have never programmed with the native windows communication api before so i dont know the answer to your question. the system we use is a bit more complex than simple pbx. we use the pc-pbx. i dont know if that could be part of the problem. maybe there are listeners to some ports on the system, we have some communication software and hardware here... could pc-anywhere pose problem? i am seeking solutions.
thanks for your help anyway Micheal
 
 
subject: Java Comm API... Please respond
 
Similar Threads
Getting available ports using Javax.comm
javax.comm can't enum ports
problem in installing the java communications API
problem in installing the java communications API
Hello World