Use an Indicator
raquel March 14, 2008
 
Hi.
I'm following the examples to create my own example using a component from a package which I've created to use the service indicator. I want to change the value associated to the object indicator, but when I initialize the service start a bucle that end when the time out property finish.
I wonder how I can get and set the value of the indicator.And what I have to do for initializate the indicator correctly
Thanks.

Roberto March 14, 2008
 
Hi Raquel,

Could you send the code of the indicator service and the test program? If it is too large, send it to xpeakersupport@cashware.biz

Thanks

raquel March 14, 2008
 
Hi,
The test program code is:
public static void main (String args[]) {
try{
File XpeakingProperties = new File( 'Xpeaking.properties');
System.out.println( 'Cargando Xpeak Services del repositorio ' + XpeakingProperties.getAbsolutePath());

XClassManager.getReference().setRepository( new URL( 'file:///' + XpeakingProperties.getAbsolutePath()));

System.out.println('Antes de obtener la referencia');
//el servicio debe estar dado de alta en Xpeaking.properties
XClassServiceIndicator indicator = (XClassServiceIndicator) XClassManager.getReference().getService( 'Indicator');

System.out.println('Antes de inicializar:'+indicator.getDeviceName());
indicator.initialize(true); //en este punto entra en un bucle que dura lo que
// marca el time out y despues termina con un error
System.out.println('Ya se puede');

XDataAnswerIndicatorGetValue valor = new XDataAnswerIndicatorGetValue();
valor=indicator.getValue();
System.out.println('el valor que tiene'+(valor.Value));
XClassTimer.sleep( 2000);

indicator.setValue(1);
valor =indicator.getValue();
System.out.println('el valor que le he puesto'+(valor.Value));


indicator.shutdown(true);
}
catch(Exception e){
e.printStackTrace();
}
System.exit(0);
}

And the code to the indicator service

public class XClassServiceAlarmIndicator extends XClassBasicServiceIndicator {

private final static String PROPERTY_VALUE_OFF = 'Alarm.Inactive';
private final static String PROPERTY_VALUE_ON = 'Alarm.Active';

protected XClassDevice Device;

protected int Inactive = 0;
protected int Active = 1;

public XClassServiceAlarmIndicator( XClassDevice device, String serviceId)
{
super( device);
Device = device;
ServiceId = serviceId;
}
public void executeGetConfiguration( XDataCommandGenericGetConfiguration command, XDataAnswerGenericGetConfiguration answer) throws Exception
{
answer.addField( PROPERTY_VALUE_OFF , Inactive);
answer.addField( PROPERTY_VALUE_ON , Active);
}

public void executeSetConfiguration( XDataCommandGenericSetConfiguration command, XDataAnswerGenericSetConfiguration answer) throws Exception
{
Inactive = Integer.parseInt( command.getField( PROPERTY_VALUE_OFF , '' + Inactive));
Active = Integer.parseInt( command.getField( PROPERTY_VALUE_ON , '' + Active));
}

public void executeGetCommands( XDataCommandGenericGetCommands command, XDataAnswerGenericGetCommands answer) throws Exception
{
}

public void executeInitialize( XDataCommandGenericInitialize command, XDataAnswerGenericInitialize answer) throws Exception
{
Device.initialize();

Device.setIndicatorOff();
}

public void executeShutdown( XDataCommandGenericShutdown command, XDataAnswerGenericShutdown answer) throws Exception
{
Device.shutdown( command.Force);
}

public void executeReset( XDataCommandGenericReset command, XDataAnswerGenericReset answer) throws Exception
{
Device.setIndicatorOff();
}

public void executeGetStatus( XDataCommandGenericGetStatus command, XDataAnswerGenericGetStatus answer) throws Exception
{
answer.add( XPEAK_STATUS_WORKING);
}

public void executeGetCapabilities( XDataCommandGenericGetCapabilities command, XDataAnswerIndicatorGetCapabilities answer) throws Exception
{
answer.CanGetValue = true;
answer.addValue( Inactive);
answer.addValue( Active);
}

public void executeSetValue( XDataCommandIndicatorSetValue command, XDataAnswerIndicatorSetValue answer) throws Exception
{
boolean ValidValue = false;
if( command.Value == Inactive) {
Device.setIndicatorOff();
ValidValue = true;
}
if( command.Value == Active) {
Device.setIndicatorOn();
ValidValue = true;
}
if( !ValidValue)
answer.Result.setValue( XPEAK_RESULT_INVALID_PARAMETER);
}

public void executeGetValue( XDataCommandIndicatorGetValue command, XDataAnswerIndicatorGetValue answer) throws Exception
{
if( Device.isIndicatorOff())
answer.Value = Inactive;

if( Device.isIndicatorOn())
answer.Value = Active;
}
}
This code is in this package

package org.xpeak.xpeaker.devices.implementation.NewDelhi.Swing.Alarma_beta.services;
Because, you said me than I mustn't touch the code outside the 'implementation' level
Thanks,

raquel March 14, 2008
 
Hi,

I don't use my service, I use the xpeaking service. I had to make a New Device because I want use only the service Indicator ( for example Barcode have, barcode and Indicator) and I make a new swing interface.
My problem is the call to inicializate method to the XClassServiceIndicator in the package org.xpeak.xpeaking.services.indicator. don't return to me the control of the execution.

thanks again

Asier March 14, 2008
 
Hi Raquel.

Have you tested this Service using the Xpeaker plugin?
Is the Xpeaker server running when you execute your tester?
Is the logical name 'Indicator' included in the Xpeaking.properties? Please send us the Xpeaking.properties you are using.

Thanks and regards.

raquel March 14, 2008
 
Hi,
I'm not sure about the reason but now it's all solve. I had to restart Eclipse.
Thank you very much.

Asier March 14, 2008
 
Hi again.

It seems the problem was due to the Xpeaker server was not running.

Regards.

raquel March 14, 2008
 
No,
The Xpeaker server was running, because I was trying others examples successfully. And I had restarted it several times for different tests.This wasn't the problem. It's the first thing than I tested.
But I had switched on the Eclipse from Wednesday, and that isn't very good.
thank very very much for your attention