forked from LupusNobilis/java-org.hwo
Exception Handling update
parent
a8fd32409d
commit
09bbb478d7
|
@ -174,7 +174,14 @@ public class RegisterEditor extends JFrame implements IInteractiveObjectEditor{
|
|||
public void setInteractiveObject(Object o) {
|
||||
serviceNodeRegister = (ServiceNodeRegister)o;
|
||||
|
||||
serviceNodeRegister.read();
|
||||
try
|
||||
{
|
||||
serviceNodeRegister.read();
|
||||
} catch (ServiceLinkRequestFailedException slex)
|
||||
{
|
||||
System.err.println("RegisterEditor: " + slex);
|
||||
}
|
||||
|
||||
|
||||
tfRegister.setText(serviceNodeRegister.register.toString());
|
||||
lblLabel.setText(serviceNodeRegister.label);
|
||||
|
|
|
@ -45,12 +45,12 @@ public class ServiceLink {
|
|||
static int SL_MAGIC = 0x66;
|
||||
|
||||
|
||||
class ServiceTelegram
|
||||
public class ServiceTelegram
|
||||
{
|
||||
byte request;
|
||||
byte achse;
|
||||
byte knoten;
|
||||
int register;
|
||||
private byte request;
|
||||
private byte achse;
|
||||
private byte knoten;
|
||||
private int register;
|
||||
byte[] value;
|
||||
|
||||
public ServiceTelegram()
|
||||
|
@ -126,6 +126,38 @@ public class ServiceLink {
|
|||
throw new ServiceLinkException(e);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -194,17 +226,21 @@ public class ServiceLink {
|
|||
intValue = new Integer(value);
|
||||
}
|
||||
|
||||
public void read()
|
||||
public void read() throws ServiceLinkRequestFailedException
|
||||
{
|
||||
try {
|
||||
if (floatType)
|
||||
floatValue = ServiceNode.this.readFloat(register);
|
||||
else
|
||||
intValue = ServiceNode.this.readInt(register);
|
||||
} catch (ServiceLinkRequestFailedException slex)
|
||||
{
|
||||
floatValue = null;
|
||||
intValue = 0;
|
||||
throw slex;
|
||||
} catch (Exception e) {
|
||||
floatValue = null;
|
||||
intValue = 0;
|
||||
e.printStackTrace();
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -265,10 +301,19 @@ public class ServiceLink {
|
|||
return registers;
|
||||
}
|
||||
|
||||
public void read()
|
||||
public void read() throws ServiceLinkRequestFailedException
|
||||
{
|
||||
for (ServiceNodeRegister r:registers)
|
||||
r.read();
|
||||
{
|
||||
try
|
||||
{
|
||||
r.read();
|
||||
} catch (ServiceLinkRequestFailedException slex)
|
||||
{
|
||||
System.err.println("ServiceNode.read(): "+ slex);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public ServiceLink getServiceLink()
|
||||
|
@ -369,16 +414,8 @@ public class ServiceLink {
|
|||
{
|
||||
this.retries = 3;
|
||||
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
|
||||
|
@ -447,10 +484,10 @@ public class ServiceLink {
|
|||
{
|
||||
ServiceTelegram telegram = new ServiceTelegram();
|
||||
|
||||
telegram.request = request;
|
||||
telegram.achse = achse;
|
||||
telegram.knoten = knoten;
|
||||
telegram.register = register;
|
||||
telegram.setRequest(request);
|
||||
telegram.setAchse(achse);
|
||||
telegram.setKnoten(knoten);
|
||||
telegram.setRegister(register);
|
||||
|
||||
if (value.length == 4)
|
||||
telegram.value = value;
|
||||
|
@ -459,8 +496,8 @@ public class ServiceLink {
|
|||
telegram.send();
|
||||
telegram.recv();
|
||||
|
||||
if ((telegram.request & REQ_ACK)==0)
|
||||
throw new ServiceLinkRequestFailedException();
|
||||
if ((telegram.getRequest() & REQ_ACK)==0)
|
||||
throw new ServiceLinkRequestFailedException(telegram);
|
||||
|
||||
return telegram;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,30 @@
|
|||
package org.hwo.io.servicelink;
|
||||
|
||||
import org.hwo.io.servicelink.ServiceLink.ServiceTelegram;
|
||||
|
||||
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