Guten Abend
Ich versuche mich das erste mal an Libnodave. Die Verbindung klappt ohne Probleme auf die 1500er Steuerung. Auch Daten kann ich schreiben und lesen.
Jedoch plötzlich kommen komplett falsche Werte daher oder die Bits die gesetzt sein sollen sind weg und kommen wieder...
Kennt jemand solche Probleme? Könnte es sein das sie kommen wenn die Verbindung kurz unterbricht? Ich hänge aktuell echt ein wenig in den Seilen...
Hallo,
versuche mich auch grad an der Verbindung per Java und die
libnodave-java.0.1.
Per PLCSIM und NETTOPLCSIM...
Er meldet zwar Connection ok, aber wenn ich Werte lesen will spuckt die Console "setupReceivedPDU() returned: 33028context is not supported." aus
Gibts da hier eine Einstellung für die 1500er?
public class DataIsoTCP {
public static boolean Connection = false;
private static int i, j;
public static byte b, b1, b2, b3;
public static long a, c;
//private static float d, e, f;
private static char buf[];
public static byte buf1[];
public static PLCinterface di;
public static TCPConnection dc;
public static Socket sock;
private static int slot;
public static byte[] by;
public static String IP;
DataIsoTCP(String host) {
IP = host;
//Nodave.Debug=Nodave.DEBUG_ALL;
buf = new char[Nodave.OrderCodeSize];
buf1 = new byte[Nodave.PartnerListSize];
try {
sock = new Socket(host, 102);
} catch (IOException e) {
System.out.println(e);
}
}
public static void Start(String adres) {
Nodave.Debug=Nodave.DEBUG_ALL^(Nodave.DEBUG_IFACE|Nodave.DEBUG_SPECIALCHARS);
DataIsoTCP tp = new DataIsoTCP(adres);
DataIsoTCP.StartConnection();
}
public static void StartConnection() {
Connection = false;
OutputStream oStream = null;
InputStream iStream = null;
slot = 1;
if (sock != null) {
try {
oStream = sock.getOutputStream();
} catch (IOException e) {
System.out.println(e);
}
try {
iStream = sock.getInputStream();
} catch (IOException e) {
System.out.println(e);
}
di = new PLCinterface(
oStream,
iStream,
"IF1",
0,
Nodave.PROTOCOL_ISOTCP);
dc = new TCPConnection(di, 0, slot);
int res = dc.connectPLC();
if (0 == res) {
Connection = true;
System.out.println("Connection OK ");
} else {
System.out.println("No connection");
}
}
}
public static void StopConnection() {
if (Connection == true) {
Connection = false;
dc.disconnectPLC();
di.disconnectAdapter();
}
}
public static float Read(int area, String type, int db, int address, int bit) {
int bytes;
if("float".equals(type)){
float r=0;
bytes=4;
int res = dc.readBytes(area, db, address, bytes, null);
if(res==0){
r=dc.getFloat();
}
return r;
}
else if("double".equals(type)){
float r=0;
bytes=4;
int res = dc.readBytes(area, db, address, bytes, null);
if(res==0){
r=dc.getU32();
}
return r;
}
else if("word".equals(type)){
int r=0;
bytes=2;
int res = dc.readBytes(area, db, address, bytes, null);
if(res==0){
r=dc.getWORD();
}
return r;
}
else if("byte".equals(type)){
int r=0;
bytes=1;
int res = dc.readBytes(area, db, address, bytes, null);
if(res==0){
r=dc.getBYTE();
}
return r;
}
else if("bit".equals(type)){
int r=0;
bytes=1;
int res = dc.readBytes(area, db, address, bytes, null);
if(res==0){
r=dc.getBYTE();
}
return (r >> bit)&1;
}else{
return 0;
}
}
}
und hier der Aufruf aus der Main:
DataIsoTCP.Start("127.0.0.1");
int area;
area = Nodave.DB;
float g=(float) DataIsoTCP.Read(area,"float",2,0,0);
jLabel1.setText(String.valueOf(g));
MfG Chef