This package uses VXI-11 remote procedure calls to control IEEE-488 (GPIB) devices through GPIB/LAN adapters such as the Agilent E2050 and the Tektronix AD007. The Remote Tea package provides the underlying communication classes. Both the Remote Tea package and the IEEE-488 package are written completely in Java and can be used by web browser applets as well as by stand-alone applications.
Example Applications
To build and run these example applications you must have the paths to ieee488.jar and remotetea.jar on your java CLASSPATH. You must also edit the example code and change all instances of eegpib01.usask.ca to the name of your GPIB/LAN adapter.
Example 1 - Simple IEEE-488 Communication
This example shows how to connect to an IEEE-488 device and then send a command to and get a reply from that device.
import ca.usask.engr.ieee488.*; public class IEEE488App { public static void main (String args[]) { IEEE488Device device; String idn; try { device = new IEEE488Device("eegpib01.usask.ca", 1); idn = device.getReplyTo("*IDN?"); System.out.println("Device identification: " + idn + "."); } catch (IEEE488Exception e) { System.err.println(e.getMessage()); System.exit(1); } } }
If you run this application you'll likely find that there's an annoying line break in the output due to the termination character, or characters, from the IEEE-488 device. An easy way to get rid of these characters is to use the String class trim() method:
idn = device.getReplyTo("*IDN?").trim();
Example 2 - IEEE-488 Service Request Handler
This example illustrates several concepts, including how to send commands to the GPIB/LAN controller, how to communicate with an IEEE-488.2 device and how to implement a service request callback.
import ca.usask.engr.ieee488.*; public class TestSrq { public static void main (String args[]) { new Tester().test(); } } class Tester implements IEEE488SrqHandler { boolean srqFlag = false; IEEE488p2Device device; synchronized void test() { try { /* * Create a thread to handle IEEE-488 service requests. */ IEEE488Controller controller = new IEEE488Controller("eegpib01.usask.ca"); controller.registerSrqHandler(this); controller.enableSRQ(true); /* * Allow IEEE-488.2 command, execution or device * error events to generate a service request. */ device = new IEEE488p2Device("eegpib01.usask.ca", 1); device.setParameter("DESE", 56); device.setParameter("*ESE", 56); device.getIntParameter("*ESR"); device.setParameter("*SRE", 32); if (controller.getSRQ()) System.out.println("Controller won't send SRQ message until SRQ goes inactive and then active."); /* * Force an illegal-command event */ device.write("FNORD"); /* * Wait for the service request handler thread to run. */ synchronized (this) { try { wait(5000); } catch (InterruptedException e) { System.out.println("Interrupted while waiting for SRQ message. " + e); } } if (srqFlag) System.out.println("DONE!"); else System.out.println("Didn't receive SRQ message."); } catch (IEEE488Exception e) { System.err.println(e.getMessage()); } } /* * Callback method from the service request handler thread */ public synchronized void ieee488SrqHandler(IEEE488Controller controller) { System.out.println("Received IEEE-488 Service Request."); try { System.out.println("Device status byte: " + device.getStatusByte()); } catch (IEEE488Exception e) { } srqFlag = true; notify(); } }
IEEE-488 Communication from Browser Applet
Applets must be given permission to connect to Internet hosts other than the host from which they were loaded. These permissions can be granted from the system-wide java security policy file or from your own personal security policy file. On Unix (Linux, Mac OS X) machines your personal security policy file is ~/.java.policy and on Windows machines your security policy file is C:\Windows\Profiles\username\.java.policy.
To grant an applet the privileges needed to communicate with a GPIB/LAN adapter add an entry like the following to your security policy file:
grant codeBase "http://www.engr.usask.ca/~norume/IEEE488Applet" { permission java.net.SocketPermission "eegpib01.usask.ca", "connect,accept"; };You'll need to replace the http://www.engr.usask.ca/~norume/IEEE488Applet with the URL from which you're loading the applet and the eegpib01.usask.ca with the name of your GPIB/LAN adapter. If you want any applet to be able to communicate with your GPIB/LAN adapter the policy entry can be simplified to:
grant { permission java.net.SocketPermission "eegpib01.usask.ca", "connect,accept"; };
Acknowledgements
I'd like to express my gratitude to: