パラレルポートの読み取りと書き込みを試みています。書き込みと読み取りをCで実装しました。次に、そのコードをJavaGUIアプリケーションにインポートします。私はなんとかC.soファイルをJavaプロジェクトに含めることができ、Javaソリューションのmain()メソッドで関数を直接呼び出すと、問題なく機能します。
ボタンが押されたときにネイティブ関数を呼び出そうとしましたが、機能せず、アプリケーションがクラッシュします。アプリケーションをルートとして実行しています。パラレルポートの値を変更して読み取るには、ルート権限が必要です。
ネイティブ関数を呼び出そうとしている方法:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try
{
int portNR=Integer.parseInt(jTextField1.getText());
int value=Integer.parseInt(jTextField2.getText());
ParalellComanderApp.setPort(portNR,value );
}
catch (Exception e)
{
System.err.println(e.getMessage());
}
}
Cのネイティブ関数:
JNIEXPORT void JNICALL Java_paralellcomander_ParalellComanderApp_setPort
(JNIEnv *env, jobject obj, jint port, jint value)
{
outb(value,MAIN_PORT+port);
printf("Setting port %d to value %d\n",port,value);
}
クラッシュメッセージ:
A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007f00adaf9833, pid=6516, tid=139640785835776
#
# JRE version: 6.0_23-b23
# Java VM: OpenJDK 64-Bit Server VM (20.0-b11 mixed mode linux-amd64 compressed oops)
# Derivative: IcedTea6 1.11pre
# Distribution: Ubuntu oneiric (development branch), package 6b23~pre10-0ubuntu5
# Problematic frame:
# C [libAccessParalel.so+0x833] inb+0x17
#
# An error report file with more information is saved as:
# /home/bari/NetBeansProjects/ParalellComander/dist/hs_err_pid6516.log
#
# If you would like to submit a bug report, please include
# instructions how to reproduce the bug and visit:
# https://bugs.launchpad.net/ubuntu/+source/openjdk-6/
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
長い投稿でごめんなさい。誰か助けてもらえますか?