Feb 20, 2003

          onlpara, Red Hat Linux 8.0 のシステムでのJavaRMIの実行
                 ---  JavaRMIで onlsbc1 と通信する #1
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                  (http://www-online.kek.jp/~inoue/para-CAMAC/
                                   Work/CAMAC-JavaRMI1.html)



                        高エネルギー加速器研究機構
                            素粒子原子核研究所
                         物理、オンライングループ
                                井上 栄二



	目的

	    SBC、PCM-9370にインストールしてある Red Hat Linux 8.0 のシステム上で
	  JNIを使ってCAMACを読み出した。 ここでは、リモートマシン onlpara から
	  onlsbc1 上のJNIプログラムと通信を行い、onlpara側で CAMACデータを
	  受け取る。


	(1). 構成
	(2). onlpara と onlsbc1 との間で arrayデータの受け渡しを行う
	(3). onlsbc1 側の JNIプログラムとRMIプロプラムをひとつに組み合わせる
	(4). リモートマシンonlpara からの CAMAC読み書き

  --------------------------------------------------------------------


 (1). 構成

	テストに使用するマシンは onlpara と onlsbc1 である。 マシン onlpara は
	DELL社製のPC, Dimension 4500 で、RedHat Linux 7.3 が動作している。 Java
	のバージョンは1.4.1 である。 一方 onlsbc1 は、アドバンテク社のSBC、
	PCM-9370である。 このSBCは、CAMACコントローラ上に装着されている。
	SBC上で動作している OSは Red Hat Linux 8.0 で、コンパクトフラッシュ上に
	構成してある。 Javaのバージョンは1.4.1_01 である。


 (2). onlpara と onlsbc1 との間で arrayデータの受け渡しを行う

   (2-1).  サーバ側、onlsbc1.kek.jp

     (2-1-1).  Javaのチェック

[inoue@onlsbc1 CAMAC-array-ok8]$ java -version
java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)
[inoue@onlsbc1 CAMAC-array-ok8]$


     (2-1-2).  実行環境

[inoue@onlsbc1 CAMAC-array-ok8]$ env
MANPATH=:/usr/java/man
HOSTNAME=onlsbc1.kek.jp
TERM=vt100
SHELL=/bin/bash
JLESSCHARSET=japanese
HISTSIZE=1000
SSH_CLIENT=130.87.153.9 32823 22
SSH_TTY=/dev/pts/0
USER=inoue
LS_COLORS=no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;0
1:or=01;05;37;41:mi=01;05;37;41:ex=01;32:*.cmd=01;32:*.exe=01;32:*.com=01;32:*.b
tm=01;32:*.bat=01;32:*.sh=01;32:*.csh=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:
*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*
.bz=01;31:*.tz=01;31:*.rpm=01;31:*.cpio=01;31:*.jpg=01;35:*.gif=01;35:*.bmp=01;3
5:*.xbm=01;35:*.xpm=01;35:*.png=01;35:*.tif=01;35:
MAIL=/var/spool/mail/inoue
PATH=/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/usr/java/bin:/home/inoue/bin
INPUTRC=/etc/inputrc
PWD=/home/inoue/JavaRMI/CAMAC/CAMAC-array-ok8
LANG=ja_JP.eucJP
SHLVL=1
HOME=/home/inoue
LOGNAME=inoue
LESSOPEN=|/usr/bin/lesspipe.sh %s
G_BROKEN_FILENAMES=1
_=/bin/env
OLDPWD=/home/inoue/JavaRMI/CAMAC
[inoue@onlsbc1 CAMAC-array-ok8]$


     (2-1-3).  コンパイル

       (2-1-3a).  Client.java

[inoue@onlsbc1 CAMAC-array-ok8]$ cat Client.java
public interface Client extends java.rmi.Remote {
        public void camac_reply( int[] ia, int[] ib) throws java.rmi.RemoteExcep
tion;
}
[inoue@onlsbc1 CAMAC-array-ok8]$


       (2-1-3b).  ClientImpl.java

[inoue@onlsbc1 CAMAC-array-ok8]$ cat ClientImpl.java
import java.rmi.*;
import java.rmi.server.*;

class ClientImpl implements Client {
        Server server;

        public ClientImpl(String host) {
                int[]  s_cmd, s_dat;


                try{
                   UnicastRemoteObject.exportObject(this);
                   Server server = (Server)Naming.lookup("//"+host+"/Server");
                   server.register(this);
                int[] array_sizes = {4096*16};

                // to send int array
                        s_cmd = new int[array_sizes[0]];
                        s_dat = new int[array_sizes[0]];

                        s_cmd[0] = 0;
                        s_cmd[1] = 1;
                        s_cmd[2] = 2;
                        s_cmd[3] = 3;

                        s_dat[0] = 5;
                        s_dat[1] = 6;
                        s_dat[2] = 7;
                        s_dat[3] = 8;


                        server.camac_cmd(s_cmd, s_dat);
                } catch ( Exception e ) {
                   System.err.println ("Failed to setup for RMI");
                }

        }

        public void camac_reply( int[] c_reply, int[] d_reply) throws RemoteExce
ption {
                System.out.println(" Client side: ");
                System.out.println("    c_reply[0] = " + c_reply[0]);
                System.out.println("    c_reply[1] = " + c_reply[1]);
                System.out.println("    c_reply[2] = " + c_reply[2]);
                System.out.println("    c_reply[3] = " + c_reply[3]);
                System.out.println("    d_reply[0] = " + d_reply[0]);
                System.out.println("    d_reply[1] = " + d_reply[1]);
                System.out.println("    d_reply[2] = " + d_reply[2]);
                System.out.println("    d_reply[3] = " + d_reply[3]);
        }

        public static void main(String argv[]) throws Exception{

                String  host = (argv.length == 1) ? argv[0] : "localhost";
                ClientImpl obj = new ClientImpl(host);
        }
}
[inoue@onlsbc1 CAMAC-array-ok8]$


       (2-1-3c).  Server.java

[inoue@onlsbc1 CAMAC-array-ok8]$ cat Server.java
import java.rmi.*;

public interface Server extends java.rmi.Remote {
        void register(Client aclient) throws java.rmi.RemoteException;
        void camac_cmd(int[] ia, int[] ib) throws RemoteException;
}
[inoue@onlsbc1 CAMAC-array-ok8]$


       (2-1-3d).  ServerImpl.java

[inoue@onlsbc1 CAMAC-array-ok8]$ cat ServerImpl.java
import java.rmi.*;
import java.rmi.server.*;

public class ServerImpl extends UnicastRemoteObject implements Server {
        Client client;
        static String serverName;
        static int[] r_cmd, r_dat;


        static {
                try {
                        serverName = java.net.InetAddress.getLocalHost().getHost
Name();
                }catch(Exception e){
                        serverName = "localhost";
                }
        }

        public ServerImpl() throws Exception {
                super();
                r_cmd = new int[4096*16];
                r_dat = new int[4096*16];

        }

        public Server createInstance() throws RemoteException {
                ServerImpl obj = null;

                try {
                        obj = new ServerImpl();
                        return obj;
                }catch(Exception e){
                        e.printStackTrace();
                }

                return obj;
        }

        public void register (Client aclient) {
                client = aclient;
        }

        public void camac_cmd(int[] cmd, int[] dat) throws RemoteException{
// E.Inoue

        if ( cmd.length > 1 ) {
           System.out.println(" Server side: ");
           System.out.println("    cmd[0] = " + cmd[0]);
           System.out.println("    cmd[1] = " + cmd[1]);
           System.out.println("    cmd[2] = " + cmd[2]);
           System.out.println("    cmd[3] = " + cmd[3]);
           System.out.println("    dat[0] = " + dat[0]);
           System.out.println("    dat[1] = " + dat[1]);
           System.out.println("    dat[2] = " + dat[2]);
           System.out.println("    dat[3] = " + dat[3]);
        }

        ServerImpl.r_cmd[0] = 8;
        ServerImpl.r_cmd[1] = 7;
        ServerImpl.r_cmd[2] = 6;
        ServerImpl.r_cmd[3] = 5;
        ServerImpl.r_dat[0] = 4;
        ServerImpl.r_dat[1] = 3;
        ServerImpl.r_dat[2] = 2;
        ServerImpl.r_dat[3] = 1;
        client.camac_reply (ServerImpl.r_cmd, ServerImpl.r_dat);
//end
        }

        public static void main(String argv[]) throws Exception {
                //System.setSecurityManager(new RMISecurityManager());
                ServerImpl obj = new ServerImpl();
                Naming.bind("//"+serverName+"/Server", obj);
                System.out.println("bind done");
        }
}
[inoue@onlsbc1 CAMAC-array-ok8]$

       (2-1-3e).  上記のソースプログラムをコンパイルする

[inoue@onlsbc1 CAMAC-array-ok8]$ pwd
/home/inoue/JavaRMI/CAMAC/CAMAC-array-ok8
[inoue@onlsbc1 CAMAC-array-ok8]$ javac *.java
[inoue@onlsbc1 CAMAC-array-ok8]$ rmic ClientImpl
[inoue@onlsbc1 CAMAC-array-ok8]$ rmic ServerImpl
[inoue@onlsbc1 CAMAC-array-ok8]$ ls -l
合計 48
-rw-rw-r--    1 inoue    inoue         201  2月 10 16:52 Client.class
-rw-rw-r--    1 inoue    inoue         131  2月 10 16:00 Client.java
-rw-rw-r--    1 inoue    inoue        1842  2月 10 16:52 ClientImpl.class
-rw-r--r--    1 inoue    inoue        1851  2月 10 16:00 ClientImpl.java
-rw-rw-r--    1 inoue    inoue        1623  2月 10 16:52 ClientImpl_Skel.class
-rw-rw-r--    1 inoue    inoue        2915  2月 10 16:52 ClientImpl_Stub.class
-rw-rw-r--    1 inoue    inoue         242  2月 10 16:52 Server.class
-rw-r--r--    1 inoue    inoue         202  2月 10 16:00 Server.java
-rw-rw-r--    1 inoue    inoue        2148  2月 10 16:52 ServerImpl.class
-rw-r--r--    1 inoue    inoue        2019  2月 10 16:00 ServerImpl.java
-rw-rw-r--    1 inoue    inoue        1873  2月 10 16:52 ServerImpl_Skel.class
-rw-rw-r--    1 inoue    inoue        3346  2月 10 16:52 ServerImpl_Stub.class
[inoue@onlsbc1 CAMAC-array-ok8]$


   (2-2).  クライアント側、onlpara.kek.jp

     (2-2-1).  Javaのチェック

[inoue@onlpara CAMAC-array-ok8]$ java -version
java version "1.4.1-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-rc-b19)
Java HotSpot(TM) Client VM (build 1.4.1-rc-b19, mixed mode)
[inoue@onlpara CAMAC-array-ok8]$


     (2-2-2).  実行環境

[inoue@onlpara CAMAC-array-ok8]$ env
PWD=/home/inoue/JavaRMI/CAMAC/CAMAC-array-ok8
HOSTNAME=onlpara.kek.jp
QTDIR=/usr/lib/qt3-gcc2.96
LESSOPEN=|/usr/bin/lesspipe.sh %s
USER=inoue
LS_COLORS=no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;0
1:or=01;05;37;41:mi=01;05;37;41:ex=01;32:*.cmd=01;32:*.exe=01;32:*.com=01;32:*.b
tm=01;32:*.bat=01;32:*.sh=01;32:*.csh=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:
*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*
.bz=01;31:*.tz=01;31:*.rpm=01;31:*.cpio=01;31:*.jpg=01;35:*.gif=01;35:*.bmp=01;3
5:*.xbm=01;35:*.xpm=01;35:*.png=01;35:*.tif=01;35:
MAIL=/var/spool/mail/inoue
INPUTRC=/etc/inputrc
LANG=ja_JP.eucJP
SSH_CLIENT=130.87.153.2 3058 22
LOGNAME=inoue
SHLVL=1
SHELL=/bin/bash
HISTSIZE=1000
HOME=/home/inoue
TERM=vt100
SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
PATH=/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/usr/java/bin:/home/inoue/bin
JLESSCHARSET=japanese
SSH_TTY=/dev/pts/3
_=/usr/bin/env
OLDPWD=/home/inoue/JavaRMI/CAMAC
[inoue@onlpara CAMAC-array-ok8]$


     (2-2-3).  コンパイル

       (2-2-3a).  Client.java

	上記の項目(2-1-3a)を参照。


       (2-2-3b).  ClientImpl.java

        上記の項目(2-1-3b)を参照。


       (2-2-3c).  Server.java

        上記の項目(2-1-3c)を参照。


       (2-2-3d).  ServerImpl.java

        上記の項目(2-1-3d)を参照。

       (2-2-3e).  上記のソースプログラムをコンパイルする

[inoue@onlpara CAMAC-array-ok8]$ pwd
/home/inoue/JavaRMI/CAMAC/CAMAC-array-ok8
[inoue@onlpara CAMAC-array-ok8]$ javac *.java
[inoue@onlpara CAMAC-array-ok8]$ rmic ClientImpl
[inoue@onlpara CAMAC-array-ok8]$ rmic ServerImpl
[inoue@onlpara CAMAC-array-ok8]$ ls -l
合計 48
-rw-rw-r--    1 inoue    inoue         201  2月 10 16:38 Client.class
-rw-rw-r--    1 inoue    inoue         131  2月 10 15:45 Client.java
-rw-rw-r--    1 inoue    inoue        1842  2月 10 16:38 ClientImpl.class
-rw-r--r--    1 inoue    inoue        1851  2月 10 15:45 ClientImpl.java
-rw-rw-r--    1 inoue    inoue        1623  2月 10 16:38 ClientImpl_Skel.class
-rw-rw-r--    1 inoue    inoue        2915  2月 10 16:38 ClientImpl_Stub.class
-rw-rw-r--    1 inoue    inoue         242  2月 10 16:38 Server.class
-rw-r--r--    1 inoue    inoue         202  2月 10 15:45 Server.java
-rw-rw-r--    1 inoue    inoue        2148  2月 10 16:38 ServerImpl.class
-rw-r--r--    1 inoue    inoue        2019  2月 10 15:45 ServerImpl.java
-rw-rw-r--    1 inoue    inoue        1873  2月 10 16:38 ServerImpl_Skel.class
-rw-rw-r--    1 inoue    inoue        3346  2月 10 16:38 ServerImpl_Stub.class
[inoue@onlpara CAMAC-array-ok8]$


   (2-3).  実行

     (2-3-1).  サーバ側の起動

[inoue@onlsbc1 CAMAC-array-ok8]$ rmiregistry &
[1] 1570
[inoue@onlsbc1 CAMAC-array-ok8]$ java ServerImpl
bind done
 Server side:
    cmd[0] = 0
    cmd[1] = 1
    cmd[2] = 2
    cmd[3] = 3
    dat[0] = 5
    dat[1] = 6
    dat[2] = 7
    dat[3] = 8
					<--- CTL-C でクライアントを停止した。
[inoue@onlsbc1 CAMAC-array-ok8]$
[inoue@onlsbc1 CAMAC-array-ok8]$ kill -KILL 1570
[inoue@onlsbc1 CAMAC-array-ok8]$
[1]+  Killed                  rmiregistry
[inoue@onlsbc1 CAMAC-array-ok8]$


     (2-3-2).  クライアント側の起動

[inoue@onlpara CAMAC-array-ok8]$ rmiregistry &
[1] 2680
[inoue@onlpara CAMAC-array-ok8]$ java ClientImpl onlsbc1
 Client side:
    c_reply[0] = 8
    c_reply[1] = 7
    c_reply[2] = 6
    c_reply[3] = 5
    d_reply[0] = 4
    d_reply[1] = 3
    d_reply[2] = 2
    d_reply[3] = 1
					<--- CTL-C でクライアントを停止した。
[inoue@onlpara CAMAC-array-ok8]$
[inoue@onlpara CAMAC-array-ok8]$ kill -KILL 2680
[inoue@onlpara CAMAC-array-ok8]$
[1]+  Killed                  rmiregistry
[inoue@onlpara CAMAC-array-ok8]$

	ok.  コールバックでの arrayデータの受け渡しは正常に実行できた。


 (3). onlsbc1 側の JNIプログラムとRMIプロプラムをひとつに組み合わせる

   (3-1).  サーバ側、onlsbc1.kek.jp のソース

[inoue@onlsbc1 CAMAC-array-ok11]$ pwd
/home/inoue/JavaRMI/CAMAC/CAMAC-array-ok11
[inoue@onlsbc1 CAMAC-array-ok11]$ ls -l
合計 32
-rw-rw-r--    1 inoue    inoue         131  2月 12 14:17 Client.java
-rw-r--r--    1 inoue    inoue        2134  2月 12 14:17 ClientImpl.java
-rw-rw-r--    1 inoue    inoue         785  2月 12 16:27 Makefile
-rw-r--r--    1 inoue    inoue         202  2月 12 14:17 Server.java
-rw-r--r--    1 inoue    inoue        2951  2月 12 16:04 ServerImpl.java
-rw-rw-r--    1 inoue    inoue        4803  2月 13 09:01 camac.c
-rw-rw-r--    1 inoue    inoue        1751  2月 12 15:57 camac.java
[inoue@onlsbc1 CAMAC-array-ok11]$

     (3-1-1).  コンパイル

       (3-1-1a).  Client.java

[inoue@onlsbc1 CAMAC-array-ok11]$ cat Client.java
public interface Client extends java.rmi.Remote {
        public void camac_reply( int[] ia, int[] ib) throws java.rmi.RemoteExcep
tion;
}
[inoue@onlsbc1 CAMAC-array-ok11]$


       (3-1-1b).  ClientImpl.java

[inoue@onlsbc1 CAMAC-array-ok11]$ cat ClientImpl.java
import java.rmi.*;
import java.rmi.server.*;

class ClientImpl implements Client {
        static Server server;

        public ClientImpl(String host) {
                try{
                   UnicastRemoteObject.exportObject(this);
                   Server server = (Server)Naming.lookup("//"+host+"/Server");
                   server.register(this);
                   ClientImpl.server = server;
                } catch ( Exception e ) {
                   System.err.println ("Failed to setup for RMI");
                }
        }

        public void camac_exec() {
                int[]  s_cmd, s_dat;

                try{
                int[] array_sizes = {4096*16};

                // to send int array
                        s_cmd = new int[array_sizes[0]];
                        s_dat = new int[array_sizes[0]];

                        s_cmd[0] = 0;
                        s_cmd[1] = 1;
                        s_cmd[2] = 2;
                        s_cmd[3] = 3;

                        s_dat[0] = 5;
                        s_dat[1] = 6;
                        s_dat[2] = 7;
                        s_dat[3] = 8;


                        ClientImpl.server.camac_cmd(s_cmd, s_dat);
                } catch ( Exception e ) {
                   System.err.println ("Failed to setup for RMI step2");
                }
        }

        public void camac_reply( int[] c_reply, int[] d_reply) throws RemoteExce
ption {
                System.out.println(" Client side: ");
                System.out.println("    c_reply[0] = " + c_reply[0]);
                System.out.println("    c_reply[1] = " + c_reply[1]);
                System.out.println("    c_reply[2] = " + c_reply[2]);
                System.out.println("    c_reply[3] = " + c_reply[3]);
                System.out.println("    d_reply[0] = " + d_reply[0]);
                System.out.println("    d_reply[1] = " + d_reply[1]);
                System.out.println("    d_reply[2] = " + d_reply[2]);
                System.out.println("    d_reply[3] = " + d_reply[3]);
        }

        public static void main(String argv[]) throws Exception{

                String  host = (argv.length == 1) ? argv[0] : "localhost";
                ClientImpl obj = new ClientImpl(host);
                obj.camac_exec();
        }
}
[inoue@onlsbc1 CAMAC-array-ok11]$


       (3-1-1c).  Server.java

[inoue@onlsbc1 CAMAC-array-ok11]$ cat Server.java
import java.rmi.*;

public interface Server extends java.rmi.Remote {
        void register(Client aclient) throws java.rmi.RemoteException;
        void camac_cmd(int[] ia, int[] ib) throws RemoteException;
}
[inoue@onlsbc1 CAMAC-array-ok11]$


       (3-1-1d).  ServerImpl.java

[inoue@onlsbc1 CAMAC-array-ok11]$ more ServerImpl.java
import java.rmi.*;
import java.rmi.server.*;

public class ServerImpl extends UnicastRemoteObject implements Server {
        Client client;
        static String serverName;
        static int[] r_cmd, r_dat;


        static {
                try {
                        serverName = java.net.InetAddress.getLocalHost().getHost
Name();
                }catch(Exception e){
                        serverName = "localhost";
                }
        }

        public ServerImpl() throws Exception {
                super();
                r_cmd = new int[4096*16];
                r_dat = new int[4096*16];

        }

        public Server createInstance() throws RemoteException {
                ServerImpl obj = null;

                try {
                        obj = new ServerImpl();
                        return obj;
                }catch(Exception e){
                        e.printStackTrace();
                }

                return obj;
        }

        public void register (Client aclient) {
                client = aclient;
        }

        public void camac_cmd(int[] cmd, int[] dat) throws RemoteException{
// E.Inoue

        if ( cmd.length > 1 ) {
           System.out.println(" Server side: ");
           System.out.println("    cmd[0] = " + cmd[0]);
           System.out.println("    cmd[1] = " + cmd[1]);
           System.out.println("    cmd[2] = " + cmd[2]);
           System.out.println("    cmd[3] = " + cmd[3]);
           System.out.println("    dat[0] = " + dat[0]);
           System.out.println("    dat[1] = " + dat[1]);
           System.out.println("    dat[2] = " + dat[2]);
           System.out.println("    dat[3] = " + dat[3]);
        }

        ServerImpl.r_cmd[0] = 8;
        ServerImpl.r_cmd[1] = 7;
        ServerImpl.r_cmd[2] = 6;
        ServerImpl.r_cmd[3] = 5;
        ServerImpl.r_dat[0] = 4;
        ServerImpl.r_dat[1] = 3;
        ServerImpl.r_dat[2] = 2;
        ServerImpl.r_dat[3] = 1;
        client.camac_reply (ServerImpl.r_cmd, ServerImpl.r_dat);
//end
//JNI
    try{
    camac p = new camac();
    int j_cmd[] = new int [11];
    int j_dat[] = new int [11];
    for (int i = 0; i < 10; i++){
      j_cmd[i] = i;
      j_dat[i] = i + 20;
    }

    System.out.println("Java side: before Native Call");
    for (int i = 0; i < 10; i++)
       System.out.println("   j_cmd[" + i + "] = " + j_cmd[i] + ", j_dat[" + i +

 "] = " + j_dat[i]);

    int sum = p.cmdArray(j_cmd, j_dat);

    System.out.println("Java side:  after Native Call");
    for (int i = 0; i < 10; i++)
       System.out.println("   j_cmd[" + i + "] = " + Integer.toHexString(j_cmd[i

]) + ", j_dat[" + i + "] = " + j_dat[i]);
       int i = 10;
       System.out.println("   j_cmd[" + i + "] = " + Integer.toHexString(j_cmd[i

]) + ", j_dat[" + i + "] = " + Integer.toHexString(j_dat[i]));
   } catch ( Exception e ) {
       System.err.println ("Failed to exec for camac");
   }

//JNI end
        }

        public static void main(String argv[]) throws Exception {
                //System.setSecurityManager(new RMISecurityManager());
                ServerImpl obj = new ServerImpl();
                Naming.bind("//"+serverName+"/Server", obj);
                System.out.println("bind done");
        }
}
[inoue@onlsbc1 CAMAC-array-ok11]$


       (3-1-1e).  camac.java

[inoue@onlsbc1 CAMAC-array-ok11]$ more camac.c
/*
// file name:  camac.c
//
// Parallel camac
// packet format of basic camac opeation
// TX
// +---------+-------+-------+-------+-------+---------------------------+
// |   cmd   |   N   |   A   |   F   |       |       24-bit DATA         |
// +---------+-------+-------+-------+-------+---------------------------+
//
// RX
// +---------+-------+-------+-------+-------+---------------------------+
// |  rply   |   N   |   A   |   F   |  ST   |       24-bit DATA         |
// +---------+-------+-------+-------+-------+---------------------------+
*/

/* rw.c */
#include    
/* rw.c end */

#include    
#include    
#include    "camac.h"

/* add */
    unsigned long long int value;
    unsigned int camac;
/* add end */

/* rw.c */
#define BASE 0xE800
#define TX_DATA1REG BASE
#define TX_DATA2REG (BASE+4)
/* #define TX_STATUSREG (BASE+0x10) */
#define TX_STATUSREG (BASE+0x1c)
#define TXSTATUS_BUSY 0x10000
#define TXSTATUS_TIMEOUT 0x20000
#define RX_DATA1REG (BASE+0x20)
#define RX_DATA2REG (BASE+0x24)
/* #define RX_FIFOREG  (BASE+0x30) */
#define RX_FIFOREG  (BASE+0x3c)
/*
#define CMD_F16_A0_N4 0xE0040010
#define CMD_F0_A0_N4 0xE0040000
*/
#define CMD_F16_A0_N3 0xE0030010
#define CMD_F0_A0_N3 0xE0030000
/* rw.c end */


JNIEXPORT jint JNICALL
Java_camac_cmdArray(JNIEnv *env, jobject obj, jintArray j_cmd, jintArray j_dat)
{
   int i, sum = 0;
   jsize len = (*env)->GetArrayLength(env, j_cmd);
   jint *c_cmd = (*env)->GetIntArrayElements(env, j_cmd, 0);

   jsize len2 = (*env)->GetArrayLength(env, j_dat);
   jint *c_dat = (*env)->GetIntArrayElements(env, j_dat, 0);

/* rw.c */
  int loop = 10;
/*  int i, ii, j, data, cmd, value; */
  int ii, j, data, cmd, value;

  printf("loop=%d\n", loop);
/* rw.c end */


   printf("In C: Step 1\n");
   for (i=0; i> 24;
 */
    } while( value < 2 );

/*
  camacからの受信用レジスタを読んで camacからの応答を得る
*/
    data = inl(RX_DATA1REG);
    cmd = inl(RX_DATA2REG);
    printf("camac write command reply:  cmd = %x : data = %x\n", cmd, data);

/*
  送信可能状態になるまで待つ
*/
    value = inl(TX_STATUSREG);
    while (value & TXSTATUS_BUSY) {
      if (value & TXSTATUS_TIMEOUT) break;
      value = inl(TX_STATUSREG);
    }

/*
  camac readコマンド&データをセットして、PCIレジスタに書き込む
*/
/*    outl(CMD_F0_A0_N4, TX_DATA2REG); */
    outl(CMD_F0_A0_N3, TX_DATA2REG);

/*
  camac応答が読み出し可能状態になるまで待つ
*/
    value = 0;
    do {
      value = inl(RX_FIFOREG);
/* for PCI ROM of new version
      value = value >> 24;
*/
    } while( value < 2);

/*
  camacからの受信用レジスタを読んで camacからの応答を得る
*/
    data = inl(RX_DATA1REG);
    cmd = inl(RX_DATA2REG);
    data = 0xffffff & data;
    ii = 0xffffff & i;
//    printf("cmd = %x : data = %x\n", cmd, data);
    printf("camac read command reply:  cmd = %x : data = %x\n", cmd, data);
    if( data != ii ) {
      printf( "written data = %x : read data = %x\n", ii, data);
      exit(0);
    }
/* E.Inoue
    cmd = 0xffffffff & cmd;
 end */
    c_cmd[i] = cmd;
    c_dat[i] = data;
  }

/*  printf("i = %d\n", i); */
  c_cmd[i] = 0xffffffff;
  c_dat[i] = 0xffffffff;

/* rw.c end */

printf("In C: Step 4\n");
  (*env)->ReleaseIntArrayElements(env, j_cmd, c_cmd, 0);
  (*env)->ReleaseIntArrayElements(env, j_dat, c_dat, 0);
  return sum;
}
[inoue@onlsbc1 CAMAC-array-ok11]$


       (3-1-1f).  camac.c

[inoue@onlsbc1 CAMAC-array-ok11]$ cat camac.java
// file name:  camac.java
//
// Parallel camac
// packet format of basic camac opeation
// TX
// +---------+-------+-------+-------+-------+---------------------------+
// |   cmd   |   N   |   A   |   F   |       |       24-bit DATA         |
// +---------+-------+-------+-------+-------+---------------------------+
//
// RX
// +---------+-------+-------+-------+-------+---------------------------+
// |  rply   |   N   |   A   |   F   |  ST   |       24-bit DATA         |
// +---------+-------+-------+-------+-------+---------------------------+


public class camac {

  public camac () throws Exception {
        try{
        } catch ( Exception e ) {
           System.err.println (" Failed to setup camac");
        }
}

//  private native int cmdArray(int j_cmd[], int j_dat[]);
  public native int cmdArray(int j_cmd[], int j_dat[]);
  public static void main(String args[]) {
    long lj_cmd;

//    camac p = new camac();
//    int j_cmd[] = new int [11];
//    int j_dat[] = new int [11];
//    for (int i = 0; i < 10; i++){
//      j_cmd[i] = i;
//      j_dat[i] = i + 20;
//    }

//    System.out.println("Java side: before Native Call");
//    for (int i = 0; i < 10; i++)
//       System.out.println("   j_cmd[" + i + "] = " + j_cmd[i] + ", j_dat[" + i
 + "] = " + j_dat[i]);

//    int sum = p.cmdArray(j_cmd, j_dat);

//    System.out.println("Java side:  after Native Call");
//    for (int i = 0; i < 10; i++)
//       System.out.println("   j_cmd[" + i + "] = " + Integer.toHexString(j_cmd
[i]) + ", j_dat[" + i + "] = " + j_dat[i]);
//    int i = 10;
//    System.out.println("   j_cmd[" + i + "] = " + Integer.toHexString(j_cmd[i]
) + ", j_dat[" + i + "] = " + Integer.toHexString(j_dat[i]));
  }
  static {
    System.loadLibrary("MyImpOfcamac");
  }
}
[inoue@onlsbc1 CAMAC-array-ok11]$


       (3-1-1g).  Makefile

[inoue@onlsbc1 CAMAC-array-ok11]$ cat Makefile

all : camac.class camac.h libMyImpOfcamac.so Client.class ClientImpl.class Serve
r.class ServerImpl.class ClientImpl_Skel.class ClientImpl_Stub.class ServerImpl_
Skel.class ServerImpl_Stub.class

camac.class:    camac.java
        javac camac.java

Client.class:   Client.java
        javac Client.java

ClientImpl.class:       ClientImpl.java
        javac ClientImpl.java

Server.class:   Server.java
        javac   Server.java

ServerImpl.class:       ServerImpl.java
        javac   ServerImpl.java

ClientImpl_Skel.class:  ClientImpl.class
        rmic ClientImpl

ServerImpl_Skel.class:  ServerImpl.class
        rmic ServerImpl


camac.h:        camac.class
        javah -jni camac

libMyImpOfcamac.so:     camac.c
        gcc -O -shared -I/usr/java/include -I/usr/java/include/linux camac.c -o
libMyImpOfcamac.so

clean:
        rm -f *.class camac.h libMyImpOfcamac.so *.o core *~
[inoue@onlsbc1 CAMAC-array-ok11]$


       (3-1-1h).  コンパイル

[inoue@onlsbc1 CAMAC-array-ok11]$ make clean
rm -f *.class camac.h libMyImpOfcamac.so *.o core *~
[inoue@onlsbc1 CAMAC-array-ok11]$ make
javac camac.java
javah -jni camac
gcc -O -shared -I/usr/java/include -I/usr/java/include/linux camac.c -o libMyImp
Ofcamac.so
javac Client.java
javac ClientImpl.java
javac   ServerImpl.java
rmic ClientImpl
rmic ServerImpl
[inoue@onlsbc1 CAMAC-array-ok11]$ ls -l
合計 80
-rw-rw-r--    1 inoue    inoue         201  2月 13 10:21 Client.class
-rw-rw-r--    1 inoue    inoue         131  2月 12 14:17 Client.java
-rw-rw-r--    1 inoue    inoue        1995  2月 13 10:21 ClientImpl.class
-rw-r--r--    1 inoue    inoue        2134  2月 12 14:17 ClientImpl.java
-rw-rw-r--    1 inoue    inoue        1623  2月 13 10:21 ClientImpl_Skel.class
-rw-rw-r--    1 inoue    inoue        2915  2月 13 10:21 ClientImpl_Stub.class
-rw-rw-r--    1 inoue    inoue         785  2月 12 16:27 Makefile
-rw-rw-r--    1 inoue    inoue         242  2月 13 10:21 Server.class
-rw-r--r--    1 inoue    inoue         202  2月 12 14:17 Server.java
-rw-rw-r--    1 inoue    inoue        2838  2月 13 10:21 ServerImpl.class
-rw-r--r--    1 inoue    inoue        2951  2月 12 16:04 ServerImpl.java
-rw-rw-r--    1 inoue    inoue        1873  2月 13 10:21 ServerImpl_Skel.class
-rw-rw-r--    1 inoue    inoue        3346  2月 13 10:21 ServerImpl_Stub.class
-rw-rw-r--    1 inoue    inoue        4803  2月 13 09:01 camac.c
-rw-rw-r--    1 inoue    inoue         490  2月 13 10:20 camac.class
-rw-rw-r--    1 inoue    inoue         384  2月 13 10:20 camac.h
-rw-rw-r--    1 inoue    inoue        1751  2月 12 15:57 camac.java
-rwxrwxr-x    1 inoue    inoue        7456  2月 13 10:20 libMyImpOfcamac.so
[inoue@onlsbc1 CAMAC-array-ok11]$


   (3-2).  クライアント側、onlpara.kek.jp のソース

[inoue@onlpara CAMAC-array-ok11]$ pwd
/home/inoue/JavaRMI/CAMAC/CAMAC-array-ok11
[inoue@onlpara CAMAC-array-ok11]$ ls -l
合計 20
-rw-rw-r--    1 inoue    inoue         131  2月 12 14:01 Client.java
-rw-r--r--    1 inoue    inoue        2134  2月 12 14:01 ClientImpl.java
-rw-rw-r--    1 inoue    inoue         515  2月 13 09:37 Makefile
-rw-r--r--    1 inoue    inoue         202  2月 12 14:01 Server.java
-rw-r--r--    1 inoue    inoue        2019  2月 12 14:01 ServerImpl.java
[inoue@onlpara CAMAC-array-ok11]$

     (3-2-1).  コンパイル

       (3-2-1a).  Client.java

[inoue@onlpara CAMAC-array-ok11]$ cat Client.java
public interface Client extends java.rmi.Remote {
        public void camac_reply( int[] ia, int[] ib) throws java.rmi.RemoteExcep
tion;
}
[inoue@onlpara CAMAC-array-ok11]$


       (3-2-1b).  ClientImpl.java

[inoue@onlpara CAMAC-array-ok11]$ cat ClientImpl.java
import java.rmi.*;
import java.rmi.server.*;

class ClientImpl implements Client {
        static Server server;

        public ClientImpl(String host) {
                try{
                   UnicastRemoteObject.exportObject(this);
                   Server server = (Server)Naming.lookup("//"+host+"/Server");
                   server.register(this);
                   ClientImpl.server = server;
                } catch ( Exception e ) {
                   System.err.println ("Failed to setup for RMI");
                }
        }

        public void camac_exec() {
                int[]  s_cmd, s_dat;

                try{
                int[] array_sizes = {4096*16};

                // to send int array
                        s_cmd = new int[array_sizes[0]];
                        s_dat = new int[array_sizes[0]];

                        s_cmd[0] = 0;
                        s_cmd[1] = 1;
                        s_cmd[2] = 2;
                        s_cmd[3] = 3;

                        s_dat[0] = 5;
                        s_dat[1] = 6;
                        s_dat[2] = 7;
                        s_dat[3] = 8;


                        ClientImpl.server.camac_cmd(s_cmd, s_dat);
                } catch ( Exception e ) {
                   System.err.println ("Failed to setup for RMI step2");
                }
        }

        public void camac_reply( int[] c_reply, int[] d_reply) throws RemoteExce
ption {
                System.out.println(" Client side: ");
                System.out.println("    c_reply[0] = " + c_reply[0]);
                System.out.println("    c_reply[1] = " + c_reply[1]);
                System.out.println("    c_reply[2] = " + c_reply[2]);
                System.out.println("    c_reply[3] = " + c_reply[3]);
                System.out.println("    d_reply[0] = " + d_reply[0]);
                System.out.println("    d_reply[1] = " + d_reply[1]);
                System.out.println("    d_reply[2] = " + d_reply[2]);
                System.out.println("    d_reply[3] = " + d_reply[3]);
        }

        public static void main(String argv[]) throws Exception{

                String  host = (argv.length == 1) ? argv[0] : "localhost";
                ClientImpl obj = new ClientImpl(host);
                obj.camac_exec();
        }
}
[inoue@onlpara CAMAC-array-ok11]$


       (3-2-1c).  Server.java

[inoue@onlpara CAMAC-array-ok11]$ cat Server.java
import java.rmi.*;

public interface Server extends java.rmi.Remote {
        void register(Client aclient) throws java.rmi.RemoteException;
        void camac_cmd(int[] ia, int[] ib) throws RemoteException;
}
[inoue@onlpara CAMAC-array-ok11]$


       (3-2-1d).  ServerImpl.java

[inoue@onlpara CAMAC-array-ok11]$ cat ServerImpl.java
import java.rmi.*;
import java.rmi.server.*;

public class ServerImpl extends UnicastRemoteObject implements Server {
        Client client;
        static String serverName;
        static int[] r_cmd, r_dat;


        static {
                try {
                        serverName = java.net.InetAddress.getLocalHost().getHost
Name();
                }catch(Exception e){
                        serverName = "localhost";
                }
        }

        public ServerImpl() throws Exception {
                super();
                r_cmd = new int[4096*16];
                r_dat = new int[4096*16];

        }

        public Server createInstance() throws RemoteException {
                ServerImpl obj = null;

                try {
                        obj = new ServerImpl();
                        return obj;
                }catch(Exception e){
                        e.printStackTrace();
                }

                return obj;
        }

        public void register (Client aclient) {
                client = aclient;
        }

        public void camac_cmd(int[] cmd, int[] dat) throws RemoteException{
// E.Inoue

        if ( cmd.length > 1 ) {
           System.out.println(" Server side: ");
           System.out.println("    cmd[0] = " + cmd[0]);
           System.out.println("    cmd[1] = " + cmd[1]);
           System.out.println("    cmd[2] = " + cmd[2]);
           System.out.println("    cmd[3] = " + cmd[3]);
           System.out.println("    dat[0] = " + dat[0]);
           System.out.println("    dat[1] = " + dat[1]);
           System.out.println("    dat[2] = " + dat[2]);
           System.out.println("    dat[3] = " + dat[3]);
        }

        ServerImpl.r_cmd[0] = 8;
        ServerImpl.r_cmd[1] = 7;
        ServerImpl.r_cmd[2] = 6;
        ServerImpl.r_cmd[3] = 5;
        ServerImpl.r_dat[0] = 4;
        ServerImpl.r_dat[1] = 3;
        ServerImpl.r_dat[2] = 2;
        ServerImpl.r_dat[3] = 1;
        client.camac_reply (ServerImpl.r_cmd, ServerImpl.r_dat);
//end
        }

        public static void main(String argv[]) throws Exception {
                //System.setSecurityManager(new RMISecurityManager());
                ServerImpl obj = new ServerImpl();
                Naming.bind("//"+serverName+"/Server", obj);
                System.out.println("bind done");
        }
}
[inoue@onlpara CAMAC-array-ok11]$


       (3-2-1e).  Makefile

[inoue@onlpara CAMAC-array-ok11]$ cat Makefile

all : Client.class ClientImpl.class Server.class ServerImpl.class ClientImpl_Ske
l.class ClientImpl_Stub.class ServerImpl_Skel.class ServerImpl_Stub.class


Client.class:   Client.java
        javac Client.java

ClientImpl.class:       ClientImpl.java
        javac ClientImpl.java

Server.class:   Server.java
        javac   Server.java

ServerImpl.class:       ServerImpl.java
        javac   ServerImpl.java

ClientImpl_Skel.class:  ClientImpl.class
        rmic ClientImpl

ServerImpl_Skel.class:  ServerImpl.class
        rmic ServerImpl

clean:
        rm -f *.class *.o core *~
[inoue@onlpara CAMAC-array-ok11]$


       (3-2-1f).  コンパイル

[inoue@onlpara CAMAC-array-ok11]$ make clean
rm -f *.class *.o core *~
[inoue@onlpara CAMAC-array-ok11]$ make
javac Client.java
javac ClientImpl.java
javac   ServerImpl.java
rmic ClientImpl
rmic ServerImpl
[inoue@onlpara CAMAC-array-ok11]$ ls -l
合計 52
-rw-rw-r--    1 inoue    inoue         201  2月 13 10:07 Client.class
-rw-rw-r--    1 inoue    inoue         131  2月 12 14:01 Client.java
-rw-rw-r--    1 inoue    inoue        1995  2月 13 10:07 ClientImpl.class
-rw-r--r--    1 inoue    inoue        2134  2月 12 14:01 ClientImpl.java
-rw-rw-r--    1 inoue    inoue        1623  2月 13 10:07 ClientImpl_Skel.class
-rw-rw-r--    1 inoue    inoue        2915  2月 13 10:07 ClientImpl_Stub.class
-rw-rw-r--    1 inoue    inoue         515  2月 13 09:37 Makefile
-rw-rw-r--    1 inoue    inoue         242  2月 13 10:07 Server.class
-rw-r--r--    1 inoue    inoue         202  2月 12 14:01 Server.java
-rw-rw-r--    1 inoue    inoue        2148  2月 13 10:07 ServerImpl.class
-rw-r--r--    1 inoue    inoue        2019  2月 12 14:01 ServerImpl.java
-rw-rw-r--    1 inoue    inoue        1873  2月 13 10:07 ServerImpl_Skel.class
-rw-rw-r--    1 inoue    inoue        3346  2月 13 10:07 ServerImpl_Stub.class
[inoue@onlpara CAMAC-array-ok11]$


   (3-3).  サーバ側のプログラムの起動

	onlsbc1 のSBCからPCIへアクセスする前に、PCIのシステムレジスタに 1を書き
	込んで CAMAC 用の FPGA をイニシャライズしないと CAMACにアクセスできない
	ようになっている。 今回のテストに使用しているネイティブコードには、この
	ための操作は含んでいない。 したがって、サーバ側のプログラムを起動する前
	に手動でこの操作をする必要がある。 これは、以下の一行のコマンドで行う。

	# ./w e840 1

[root@onlsbc1 CAMAC-array-ok11]# pwd
/home/inoue/JavaRMI/CAMAC/CAMAC-array-ok11
[root@onlsbc1 CAMAC-array-ok11]# rmiregistry &
[1] 4228
[root@onlsbc1 CAMAC-array-ok11]# export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH
[root@onlsbc1 CAMAC-array-ok11]# java camac
[root@onlsbc1 CAMAC-array-ok11]# java ServerImpl
bind done
 Server side:
    cmd[0] = 0
    cmd[1] = 1
    cmd[2] = 2
    cmd[3] = 3
    dat[0] = 5
    dat[1] = 6
    dat[2] = 7
    dat[3] = 8
Java side: before Native Call
   j_cmd[0] = 0, j_dat[0] = 20
   j_cmd[1] = 1, j_dat[1] = 21
   j_cmd[2] = 2, j_dat[2] = 22
   j_cmd[3] = 3, j_dat[3] = 23
   j_cmd[4] = 4, j_dat[4] = 24
   j_cmd[5] = 5, j_dat[5] = 25
   j_cmd[6] = 6, j_dat[6] = 26
   j_cmd[7] = 7, j_dat[7] = 27
   j_cmd[8] = 8, j_dat[8] = 28
   j_cmd[9] = 9, j_dat[9] = 29
loop=10
In C: Step 1
      c_cmd[0] = 0, c_dat[0] = 20
      c_cmd[1] = 1, c_dat[1] = 21
      c_cmd[2] = 2, c_dat[2] = 22
      c_cmd[3] = 3, c_dat[3] = 23
      c_cmd[4] = 4, c_dat[4] = 24
      c_cmd[5] = 5, c_dat[5] = 25
      c_cmd[6] = 6, c_dat[6] = 26
      c_cmd[7] = 7, c_dat[7] = 27
      c_cmd[8] = 8, c_dat[8] = 28
      c_cmd[9] = 9, c_dat[9] = 29
      c_cmd[10] = 0, c_dat[10] = 0
In C: Step 2
      c_cmd[0] = 10, c_dat[0] = 20
      c_cmd[1] = 11, c_dat[1] = 19
      c_cmd[2] = 12, c_dat[2] = 18
      c_cmd[3] = 13, c_dat[3] = 17
      c_cmd[4] = 14, c_dat[4] = 16
      c_cmd[5] = 15, c_dat[5] = 15
      c_cmd[6] = 16, c_dat[6] = 14
      c_cmd[7] = 17, c_dat[7] = 13
      c_cmd[8] = 18, c_dat[8] = 12
      c_cmd[9] = 19, c_dat[9] = 11
      c_cmd[10] = 10, c_dat[10] = -20
In C: Step 3
      size of int = 4, size of long long int = 8
      0x9 = inl(0xe800)
      0xe0030000 = inl(0xe804)
camac write data:  data = 0
camac write command reply:  cmd = e0030010 : data = 23000000
camac read command reply:  cmd = e0030000 : data = 0
camac write data:  data = 1
camac write command reply:  cmd = e0030010 : data = 23000000
camac read command reply:  cmd = e0030000 : data = 1
camac write data:  data = 2
camac write command reply:  cmd = e0030010 : data = 23000000
camac read command reply:  cmd = e0030000 : data = 2
camac write data:  data = 3
camac write command reply:  cmd = e0030010 : data = 23000000
camac read command reply:  cmd = e0030000 : data = 3
camac write data:  data = 4
camac write command reply:  cmd = e0030010 : data = 23000000
camac read command reply:  cmd = e0030000 : data = 4
camac write data:  data = 5
camac write command reply:  cmd = e0030010 : data = 23000000
camac read command reply:  cmd = e0030000 : data = 5
camac write data:  data = 6
camac write command reply:  cmd = e0030010 : data = 23000000
camac read command reply:  cmd = e0030000 : data = 6
camac write data:  data = 7
camac write command reply:  cmd = e0030010 : data = 23000000
camac read command reply:  cmd = e0030000 : data = 7
camac write data:  data = 8
camac write command reply:  cmd = e0030010 : data = 23000000
camac read command reply:  cmd = e0030000 : data = 8
camac write data:  data = 9
camac write command reply:  cmd = e0030010 : data = 23000000
camac read command reply:  cmd = e0030000 : data = 9
In C: Step 4
Java side:  after Native Call
   j_cmd[0] = e0030000, j_dat[0] = 0
   j_cmd[1] = e0030000, j_dat[1] = 1
   j_cmd[2] = e0030000, j_dat[2] = 2
   j_cmd[3] = e0030000, j_dat[3] = 3
   j_cmd[4] = e0030000, j_dat[4] = 4
   j_cmd[5] = e0030000, j_dat[5] = 5
   j_cmd[6] = e0030000, j_dat[6] = 6
   j_cmd[7] = e0030000, j_dat[7] = 7
   j_cmd[8] = e0030000, j_dat[8] = 8
   j_cmd[9] = e0030000, j_dat[9] = 9
   j_cmd[10] = ffffffff, j_dat[10] = ffffffff
[root@onlsbc1 CAMAC-array-ok11]#


   (3-4).  クライアント側のプログラムの起動

[inoue@onlpara CAMAC-array-ok11]$ pwd
/home/inoue/JavaRMI/CAMAC/CAMAC-array-ok11
[inoue@onlpara CAMAC-array-ok11]$ rmiregistry &
[1] 9902
[inoue@onlpara CAMAC-array-ok11]$ java ClientImpl onlsbc1
 Client side:
    c_reply[0] = 8
    c_reply[1] = 7
    c_reply[2] = 6
    c_reply[3] = 5
    d_reply[0] = 4
    d_reply[1] = 3
    d_reply[2] = 2
    d_reply[3] = 1
[inoue@onlpara CAMAC-array-ok11]$

	ok.  リモートマシンonlpara から サーバマシンonlsbc1 への JavaRMI および
	JNI を使った一連のやり取りは正常に実行できた。 続いて、camac への読み
	書きをテストする。


 (4). リモートマシンonlpara からの CAMAC読み書き

   (4-1).  サーバ側、onlsbc1.kek.jp のソース

     (4-1-1).  コンパイル

[inoue@onlsbc1 CAMAC-array-ok18]$ pwd
/home/inoue/JavaRMI/CAMAC/CAMAC-array-ok18
[inoue@onlsbc1 CAMAC-array-ok18]$ ls -l
合計 28
-rw-rw-r--    1 inoue    inoue         213  2月 20 10:38 Client.java
-rw-r--r--    1 inoue    inoue        3104  2月 20 10:38 ClientImpl.java
-rw-rw-r--    1 inoue    inoue         852  2月 20 10:38 Makefile
-rw-r--r--    1 inoue    inoue         288  2月 20 10:38 Server.java
-rw-r--r--    1 inoue    inoue        2417  2月 20 10:38 ServerImpl.java
-rw-rw-r--    1 inoue    inoue        3839  2月 20 10:38 camac.c
-rw-rw-r--    1 inoue    inoue         828  2月 20 10:38 camac.java
[inoue@onlsbc1 CAMAC-array-ok18]$


       (4-1-1a).  Client.java

[inoue@onlsbc1 CAMAC-array-ok18]$ cat Client.java
// File Name: Client.java
// Date: Feb 19, 2003
// Edited by: Eiji Inoue

public interface Client extends java.rmi.Remote {
        public void camac_reply( int[] ia, int[] ib, int ic) throws java.rmi.Rem
oteException;
}
[inoue@onlsbc1 CAMAC-array-ok18]$


       (4-1-1b).  ClientImpl.java

[inoue@onlsbc1 CAMAC-array-ok18]$ cat ClientImpl.java
// File Name: ClientImpl.java
// Date: Feb 19, 2003
// Edited by: Eiji Inoue

import java.rmi.*;
import java.rmi.server.*;

class ClientImpl implements Client {
        public static final int  CMD_F16_A0_N3 = 0xE0030010;
        public static final int  CMD_F0_A0_N3  = 0xE0030000;

        static Server server;

        public ClientImpl(String host) {
                try{
                   UnicastRemoteObject.exportObject(this);
                   Server server = (Server)Naming.lookup("//"+host+"/Server");
                   server.register(this);
                   ClientImpl.server = server;
                } catch ( Exception e ) {
                   System.err.println ("Failed to setup for RMI");
                }
        }

        public void camac_exec() {
                int[]  s_cmd, s_dat;
                int[] array_sizes = {4096*16};
                int    s_length;
                int    j;

                try{
                System.out.println(" RMI: Client side: ");
                // to send int array
                        s_cmd = new int[array_sizes[0]];
                        s_dat = new int[array_sizes[0]];

                        s_cmd[0] = ClientImpl.CMD_F16_A0_N3;
                        s_cmd[1] = ClientImpl.CMD_F0_A0_N3;
                        s_cmd[2] = ClientImpl.CMD_F16_A0_N3;
                        s_cmd[3] = ClientImpl.CMD_F0_A0_N3;
                        s_cmd[4] = ClientImpl.CMD_F16_A0_N3;
                        s_cmd[5] = ClientImpl.CMD_F0_A0_N3;
                        s_cmd[6] = ClientImpl.CMD_F16_A0_N3;
                        s_cmd[7] = ClientImpl.CMD_F0_A0_N3;

                        s_dat[0] = 5;
                        s_dat[1] = 0;
                        s_dat[2] = 6;
                        s_dat[3] = 0;
                        s_dat[4] = 7;
                        s_dat[5] = 0;
                        s_dat[6] = 8;
                        s_dat[7] = 0;

                        s_length = 8;

                        System.out.println("   RMI: Sent CAMAC command: array le
ngth =" + s_length);
                        for (int i = 0; i < s_length + 1; i++)
                            System.out.println("      s_cmd[" + i + "] = 0x" + I
nteger.toHexString(s_cmd[i]) + ", s_dat[" + i + "] = 0x" + Integer.toHexString(s
_dat[i]));


                        ClientImpl.server.camac_cmd(s_cmd, s_dat, s_length);
                } catch ( Exception e ) {
                   System.err.println ("Failed to setup for RMI step2");
                }
        }

        public void camac_reply( int[] c_reply, int[] d_reply, int l_reply) thro
ws RemoteException {
                System.out.println();
                System.out.println("   RMI: Received CAMAC reply: " + "array len
gth = " + l_reply);
                for (int i = 0; i < l_reply + 1; i++)
                    System.out.println("      c_reply[" + i + "] = 0x" + Integer
.toHexString(c_reply[i]) + ", d_reply[" + i + "] = 0x" + Integer.toHexString(d_r
eply[i]));

        }

        public static void main(String argv[]) throws Exception{

                String  host = (argv.length == 1) ? argv[0] : "localhost";
                ClientImpl obj = new ClientImpl(host);
                obj.camac_exec();
        }
}
[inoue@onlsbc1 CAMAC-array-ok18]$


       (4-1-1c).  Server.java

[inoue@onlsbc1 CAMAC-array-ok18]$ cat Server.java
// File Name: Server.java
// Date: Feb 19, 2003
// Edited by: Eiji Inoue

import java.rmi.*;

public interface Server extends java.rmi.Remote {
        void register(Client aclient) throws java.rmi.RemoteException;
        void camac_cmd(int[] ia, int[] ib, int ic) throws RemoteException;
}
[inoue@onlsbc1 CAMAC-array-ok18]$


       (4-1-1d).  ServerImpl.java

[inoue@onlsbc1 CAMAC-array-ok18]$ cat ServerImpl.java
// File Name: ServerImpl.java
// Date: Feb 19, 2003
// Edited by: Eiji Inoue

import java.rmi.*;
import java.rmi.server.*;

public class ServerImpl extends UnicastRemoteObject implements Server {
        Client client;
        static String serverName;
        static int[] r_cmd, r_dat;
        static camac p;


        static {
                try {
                        serverName = java.net.InetAddress.getLocalHost().getHost
Name();
                }catch(Exception e){
                        serverName = "localhost";
                }
        }

        public ServerImpl() throws Exception {
                super();
                r_cmd = new int[4096*16];
                r_dat = new int[4096*16];
                p = new camac();

        }

        public void register (Client aclient) {
                client = aclient;
        }

        public void camac_cmd(int[] cmd, int[] dat, int length) throws RemoteExc
eption{

           System.out.println(" RMI: Server side: ");
           System.out.println("   RMI: Received CAMAC command: " + "array length
 = " + length);
           for (int i = 0; i < length + 1; i++)
               System.out.println("      cmd[" + i + "] = 0x" + Integer.toHexStr
ing(cmd[i]) + ", dat[" + i + "] = 0x" + Integer.toHexString(dat[i]));

        ServerImpl.r_cmd = cmd;
        ServerImpl.r_dat = dat;

//JNI
    try{
    System.out.println();
    System.out.println("   JNI, Java side: before Native Call");
    for (int i = 0; i < length + 1; i++)
         System.out.println("      ServerImpl.r_cmd[" + i + "] = 0x" + Integer.t
oHexString(ServerImpl.r_cmd[i]) + ", ServerImpl.r_dat[" + i + "] = 0x" + Integer
.toHexString(ServerImpl.r_dat[i]));


    int sum = ServerImpl.p.cmdArray(ServerImpl.r_cmd, ServerImpl.r_dat, length);

    System.out.println();
    System.out.println("   JNI, Java side: after Native Call" + " array length =
 " + length);
    for (int i = 0; i < length + 1; i++)
         System.out.println("      ServerImpl.r_cmd[" + i + "] = 0x" + Integer.t
oHexString(ServerImpl.r_cmd[i]) + ", ServerImpl.r_dat[" + i + "] = 0x" + Integer
.toHexString(ServerImpl.r_dat[i]));

        client.camac_reply (ServerImpl.r_cmd, ServerImpl.r_dat, length);

   } catch ( Exception e ) {
       System.err.println ("Failed to exec for camac");
   }

//JNI end
        }

        public static void main(String argv[]) throws Exception {
                //System.setSecurityManager(new RMISecurityManager());
                ServerImpl obj = new ServerImpl();
                Naming.bind("//"+serverName+"/Server", obj);
                System.out.println("bind done");
        }
}
[inoue@onlsbc1 CAMAC-array-ok18]$


       (4-1-1e).  camac.java

[inoue@onlsbc1 CAMAC-array-ok18]$ cat camac.java
// File name:  camac.java
// Date: Feb 19, 2003
// Edited by: Eiji Inoue
//
//
// Parallel camac
// packet format of basic camac opeation
// TX
// +---------+-------+-------+-------+-------+---------------------------+
// |   cmd   |   N   |   A   |   F   |       |       24-bit DATA         |
// +---------+-------+-------+-------+-------+---------------------------+
//
// RX
// +---------+-------+-------+-------+-------+---------------------------+
// |  rply   |   N   |   A   |   F   |  ST   |       24-bit DATA         |
// +---------+-------+-------+-------+-------+---------------------------+

public class camac {

  public native int cmdArray(int j_cmd[], int j_dat[], int j_length);

  public static void main(String args[]) {
    camac p = new camac();
  }
  static {
    System.loadLibrary("MyImpOfcamac");
  }
}
[inoue@onlsbc1 CAMAC-array-ok18]$


       (4-1-1f).  camac.c

[inoue@onlsbc1 CAMAC-array-ok18]$ more camac.c
// file name:  camac.c
// Date: Feb 19, 2003
// Edited by:  E.Inoue
//
// Parallel camac
// packet format of basic camac opeation
// TX
// +---------+-------+-------+-------+-------+---------------------------+
// |   cmd   |   N   |   A   |   F   |       |       24-bit DATA         |
// +---------+-------+-------+-------+-------+---------------------------+
//
// RX
// +---------+-------+-------+-------+-------+---------------------------+
// |  rply   |   N   |   A   |   F   |  ST   |       24-bit DATA         |
// +---------+-------+-------+-------+-------+---------------------------+

#include    
#include    
#include    
#include    "camac.h"

#define BASE 0xE800
#define TX_DATA1REG BASE
#define TX_DATA2REG (BASE+4)
/* #define TX_STATUSREG (BASE+0x10) */
#define TX_STATUSREG (BASE+0x1c)
#define TXSTATUS_BUSY 0x10000
#define TXSTATUS_TIMEOUT 0x20000
#define RX_DATA1REG (BASE+0x20)
#define RX_DATA2REG (BASE+0x24)
/* #define RX_FIFOREG  (BASE+0x30) */
#define RX_FIFOREG  (BASE+0x3c)
#define CMD_F16_A0_N3 0xE0030010
#define CMD_F0_A0_N3 0xE0030000

unsigned long long int value;
unsigned int camac;


JNIEXPORT jint JNICALL
Java_camac_cmdArray(JNIEnv *env, jobject obj, jintArray r_cmd, jintArray r_dat,
jint length)
{
        int     i, sum = 0;
        jsize   len = (*env)->GetArrayLength(env, r_cmd);
        jint    *c_cmd = (*env)->GetIntArrayElements(env, r_cmd, 0);

        jsize   len2 = (*env)->GetArrayLength(env, r_dat);
        jint    *c_dat = (*env)->GetIntArrayElements(env, r_dat, 0);

        int     loop = length;
        int     ii, j, data, cmd, value;

        printf ("\n   JNI, C side: Received CAMAC command: ");
        printf ("array length = %d\n", length);
        for (i=0; i < length +1; i++) {
           printf("      c_cmd[%d] = 0x%x, c_dat[%d] = 0x%x\n", i, c_cmd[i], i,
c_dat[i]);
        }

        if( iopl(3) ){
           printf("can not change the privilege level\n");
           exit(0);
        }

        printf("\n   JNI, C side: CAMAC access\n");
        for( i = 0; i < loop; i++) {
           switch (c_cmd[i] & 0x00000018) {

//  CAMAC Write
                case 0x00000010 :

//  送信可能状態になるまで待つ
                        value = inl(TX_STATUSREG);
                        while (value & TXSTATUS_BUSY) {
                           if (value & TXSTATUS_TIMEOUT) break;
                           value = inl(TX_STATUSREG);
                        }

//  camac writeコマンド&データをセットして、PCIレジスタに書き込む
                        data = c_dat[i] & 0x00ffffff;
                        outl(data, TX_DATA1REG);
                        outl(CMD_F16_A0_N3, TX_DATA2REG);
                        printf("      camac write data:  data = %x\n", data);

//  camac応答が読み出し可能状態になるまで待つ
                        value = 0;
                        do {
                           value = inl(RX_FIFOREG);
                           // for PCI ROM of new version
                           //  value = value >> 24;
                        } while( value < 2 );

//  camacからの受信用レジスタを読んで camacからの応答を得る
                        data = inl(RX_DATA1REG);
                        cmd = inl(RX_DATA2REG);
                        printf("      camac write command reply:  cmd = %x : dat
a = %x\n", cmd, data);
                        c_cmd[i] = cmd;
                        c_dat[i] = data;
                        break;


//  CAMAC Read
                case 0x00000000 :

//  送信可能状態になるまで待つ
                        value = inl(TX_STATUSREG);
                        while (value & TXSTATUS_BUSY) {
                        if (value & TXSTATUS_TIMEOUT) break;
                           value = inl(TX_STATUSREG);
                        }

//  camac readコマンド&データをセットして、PCIレジスタに書き込む
                        outl(CMD_F0_A0_N3, TX_DATA2REG);

//  camac応答が読み出し可能状態になるまで待つ
                        value = 0;
                        do {
                           value = inl(RX_FIFOREG);
                           // for PCI ROM of new version
                           //  value = value >> 24;
                        } while( value < 2);

//  camacからの受信用レジスタを読んで camacからの応答を得る
                        data = inl(RX_DATA1REG);
                        cmd = inl(RX_DATA2REG);
                        data = 0xffffff & data;
                        ii = 0xffffff & c_dat[i];
                        printf("      camac read command reply:  cmd = %x : data
 = %x\n", cmd, data);
                        c_cmd[i] = cmd;
                        c_dat[i] = data;
                        break;

//  Default
                default :
                        break;
           }
        }

        (*env)->ReleaseIntArrayElements(env, r_cmd, c_cmd, 0);
        (*env)->ReleaseIntArrayElements(env, r_dat, c_dat, 0);
        return sum;
}
[inoue@onlsbc1 CAMAC-array-ok18]$


       (4-1-1g).  Makefile

[inoue@onlsbc1 CAMAC-array-ok18]$ cat Makefile
# File Name: Makefile
# Date: Feb 19, 2003
# Edited by: Eiji Inoue

all : camac.class camac.h libMyImpOfcamac.so Client.class ClientImpl.class Serve
r.class ServerImpl.class ClientImpl_Skel.class ClientImpl_Stub.class ServerImpl_
Skel.class ServerImpl_Stub.class

camac.class:    camac.java
        javac camac.java

Client.class:   Client.java
        javac Client.java

ClientImpl.class:       ClientImpl.java
        javac ClientImpl.java

Server.class:   Server.java
        javac Server.java

ServerImpl.class:       ServerImpl.java
        javac ServerImpl.java

ClientImpl_Skel.class:  ClientImpl.class
        rmic ClientImpl

ServerImpl_Skel.class:  ServerImpl.class
        rmic ServerImpl


camac.h:        camac.class
        javah -jni camac

libMyImpOfcamac.so:     camac.c
        gcc -O -shared -I/usr/java/include -I/usr/java/include/linux camac.c -o
libMyImpOfcamac.so

clean:
        rm -f *.class camac.h libMyImpOfcamac.so *.o core *~
[inoue@onlsbc1 CAMAC-array-ok18]$


       (4-1-1h).  コンパイル

[inoue@onlsbc1 CAMAC-array-ok18]$ pwd
/home/inoue/JavaRMI/CAMAC/CAMAC-array-ok18
[inoue@onlsbc1 CAMAC-array-ok18]$ ls -l
合計 28
-rw-rw-r--    1 inoue    inoue         213  2月 20 10:38 Client.java
-rw-r--r--    1 inoue    inoue        3104  2月 20 10:38 ClientImpl.java
-rw-rw-r--    1 inoue    inoue         852  2月 20 10:38 Makefile
-rw-r--r--    1 inoue    inoue         288  2月 20 10:38 Server.java
-rw-r--r--    1 inoue    inoue        2417  2月 20 10:38 ServerImpl.java
-rw-rw-r--    1 inoue    inoue        3839  2月 20 10:38 camac.c
-rw-rw-r--    1 inoue    inoue         828  2月 20 10:38 camac.java
[inoue@onlsbc1 CAMAC-array-ok18]$ make clean
rm -f *.class camac.h libMyImpOfcamac.so *.o core *~
[inoue@onlsbc1 CAMAC-array-ok18]$ make
javac camac.java
javah -jni camac
gcc -O -shared -I/usr/java/include -I/usr/java/include/linux camac.c -o libMyImp
Ofcamac.so
javac Client.java
javac ClientImpl.java
javac ServerImpl.java
rmic ClientImpl
rmic ServerImpl
[inoue@onlsbc1 CAMAC-array-ok18]$ ls -l
合計 76
-rw-rw-r--    1 inoue    inoue         202  2月 20 11:04 Client.class
-rw-rw-r--    1 inoue    inoue         213  2月 20 10:38 Client.java
-rw-rw-r--    1 inoue    inoue        2269  2月 20 11:04 ClientImpl.class
-rw-r--r--    1 inoue    inoue        3104  2月 20 10:38 ClientImpl.java
-rw-rw-r--    1 inoue    inoue        1689  2月 20 11:04 ClientImpl_Skel.class
-rw-rw-r--    1 inoue    inoue        3046  2月 20 11:04 ClientImpl_Stub.class
-rw-rw-r--    1 inoue    inoue         852  2月 20 10:38 Makefile
-rw-rw-r--    1 inoue    inoue         243  2月 20 11:04 Server.class
-rw-r--r--    1 inoue    inoue         288  2月 20 10:38 Server.java
-rw-rw-r--    1 inoue    inoue        2429  2月 20 11:04 ServerImpl.class
-rw-r--r--    1 inoue    inoue        2417  2月 20 10:38 ServerImpl.java
-rw-rw-r--    1 inoue    inoue        1939  2月 20 11:04 ServerImpl_Skel.class
-rw-rw-r--    1 inoue    inoue        3477  2月 20 11:04 ServerImpl_Stub.class
-rw-rw-r--    1 inoue    inoue        3839  2月 20 10:38 camac.c
-rw-rw-r--    1 inoue    inoue         449  2月 20 11:03 camac.class
-rw-rw-r--    1 inoue    inoue         391  2月 20 11:03 camac.h
-rw-rw-r--    1 inoue    inoue         828  2月 20 10:38 camac.java
-rwxrwxr-x    1 inoue    inoue        6976  2月 20 11:04 libMyImpOfcamac.so
[inoue@onlsbc1 CAMAC-array-ok18]$


   (4-2).  クライアント側、onlpara.kek.jp のソース

     (4-2-1).  コンパイル

[inoue@onlpara CAMAC-array-ok18]$ pwd
/home/inoue/JavaRMI/CAMAC/CAMAC-array-ok18
[inoue@onlpara CAMAC-array-ok18]$ ls -l
合計 28
-rw-rw-r--    1 inoue    inoue         213  2月 19 15:43 Client.java
-rw-r--r--    1 inoue    inoue        3104  2月 20 09:55 ClientImpl.java
-rw-rw-r--    1 inoue    inoue         852  2月 19 15:49 Makefile
-rw-r--r--    1 inoue    inoue         288  2月 19 15:46 Server.java
-rw-r--r--    1 inoue    inoue        2417  2月 20 09:57 ServerImpl.java
-rw-rw-r--    1 inoue    inoue        3839  2月 20 09:45 camac.c
-rw-rw-r--    1 inoue    inoue         828  2月 19 15:47 camac.java
[inoue@onlpara CAMAC-array-ok18]$


       (4-2-1a).  Client.java

	上記の項目(4-1-1a)を参照。


       (4-2-1b).  ClientImpl.java

        上記の項目(4-1-1b)を参照。


       (4-2-1c).  Server.java

        上記の項目(4-1-1c)を参照。


       (4-2-1d).  ServerImpl.java

        上記の項目(4-1-1d)を参照。


       (4-2-1e).  camac.java

        上記の項目(4-1-1e)を参照。


       (4-2-1f).  camac.c

        上記の項目(4-1-1f)を参照。


       (4-2-1g).  Makefile

        上記の項目(4-1-1g)を参照。


       (4-2-1h).  コンパイル

[inoue@onlpara CAMAC-array-ok18]$ pwd
/home/inoue/JavaRMI/CAMAC/CAMAC-array-ok18
[inoue@onlpara CAMAC-array-ok18]$ ls -l
合計 28
-rw-rw-r--    1 inoue    inoue         213  2月 19 15:43 Client.java
-rw-r--r--    1 inoue    inoue        3104  2月 20 09:55 ClientImpl.java
-rw-rw-r--    1 inoue    inoue         852  2月 19 15:49 Makefile
-rw-r--r--    1 inoue    inoue         288  2月 19 15:46 Server.java
-rw-r--r--    1 inoue    inoue        2417  2月 20 09:57 ServerImpl.java
-rw-rw-r--    1 inoue    inoue        3839  2月 20 09:45 camac.c
-rw-rw-r--    1 inoue    inoue         828  2月 19 15:47 camac.java
[inoue@onlpara CAMAC-array-ok18]$ make clean
rm -f *.class camac.h libMyImpOfcamac.so *.o core *~
[inoue@onlpara CAMAC-array-ok18]$ make
javac camac.java
javah -jni camac
gcc -O -shared -I/usr/java/include -I/usr/java/include/linux camac.c -o libMyImp
Ofcamac.so
javac Client.java
javac ClientImpl.java
javac ServerImpl.java
rmic ClientImpl
rmic ServerImpl
[inoue@onlpara CAMAC-array-ok18]$ ls -l
合計 76
-rw-rw-r--    1 inoue    inoue         202  2月 20 10:49 Client.class
-rw-rw-r--    1 inoue    inoue         213  2月 19 15:43 Client.java
-rw-rw-r--    1 inoue    inoue        2269  2月 20 10:49 ClientImpl.class
-rw-r--r--    1 inoue    inoue        3104  2月 20 09:55 ClientImpl.java
-rw-rw-r--    1 inoue    inoue        1689  2月 20 10:50 ClientImpl_Skel.class
-rw-rw-r--    1 inoue    inoue        3046  2月 20 10:49 ClientImpl_Stub.class
-rw-rw-r--    1 inoue    inoue         852  2月 19 15:49 Makefile
-rw-rw-r--    1 inoue    inoue         243  2月 20 10:49 Server.class
-rw-r--r--    1 inoue    inoue         288  2月 19 15:46 Server.java
-rw-rw-r--    1 inoue    inoue        2429  2月 20 10:49 ServerImpl.class
-rw-r--r--    1 inoue    inoue        2417  2月 20 09:57 ServerImpl.java
-rw-rw-r--    1 inoue    inoue        1939  2月 20 10:50 ServerImpl_Skel.class
-rw-rw-r--    1 inoue    inoue        3477  2月 20 10:50 ServerImpl_Stub.class
-rw-rw-r--    1 inoue    inoue        3839  2月 20 09:45 camac.c
-rw-rw-r--    1 inoue    inoue         449  2月 20 10:49 camac.class
-rw-rw-r--    1 inoue    inoue         391  2月 20 10:49 camac.h
-rw-rw-r--    1 inoue    inoue         828  2月 19 15:47 camac.java
-rwxrwxr-x    1 inoue    inoue        6659  2月 20 10:49 libMyImpOfcamac.so
[inoue@onlpara CAMAC-array-ok18]$


   (4-3).  サーバ側のプログラムの起動

	onlsbc1 のSBCからPCIへアクセスする前に、PCIのシステムレジスタに 1を書き
	込んで CAMAC 用の FPGA をイニシャライズしないと CAMACにアクセスできない
	ようになっている。 今回のテストに使用しているネイティブコードには、この
	ための操作は含んでいない。 したがって、サーバ側のプログラムを起動する前
	に手動でこの操作をする必要がある。 これは、以下の一行のコマンドで行う。

	# ./w e840 1

[root@onlsbc1 CAMAC-array-ok18]# pwd
/home/inoue/JavaRMI/CAMAC/CAMAC-array-ok18
[root@onlsbc1 CAMAC-array-ok18]# export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH
[root@onlsbc1 CAMAC-array-ok18]# rmiregistry &
[1] 13431
[root@onlsbc1 CAMAC-array-ok18]# java ServerImpl
bind done
 RMI: Server side:
   RMI: Received CAMAC command: array length = 8
      cmd[0] = 0xe0030010, dat[0] = 0x5
      cmd[1] = 0xe0030000, dat[1] = 0x0
      cmd[2] = 0xe0030010, dat[2] = 0x6
      cmd[3] = 0xe0030000, dat[3] = 0x0
      cmd[4] = 0xe0030010, dat[4] = 0x7
      cmd[5] = 0xe0030000, dat[5] = 0x0
      cmd[6] = 0xe0030010, dat[6] = 0x8
      cmd[7] = 0xe0030000, dat[7] = 0x0
      cmd[8] = 0x0, dat[8] = 0x0

   JNI, Java side: before Native Call
      ServerImpl.r_cmd[0] = 0xe0030010, ServerImpl.r_dat[0] = 0x5
      ServerImpl.r_cmd[1] = 0xe0030000, ServerImpl.r_dat[1] = 0x0
      ServerImpl.r_cmd[2] = 0xe0030010, ServerImpl.r_dat[2] = 0x6
      ServerImpl.r_cmd[3] = 0xe0030000, ServerImpl.r_dat[3] = 0x0
      ServerImpl.r_cmd[4] = 0xe0030010, ServerImpl.r_dat[4] = 0x7
      ServerImpl.r_cmd[5] = 0xe0030000, ServerImpl.r_dat[5] = 0x0
      ServerImpl.r_cmd[6] = 0xe0030010, ServerImpl.r_dat[6] = 0x8
      ServerImpl.r_cmd[7] = 0xe0030000, ServerImpl.r_dat[7] = 0x0
      ServerImpl.r_cmd[8] = 0x0, ServerImpl.r_dat[8] = 0x0

   JNI, C side: Received CAMAC command: array length = 8
      c_cmd[0] = 0xe0030010, c_dat[0] = 0x5
      c_cmd[1] = 0xe0030000, c_dat[1] = 0x0
      c_cmd[2] = 0xe0030010, c_dat[2] = 0x6
      c_cmd[3] = 0xe0030000, c_dat[3] = 0x0
      c_cmd[4] = 0xe0030010, c_dat[4] = 0x7
      c_cmd[5] = 0xe0030000, c_dat[5] = 0x0
      c_cmd[6] = 0xe0030010, c_dat[6] = 0x8
      c_cmd[7] = 0xe0030000, c_dat[7] = 0x0
      c_cmd[8] = 0x0, c_dat[8] = 0x0

   JNI, C side: CAMAC access
      camac write data:  data = 5
      camac write command reply:  cmd = e0030010 : data = 23000000
      camac read command reply:  cmd = e0030000 : data = 5
      camac write data:  data = 6
      camac write command reply:  cmd = e0030010 : data = 23000000
      camac read command reply:  cmd = e0030000 : data = 6
      camac write data:  data = 7
      camac write command reply:  cmd = e0030010 : data = 23000000
      camac read command reply:  cmd = e0030000 : data = 7
      camac write data:  data = 8
      camac write command reply:  cmd = e0030010 : data = 23000000
      camac read command reply:  cmd = e0030000 : data = 8

   JNI, Java side: after Native Call array length = 8
      ServerImpl.r_cmd[0] = 0xe0030010, ServerImpl.r_dat[0] = 0x23000000
      ServerImpl.r_cmd[1] = 0xe0030000, ServerImpl.r_dat[1] = 0x5
      ServerImpl.r_cmd[2] = 0xe0030010, ServerImpl.r_dat[2] = 0x23000000
      ServerImpl.r_cmd[3] = 0xe0030000, ServerImpl.r_dat[3] = 0x6
      ServerImpl.r_cmd[4] = 0xe0030010, ServerImpl.r_dat[4] = 0x23000000
      ServerImpl.r_cmd[5] = 0xe0030000, ServerImpl.r_dat[5] = 0x7
      ServerImpl.r_cmd[6] = 0xe0030010, ServerImpl.r_dat[6] = 0x23000000
      ServerImpl.r_cmd[7] = 0xe0030000, ServerImpl.r_dat[7] = 0x8
      ServerImpl.r_cmd[8] = 0x0, ServerImpl.r_dat[8] = 0x0
[root@onlsbc1 CAMAC-array-ok18]# kill -KILL 13431
[root@onlsbc1 CAMAC-array-ok18]#
[1]+  強制終了                rmiregistry
[root@onlsbc1 CAMAC-array-ok18]#


   (4-4).  クライアント側のプログラムの起動

[inoue@onlpara CAMAC-array-ok18]$ pwd
/home/inoue/JavaRMI/CAMAC/CAMAC-array-ok18
[inoue@onlpara CAMAC-array-ok18]$ rmiregistry &
[1] 7624
[inoue@onlpara CAMAC-array-ok18]$ java ClientImpl onlsbc1
 RMI: Client side:
   RMI: Sent CAMAC command: array length =8
      s_cmd[0] = 0xe0030010, s_dat[0] = 0x5
      s_cmd[1] = 0xe0030000, s_dat[1] = 0x0
      s_cmd[2] = 0xe0030010, s_dat[2] = 0x6
      s_cmd[3] = 0xe0030000, s_dat[3] = 0x0
      s_cmd[4] = 0xe0030010, s_dat[4] = 0x7
      s_cmd[5] = 0xe0030000, s_dat[5] = 0x0
      s_cmd[6] = 0xe0030010, s_dat[6] = 0x8
      s_cmd[7] = 0xe0030000, s_dat[7] = 0x0
      s_cmd[8] = 0x0, s_dat[8] = 0x0

   RMI: Received CAMAC reply: array length = 8
      c_reply[0] = 0xe0030010, d_reply[0] = 0x23000000
      c_reply[1] = 0xe0030000, d_reply[1] = 0x5
      c_reply[2] = 0xe0030010, d_reply[2] = 0x23000000
      c_reply[3] = 0xe0030000, d_reply[3] = 0x6
      c_reply[4] = 0xe0030010, d_reply[4] = 0x23000000
      c_reply[5] = 0xe0030000, d_reply[5] = 0x7
      c_reply[6] = 0xe0030010, d_reply[6] = 0x23000000
      c_reply[7] = 0xe0030000, d_reply[7] = 0x8
      c_reply[8] = 0x0, d_reply[8] = 0x0
[inoue@onlpara CAMAC-array-ok18]$ kill -KILL 7624
[inoue@onlpara CAMAC-array-ok18]$
[1]+  Killed                  rmiregistry
[inoue@onlpara CAMAC-array-ok18]$

	ok.    リモートマシンonlpara から、CAMACコントローラ上のサーバマシン
	onlsbc1 への JavaRMI およびJNI を使った camac リード/ライトは正常に
	実行できた。

---xxxx