TANGO Java API classes
See : Release Note
Getting started with java client api
The quickest way of getting started is by studying this example:
/**
* Example of a client using the TANGO Api
*/
package my_package;
import fr.esrf.Tango.*;
import fr.esrf.TangoDs.*;
import fr.esrf.TangoApi.*;
public class StartingWithTango
{
public static void main (String args[])
{
try
{
// Database Management.
//----------------------
// Create a Database object or retrieve an existing connection
Database dbase = ApiUtil.get_db_obj();
// Get and display database info.
System.out.println(dbase.get_info());
// Build a DbDevInfo object (name, class, server)
// to add a device into the database .
String devname = "tango/admin/corvus";
DbDevInfo devinfo = new DbDevInfo(devname, "Starter", "Starter/corvus");
dbase.add_device(devinfo);
// Get and isplay info about device import.
DbDevImportInfo imp_info = dbase.import_device(devname);
System.out.println(imp_info);
// Update device properties.
devname = "my/serial/device";
DbDatum[] prop;
prop = new DbDatum[3];
prop[0] = new DbDatum("baudrate", 19200);
prop[1] = new DbDatum("parity", "none");
prop[2] = new DbDatum("stopbits", 1);
dbase.put_device_property(devname, prop);
// Query the database for device properties.
int baud = 9600;
String parity = none;
short stop = 1;
String[] propnames = { "baudrate", "parity", "stopbits"};
prop = dbase.get_device_property(devname, propnames);
if (prop[0].is_empty()==false) baud = prop[0].extractLong();
if (prop[1].is_empty()==false) parity = prop[1].extractString();
if (prop[2].is_empty()==false) stop = prop[2].extractShort();
// Device Management
//------------------
// get device properties as from database.
DeviceProxy dev = new DeviceProxy("my/serial/device");
prop = dev.get_property(propnames);
if (prop[0].is_empty()==false) baud = prop[0].extractLong();
if (prop[1].is_empty()==false) parity = prop[1].extractString();
if (prop[2].is_empty()==false) stop = prop[2].extractShort();
// Send a write command to the device
DeviceData argin = new DeviceData();
argin.insert("Hello World !");
dev.command_inout("DevWriteMessage", argin);
// Send a read command to the device
DeviceData argout = dev.command_inout("DevReadMessage");
String received = argout.extractString();
System.out.println(received);
}
catch (NonSupportedFeature e)
{
System.out.println(e.getStack());
}
catch (NonDbDevice e)
{
System.out.println(e.getStack());
}
catch (WrongData e)
{
System.out.println(e.getStack());
}
catch (WrongNameSyntax e)
{
System.out.println(e.getStack());
}
catch (ConnectionFailed e)
{
System.out.println(e.getStack());
}
catch (CommunicationFailed e)
{
System.out.println(e.getStack());
}
catch (DevFailed e)
{
Except.print_exception(e);
}
}
}
Modify this example to fit your device server or client's needs, compile it.
Do not forget when you start it to set the parameter TANGO_HOST with
<host_name>:<port_number>
(i.e. java -DTANGO_HOST=hal:2001 my_package.StartingWithTango
or if you have two database servers running
java -DTANGO_HOST=hal:2001,hal:3001 my_package.StartingWithTango).
And forget about those painful early Tango days when you had to learn CORBA and
manipulate Any's.
Life is going to easy and fun from now.