LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-10-2003, 06:09 AM   #1
tda
Member
 
Registered: Mar 2002
Location: Ukraine, Kiev
Distribution: Mandrake 7.2
Posts: 37

Rep: Reputation: 15
Exclamation java comm api from ibm


Hello ALL!
I wrote a simple java program to test an ibm communication api implementation. But it throws IllegalMonitorStateException when I trying to close com port on RedHat Linux 7.3. Please comment this situation if you can.
This is a program:

import java.io.*;
import java.util.*;
import javax.comm.*;

public class Relay {

static final String comPortName = "COM1";
static final String toRealy = "BLABLABLA";

public static void main( String[] argv ) {
try {
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
CommPortIdentifier portId = getCommPortIdentifierByPortNumber( comPortName, portList );
SerialPort serialPort = (SerialPort) portId.open( "Relay", 30000 ); // 30 secs timeout
// System.out.println( "Sleep before closing 1 sec." );
// Thread.sleep( 1000 );
// System.out.println( "About to close serial port." );
serialPort.close();
} catch( Throwable e ) {
e.printStackTrace();
}
}

protected static CommPortIdentifier getCommPortIdentifierByPortNumber( String strPort, Enumeration portList ) throws IllegalArgumentException {
while( portList.hasMoreElements() ) {
CommPortIdentifier cpi = (CommPortIdentifier) portList.nextElement();
if( cpi.getName().equalsIgnoreCase( strPort ) == true ) return cpi;
}
throw new IllegalArgumentException( "Invalid port: " + strPort );
}

}

This program throws following exception:
java.lang.IllegalMonitorStateException
at java.lang.Object.notify(Native Method)
at com.ibm.comm.NSSerialPort$SerialEventDeliveryThread.prepareToStop(NSSerialPort.java:1275)
at com.ibm.comm.NSSerialPort.close(NSSerialPort.java:240)
at Relay.main(Relay.java:18)

P.S.I found in an archive http://www-106.ibm.com/developerwork...ad=5511&cat=10 the same question but without answer
 
Old 02-10-2003, 09:50 PM   #2
moeminhtun
Member
 
Registered: Dec 2002
Location: Singapore
Distribution: Fedora Core 6
Posts: 647

Rep: Reputation: 30
I've never used IBM Comm API before but I've used the Comm API from the Sun website. It is not their API (they have no Comm API for Linux platform). They redirect a third party one. The link is located at the FAQ page of the "Sun website", "Comm API download page". I'm working fine with it.

Coming to your problem,

"COM1", "COM2" are the windows names for the comm ports.
On Linux,
"/dev/ttyS0" for COM1,
"/dev/ttyS1" for COM2 etc.

Try to use "/dev/ttyS0" rather than COM1 and see if it's Ok.

Last edited by moeminhtun; 02-11-2003 at 02:30 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
comm question webeye Programming 9 11-29-2005 12:49 AM
Comm 5 WillG SUSE / openSUSE 3 09-04-2005 10:16 PM
usb serial comm guyulmaz Mandriva 3 06-07-2005 01:20 AM
which should I use? diff cmp comm Frybyte Linux - Newbie 2 07-19-2004 08:22 AM
IBM Java, Netscape and Mandrake robertoneto123 Linux - Software 6 01-12-2004 01:37 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration