The following program in Java is a test client which compiles under Windows (WIN32) or Solaris with Sun's JDK. You need to download and install the Java JDK/IDL packages in order to build the test client. Please read the appropriate instruction file(s) delivered with the package(s). After a successful completion of the program building process (client.class, CamCoStr.class, CamCoStrHelper.class and _CamCoStrStub.class are generated) you should be able to connect to one of the 7 CAMAC servers if you know its name. (omniORB2's COS naming service "omniNames" - works also with code built for Sun's Java IDL - is running on pc303.psi.ch and using port 900.) This java sample program is a good demo to prove that IIOP (Internet Inter ORB (Object Request Broker) Protocol) is functioning because the CAMAC server is implemented with AT&T's omniORB2 (C++) and the client with Sun's IDL (Java). If you have a modem connected to your computer, the JRE 1.2 installed on it and a PSI-DIS account, then you should be able with the above mentioned 4 class files to interact with the 7 CAMAC servers from anywhere on the world. This java sample works also fine with the RedHat 6.0 Linux distribution. But you have to replace the JRE1.1 by the JRE1.2 (pre-v2 for glibc2.1) because JRE1.1 does not support org.omg.CORBA-classes. Furthermore, because Java Linux does not (yet) have an idltojava compiler you have to create the needed 3 class files (CamCoStr.class, CamCoStrHelper.class and _CamCoStrStub.class) under Windows or Solaris. 1) file CamCoStr.idl: ===================== interface CamCoStr { string cacoStr(in string inStr); }; 2) file make.bat: ===================== echo Building Java Camac client .... idltojava CamCoStr.idl javac client.java 3) file client.java: ===================== //================================================================================= // client program for testing CORBA camac server with java. // compiled by Urs Rohrer (PSI), August 1999 // used CORBA implementation: Sun's IDL compiler for java together with JDK_1.2.2 // (for downloading see http://java.sun.com/products/OV_jdkProduct.html ) //================================================================================= import org.omg.CosNaming.*; import java.util.Properties; import java.io.*; public class client { public static void main(String args[]) { if (args.length != 1) { System.out.println("Usage: java client pcxyz"); System.exit(1); } Properties props = new Properties(); props.put("org.omg.CORBA.ORBInitialPort", "900"); props.put("org.omg.CORBA.ORBInitialHost", "pc303.psi.ch"); org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args,props); try { org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); NamingContext ncRef = NamingContextHelper.narrow(objRef); NameComponent nc1 = new NameComponent(args[0],""); NameComponent nc2 = new NameComponent(args[0],"Object"); NameComponent [] path = {nc1, nc2}; org.omg.CORBA.Object obj = ncRef.resolve(path); CamCoStr myobject = CamCoStrHelper.narrow(obj); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); while(true) { System.out.print("Enter command [ ? for help, EXIT for quit ] : "); System.out.flush(); String In = in.readLine(); if (In.equals("EXIT")) break; else if (In.equals("?")) Help(); else { String Out = myobject.cacoStr(In); System.out.println("server returned: " + Out); } } } catch(Exception e) { System.out.println("Exception: " + e); System.exit(1); } } public static void Help() { System.out.println("Version 1.00: Legal commands are:"); System.out.println("-------------------------------------------------------------------------"); System.out.println("| desired Action | Input | Receive (ok) | or Error |"); System.out.println("-------------------+-----------------+-------------------+---------------"); System.out.println("| SockTimeOut | TOUT nnn | *TOUT* nnn | |"); System.out.println("| ReadAllDevices | RALL | *RALL* <list> | *RALL* 0 |"); System.out.println("| ReadAllDevices | RAL2 | *RAL2* <list> | *RAL2* 0 |"); System.out.println("| ReadAllDacs | ALLD | *ALLD* <list> | *ALLD* 0 |"); System.out.println("| WriteDAC | WDAC XYZ nnn | *WDAC* XYZ= nnn | *WDAC* error |"); System.out.println("| WriteDAC&Wait | WDAW XYZ nnn | *WDAW* XYZ= nnn | *WDAW* error |"); System.out.println("| ReadDAC | RDAC XYZ | *RDAC* XYZ= nnn | *RDAC* error |"); System.out.println("| ReadADC | RADC XYZ | *RADC* XYZ= nnn | *RADC* error |"); System.out.println("| ReadCamacDac | RCAD XYZ f | *RCAD* nnn | *RCAD* error |"); System.out.println("| WriteCamacDac | WCAD XYZ f nnn | *WCAD* nnn | *WCAD* error |"); System.out.println("| DoReadCamac | RCAM N A F | *RCAM* sta nnn | *RCAM* error |"); System.out.println("| DoWriteCamac | WCAM N A F nnn | *WCAM* sta | *WCAM* error |"); System.out.println("| DoControlCamac | CCAM N A F | *CCAM* sta | *CCAM* error |"); System.out.println("| GetDeviceName | DEVN nnn | *DEVN* nnn= XYZ | *DEVN* error |"); System.out.println("| DeviceParameter | DEVP nnn | *DEVP* <3par> | *DEVP* error |"); System.out.println("| DeviceParameter2 | DEPA nnn | *DEPA* <17par> | *DEPA* error |"); System.out.println("| DeviceParameter3 | DEPB nnn | *DEPB* <4par> | *DEPB* error |"); System.out.println("-------------------+-----------------+-------------------+---------------"); System.out.print("--- press <Enter> key for more --- "); System.out.flush(); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); try { String In = in.readLine(); } catch(Exception e) {} System.out.println("-------------------------------------------------------------------------"); System.out.println("| desired Action | Input | Receive (ok) | or Error |"); System.out.println("-------------------+-----------------+-------------------+---------------"); System.out.println("| ReserveCrate | RESC | *RESC* 1 | *RESC* 0 |"); System.out.println("| FreeCrate | FREE | *FREE* 1 | |"); System.out.println("| NewDeviceList | NEWL | *NEWL* 1 | *NEWL* 0 |"); System.out.println("| GetPageIndex | PIND nnn | *PIND* nnn | *PIND* error |"); System.out.println("| GetNumberOfPages | NPAG | *NPAG* nnn | |"); System.out.println("| ReadOnePage | RPAG nnn | *RPAG* nnn <list> | *RPAG* 0 |"); System.out.println("| SwitchOnCombis | SWON | *SWON* nnn | |"); System.out.println("| SwitchOnCombi | SWCO XYZ | *SWCO* XYZ 1 | *SWCO* XYZ 0 |"); System.out.println("| SwitchOffCombi | SWOF XYZ | *SWOF* XYZ 1 | *SWOF* XYZ 0 |"); System.out.println("| ClearScalers | CLSC sn s1 s2 | *CLSC* | *CLSC* error |"); System.out.println("| ReadScalers | RDSC sn s1 s2 | *RDSC* nnn mmm | *RDSC* error |"); System.out.println("| ReadClAllScalers | RCAS n | *RCAS* <6rates> | *RCAS* error |"); System.out.println("| Shutdown | EXIT | | |"); System.out.println("| Help info | ? | these help frames | |"); System.out.println("-------------------------------------------------------------------------"); System.out.flush(); } } Last updated by Urs Rohrer on 10-Feb-2005 |