Exception Handling update
parent
a8fd32409d
commit
09bbb478d7
|
@ -174,7 +174,14 @@ public class RegisterEditor extends JFrame implements IInteractiveObjectEditor{
|
||||||
public void setInteractiveObject(Object o) {
|
public void setInteractiveObject(Object o) {
|
||||||
serviceNodeRegister = (ServiceNodeRegister)o;
|
serviceNodeRegister = (ServiceNodeRegister)o;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
serviceNodeRegister.read();
|
serviceNodeRegister.read();
|
||||||
|
} catch (ServiceLinkRequestFailedException slex)
|
||||||
|
{
|
||||||
|
System.err.println("RegisterEditor: " + slex);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
tfRegister.setText(serviceNodeRegister.register.toString());
|
tfRegister.setText(serviceNodeRegister.register.toString());
|
||||||
lblLabel.setText(serviceNodeRegister.label);
|
lblLabel.setText(serviceNodeRegister.label);
|
||||||
|
|
|
@ -45,12 +45,12 @@ public class ServiceLink {
|
||||||
static int SL_MAGIC = 0x66;
|
static int SL_MAGIC = 0x66;
|
||||||
|
|
||||||
|
|
||||||
class ServiceTelegram
|
public class ServiceTelegram
|
||||||
{
|
{
|
||||||
byte request;
|
private byte request;
|
||||||
byte achse;
|
private byte achse;
|
||||||
byte knoten;
|
private byte knoten;
|
||||||
int register;
|
private int register;
|
||||||
byte[] value;
|
byte[] value;
|
||||||
|
|
||||||
public ServiceTelegram()
|
public ServiceTelegram()
|
||||||
|
@ -127,6 +127,38 @@ public class ServiceLink {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public byte getRequest() {
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRequest(byte request) {
|
||||||
|
this.request = request;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte getAchse() {
|
||||||
|
return achse;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAchse(byte achse) {
|
||||||
|
this.achse = achse;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte getKnoten() {
|
||||||
|
return knoten;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setKnoten(byte knoten) {
|
||||||
|
this.knoten = knoten;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRegister() {
|
||||||
|
return register;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRegister(int register) {
|
||||||
|
this.register = register;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ServiceNode
|
public class ServiceNode
|
||||||
|
@ -194,17 +226,21 @@ public class ServiceLink {
|
||||||
intValue = new Integer(value);
|
intValue = new Integer(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void read()
|
public void read() throws ServiceLinkRequestFailedException
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (floatType)
|
if (floatType)
|
||||||
floatValue = ServiceNode.this.readFloat(register);
|
floatValue = ServiceNode.this.readFloat(register);
|
||||||
else
|
else
|
||||||
intValue = ServiceNode.this.readInt(register);
|
intValue = ServiceNode.this.readInt(register);
|
||||||
|
} catch (ServiceLinkRequestFailedException slex)
|
||||||
|
{
|
||||||
|
floatValue = null;
|
||||||
|
intValue = 0;
|
||||||
|
throw slex;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
floatValue = null;
|
floatValue = null;
|
||||||
intValue = 0;
|
intValue = 0;
|
||||||
e.printStackTrace();
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,10 +301,19 @@ public class ServiceLink {
|
||||||
return registers;
|
return registers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void read()
|
public void read() throws ServiceLinkRequestFailedException
|
||||||
{
|
{
|
||||||
for (ServiceNodeRegister r:registers)
|
for (ServiceNodeRegister r:registers)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
r.read();
|
r.read();
|
||||||
|
} catch (ServiceLinkRequestFailedException slex)
|
||||||
|
{
|
||||||
|
System.err.println("ServiceNode.read(): "+ slex);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServiceLink getServiceLink()
|
public ServiceLink getServiceLink()
|
||||||
|
@ -369,16 +414,8 @@ public class ServiceLink {
|
||||||
{
|
{
|
||||||
this.retries = 3;
|
this.retries = 3;
|
||||||
this.serialPort = serialPort;
|
this.serialPort = serialPort;
|
||||||
this.serialPort.setTimeout(500);
|
this.serialPort.setTimeout(100);
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
System.err.println(String.format("BRKVAL : 0x%04x",readInt((byte)0,(byte)0,(short)0x200)));
|
|
||||||
System.err.println(String.format("SPLIMIT: 0x%04x",readInt((byte)0,(byte)0,(short)0x201)));
|
|
||||||
} catch (Exception e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void open() throws ServiceLinkException
|
public void open() throws ServiceLinkException
|
||||||
|
@ -447,10 +484,10 @@ public class ServiceLink {
|
||||||
{
|
{
|
||||||
ServiceTelegram telegram = new ServiceTelegram();
|
ServiceTelegram telegram = new ServiceTelegram();
|
||||||
|
|
||||||
telegram.request = request;
|
telegram.setRequest(request);
|
||||||
telegram.achse = achse;
|
telegram.setAchse(achse);
|
||||||
telegram.knoten = knoten;
|
telegram.setKnoten(knoten);
|
||||||
telegram.register = register;
|
telegram.setRegister(register);
|
||||||
|
|
||||||
if (value.length == 4)
|
if (value.length == 4)
|
||||||
telegram.value = value;
|
telegram.value = value;
|
||||||
|
@ -459,8 +496,8 @@ public class ServiceLink {
|
||||||
telegram.send();
|
telegram.send();
|
||||||
telegram.recv();
|
telegram.recv();
|
||||||
|
|
||||||
if ((telegram.request & REQ_ACK)==0)
|
if ((telegram.getRequest() & REQ_ACK)==0)
|
||||||
throw new ServiceLinkRequestFailedException();
|
throw new ServiceLinkRequestFailedException(telegram);
|
||||||
|
|
||||||
return telegram;
|
return telegram;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,30 @@
|
||||||
package org.hwo.io.servicelink;
|
package org.hwo.io.servicelink;
|
||||||
|
|
||||||
|
import org.hwo.io.servicelink.ServiceLink.ServiceTelegram;
|
||||||
|
|
||||||
public class ServiceLinkRequestFailedException extends ServiceLinkException {
|
public class ServiceLinkRequestFailedException extends ServiceLinkException {
|
||||||
|
|
||||||
|
private ServiceTelegram serviceTelegram;
|
||||||
|
|
||||||
|
public ServiceLinkRequestFailedException(ServiceTelegram telegram)
|
||||||
|
{
|
||||||
|
serviceTelegram = telegram;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServiceLinkRequestFailedException()
|
||||||
|
{
|
||||||
|
serviceTelegram = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServiceTelegram getServiceTelegram()
|
||||||
|
{
|
||||||
|
return this.serviceTelegram;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
if (getServiceTelegram()!=null)
|
||||||
|
return String.format("ServiceLinkRequestFailedException: %d.%d:%d",getServiceTelegram().getAchse(),getServiceTelegram().getKnoten(),getServiceTelegram().getRegister());
|
||||||
|
return "ServiceLinkRequestFailedException";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue