beckhoff — 6.5 Reading out the PLC variable declaration of a single variable

Samples: TcJavaToAds Length Address (IndexGroup / IndexOffset) Comment Unpack the sample program 'Reading the PLC variable declaration of an individual variable': https:// infosys.beckhoff.com/content/1033/tcjavatoads/Resources/12475095819/.zip To execute the *.jar sample, the command 'java -classpath "Sample05.jar;[path to TcJavaToAds.jar] Main' must be executed in the console in the correct directory (example path: "C:TwinCAT\Ads Api\AdsToJava\*"). For this, java must be entered in the environment variables. The AdsSyncReadWriteReq() call is used to read the variable information. The variable name is transferred to the function via parameter pWriteData.

After the call the requested information is in a buffer of type JNIByteBuffer. The buffer is passed into the constructor of a variable of type AdsSymbolEntry. The individual information items in the PLC variables are stored in this class. The entryLenght, typeLength and commentLength fields specify the lengths of the associated strings located after the class. Next, the data type of the variable is determined by searching the adsDatatypeString for the label that matches the value. If the data type is UDINT or ARRAY OF UDINT, the value of this variable is also read:

import de.beckhoff.jni.JNIByteBuffer; import de.beckhoff.jni.tcads.AmsAddr; import de.beckhoff.jni.tcads.AdsCallDllFunction; import de.beckhoff.jni.Convert; import de.beckhoff.jni.tcads.AdsSymbolEntry; import java.io.BufferedReader; import java.io.InputStreamReader; import java.nio.ByteBuffer; import java.nio.ByteOrder; public class Main { // TODO: Check real values of each constant.

private static final int ADST_VOID = 0; private static final int ADST_INT8 = 16; private static final int ADST_UINT8 = 17; private static final int ADST_INT16 = 2; private static final int ADST_UINT16 = 18; private static final int ADST_INT32 = 3; private static final int ADST_UINT32 = 19; private static final int ADST_INT64 = 20; private static final int ADST_UINT64 = 21; private static final int ADST_REAL32 = 4; private static final int ADST_REAL64 = 5; private static final int ADST_STRING = 30; private static final int ADST_WSTRING = 31; private static final int ADST_REAL80 = 32; private static final int ADST_BIT = 33; private static final int ADST_BIGTYPE = 65; private static final int ADST_MAXTYPES = 67; private static final ValueString[] adsDatatypeString = new ValueString[]{ new ValueString(ADST_VOID, "ADST_VOID"), new ValueString(ADST_INT8, "ADST_INT8"), new ValueString(ADST_UINT8, "ADST_UINT8"), new ValueString(ADST_INT16, "ADST_INT16"), new ValueString(ADST_UINT16, "ADST_UINT16"), new ValueString(ADST_INT32, "ADST_INT32"), new ValueString(ADST_UINT32, "ADST_UINT32"), new ValueString(ADST_INT64, "ADST_INT64"), new ValueString(ADST_UINT64, "ADST_UINT64"), new ValueString(ADST_REAL32, "ADST_REAL32"), new ValueString(ADST_REAL64, "ADST_REAL64"), new ValueString(ADST_STRING, "ADST_STRING"), new ValueString(ADST_WSTRING, "ADST_WSTRING"), new ValueString(ADST_REAL80, "ADST_REAL80"), new ValueString(ADST_BIT, "ADST_BIT"), new ValueString(ADST_BIGTYPE, "ADST_BIGTYPE"), new ValueString(ADST_MAXTYPES, "ADST_MAXTYPES") }; public static void main(String[] args) { long err; AmsAddr addr = new AmsAddr(); TX1000 36 Version:

1.1