Sorry für die verspätete Antwort!
Hier meine JAVA Experimente zum Lesen/Anallysieren einer *.wld der 1 S7 Baustein beeinhaltet:
package WLD;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Calendar;
public class WLD {
public static void main(String arg[]) {
final String fileName = "fb5.wld";
try {
RandomAccessFile wldStream = new RandomAccessFile(fileName, "r");
Long fileLen = wldStream.length();
System.out.println("Length of File: " + fileLen+ " Bytes");
// Read 36 Byte Header
final int headLen = 36;
wldStream.seek(0); // Byte 0..1 = 0x7070 Sync
if (wldStream.readUnsignedShort() != 0x7070) {
System.out.println("No Sync at BlockStart");
}
wldStream.seek(8); // Byte 8..11 = LoadMemory
int loadMemLen = wldStream.readInt(); // Load Memory
System.out.println("Length of Load Memory: " + loadMemLen + " Bytes");
String s7BlockLang;
wldStream.seek(4); // Byte 4 = BlockLanguage "AWL,KOP,FUP,SCL,DB,SDB"
switch (wldStream.readByte()) {
case 0x01: // AWL
s7BlockLang= "AWL";
break;
case 0x02: // KOP
s7BlockLang= "KOP";
break;
case 0x03: // FUP
s7BlockLang= "FUP";
break;
case 0x04: // SCL
s7BlockLang= "SCL";
break;
case 0x05: // DB
s7BlockLang= "DB";
break;
case 0x06: // GRAPH
s7BlockLang= "GRAPH";
break;
case 0x07: // SDB
s7BlockLang= "SDB";
break;
default:
s7BlockLang = "Unknown";
}
System.out.println(s7BlockLang);
wldStream.seek(5); // Byte 5 = Block Type ID "DB,FC,FB,SDB"
byte s7BlockType = wldStream.readByte();
String s7BlockTypeS;
switch (s7BlockType) {
case 0x08: // OB
s7BlockTypeS = "OB";
break;
case 0x0A: // DB
s7BlockTypeS = "DB";
break;
case 0x0B: // SDB
s7BlockTypeS = "SDB";
break;
case 0x0C: // FC
s7BlockTypeS = "FC";
break;
case 0x0D: // SFC
s7BlockTypeS = "SFC";
break;
case 0x0E: // FB
s7BlockTypeS = "FB";
break;
case 0x0F: // SFB
s7BlockTypeS = "SFB";
break;
default:
s7BlockTypeS = "Unknown";
}
wldStream.seek(6); // Byte 6..7 = BlockNumber
int blockNo = wldStream.readUnsignedShort();
System.out.println(s7BlockTypeS+" "+blockNo);
wldStream.seek(15); //
boolean knowHowProtect = (wldStream.readByte() == 3);
System.out.println("KnowHowProtected: " + Boolean.toString(knowHowProtect));
// ---------------------------------
Calendar calTimeStampChanged = Calendar.getInstance();
calTimeStampChanged.set(Calendar.YEAR, 1984);
calTimeStampChanged.set(Calendar.MONTH, 0); // 0 = Januar!
calTimeStampChanged.set(Calendar.DAY_OF_MONTH, 1);
calTimeStampChanged.set(Calendar.HOUR_OF_DAY, 0);
calTimeStampChanged.set(Calendar.MINUTE, 0);
calTimeStampChanged.set(Calendar.SECOND, 0);
calTimeStampChanged.set(Calendar.MILLISECOND, 0);
wldStream.seek(16); // TimeStamp Changed Byte 16-21
int msSinceMidnight = wldStream.readInt();
wldStream.seek(20); // TimeStamp Changed Byte 20-21
int days1184 = wldStream.readUnsignedShort(); // Days since
// 1.Jan.1984
calTimeStampChanged.add(Calendar.DAY_OF_YEAR, days1184);
calTimeStampChanged.add(Calendar.MILLISECOND, msSinceMidnight);
System.out.printf("Changed: ");
System.out.printf("%tD", calTimeStampChanged); // 01/01/84
System.out.printf(" ");
System.out.printf("%tT%n", calTimeStampChanged);
// wldStream.seek(22); // TimeStamp Schnittstellen Änderung Byte
// 22-27
Calendar calTimeStampIfChanged = Calendar.getInstance();
calTimeStampIfChanged.set(Calendar.YEAR, 1984);
calTimeStampIfChanged.set(Calendar.MONTH, 0); // 0 = Januar!
calTimeStampIfChanged.set(Calendar.DAY_OF_MONTH, 1);
calTimeStampIfChanged.set(Calendar.HOUR_OF_DAY, 0);
calTimeStampIfChanged.set(Calendar.MINUTE, 0);
calTimeStampIfChanged.set(Calendar.SECOND, 0);
calTimeStampIfChanged.set(Calendar.MILLISECOND, 0);
wldStream.seek(22); // TimeStamp Changed Byte 22-25 Millisecond
// since Mindnight 0:00:00
int msIfSinceMidnight = wldStream.readInt();
wldStream.seek(26); // TimeStamp Changed Byte 26-27 Days since
// 1.Jan.1984
int daysIf1184 = wldStream.readUnsignedShort();
calTimeStampIfChanged.add(Calendar.DAY_OF_YEAR, daysIf1184);
calTimeStampIfChanged.add(Calendar.MILLISECOND, msIfSinceMidnight);
System.out.printf("IF Changed : ");
System.out.printf("%tD", calTimeStampIfChanged);
System.out.printf(" ");
System.out.printf("%tT%n", calTimeStampIfChanged);
wldStream.seek(28); // Len of Structure Datas [Bytes]
int structDataLen = wldStream.readUnsignedShort();
System.out.println("Length of Structure Datas: " + structDataLen + " Bytes");
wldStream.seek(30); // Len of Sdb Datas [Bytes]
int sdbDataLen = wldStream.readUnsignedShort();
System.out.println("Length of SDB Datas: " + sdbDataLen + " Bytes");
wldStream.seek(34); // Len of Working Memory Datas [Bytes]
int workMemLen = wldStream.readUnsignedShort();
System.out.println("Length of Working Memory without Header: " + workMemLen + " Bytes");
System.out.println("Length of Working Memory: " + (workMemLen + headLen) + " Bytes");
// Reading Working Memory Datas, Starting at Byte 36 (= headLen)
// wldStream.seek(headLen);
// Reading Structure Datas, Starting at Byte headLen+workMemLen
if (s7BlockTypeS=="DB"){
wldStream.seek(headLen + workMemLen + 1);// Blocknumber in Structure, Datas are in Big Endian!
int blockNoStruct = wldStream.readUnsignedByte() | (wldStream.readUnsignedByte() << 8);
if( blockNoStruct != blockNo){
System.out.println("Unequal DB Number in Struct Data! :" + blockNoStruct);
}
wldStream.seek(3); // Byte 3 = Retain / Linked
byte retainLinked = wldStream.readByte();
boolean linked = (retainLinked & 0x01) == 0x01;
boolean nonRetain = (retainLinked & 0x20) == 0x20;
System.out.println("Linked: " + Boolean.toString(linked));
System.out.println("Non-Retain: " + Boolean.toString(nonRetain));
wldStream.seek(33); // ReadOnly
boolean readOnly = (wldStream.readByte() & 0x1) == 0x1;
System.out.println("ReadOnly: " + Boolean.toString(readOnly));
}
if (s7BlockTypeS=="FC" || s7BlockTypeS=="FB"){
wldStream.seek(32); // Local Memory need
int locMemLen = wldStream.readUnsignedShort();
System.out.println("Length of Local Memory: " + locMemLen + " Bytes");
}
byte[] bufferChar = new byte[8];
wldStream.seek(headLen + workMemLen + sdbDataLen + structDataLen); // Read 8 Byte Author
wldStream.readFully(bufferChar);
String author = new String(bufferChar, "UTF-8");
System.out.println("Author: " + author);
wldStream.seek(headLen + workMemLen + sdbDataLen + structDataLen + 8); // Read 8 Byte Family
wldStream.readFully(bufferChar);
String family = new String(bufferChar, "UTF-8");
System.out.println("Familie: " + family);
wldStream.seek(headLen + workMemLen + sdbDataLen + structDataLen + 16); // Read 8 Byte Name (Header)
wldStream.readFully(bufferChar);
String name = new String(bufferChar, "UTF-8");
System.out.println("Name: " + name);
wldStream.seek(headLen + workMemLen + sdbDataLen + structDataLen + 24);// Read 1 Byte Version Number
byte versionNumber = wldStream.readByte();
System.out.println("Version Number: "+ ((versionNumber & 0xF0) >> 4) + "." + (versionNumber & 0xF));
wldStream.seek(headLen + workMemLen + sdbDataLen + structDataLen + 26);// Read 2 Byte Checksum
int checkSum = wldStream.readUnsignedShort();
System.out.println("Checksum: 0x" + Integer.toHexString(checkSum));
// CRC Calculation
wldStream.seek(headLen-2); // Len MC7 Code + MC7 Code
int crc = 0x0000;
int polynomial = 0x9003;
byte b;
b = s7BlockType;
for (int i = 0; i < 8; i++) {
boolean bit = ((b >> (7-i) & 1) == 1);
boolean c15 = ((crc >> 15 & 1) == 1);
crc <<= 1;
if (c15 ^ bit) crc ^= polynomial;
}
for (int count = 0; count < workMemLen+2; count++) {
b = wldStream.readByte();
for (int i = 0; i < 8; i++) {
boolean bit = ((b >> (7-i) & 1) == 1);
boolean c15 = ((crc >> 15 & 1) == 1);
crc <<= 1;
if (c15 ^ bit) crc ^= polynomial;
}
}
crc &=0xFFFF;
System.out.println("Checksum Calculated: 0x" + Integer.toHexString(crc));
// End of CRC Calculation
wldStream.close();
} catch (FileNotFoundException ex) {
System.out.println("Unable to open file '" + fileName + "'");
} catch (IOException ex) {
System.out.println("Error reading file '" + fileName + "'");
// Or we could just do this:
// ex.printStackTrace();
}
} // End Main
} // End Class