beckhoff — 6.12 ADS sum command: fetch and release multiple handles

Samples:

TcJavaToAds private static final String VAR_NAME2 = ".bVar02"; public static void main (String[] args) { long err = 0; try { AmsAddr addr = new AmsAddr(); // Create request and response buffer JNIByteBuffer jniReqBuff; JNIByteBuffer jniResBuff = new JNIByteBuffer(new byte[24]); // Construct data objects RequestData req1 = new RequestData(); req1.setIndexGroup(AdsCallDllFunction.ADSIGRP_SYM_HNDBYNAME); req1.setIndexOffset(0x0); req1.setReadLength(Integer.SIZE / Byte.SIZE); req1.setWriteLength(VAR_NAME1.length()); RequestData req2 = new RequestData(); req2.setIndexGroup(AdsCallDllFunction.ADSIGRP_SYM_HNDBYNAME); req2.setIndexOffset(0x0); req2.setReadLength(Integer.SIZE / Byte.SIZE); req2.setWriteLength(VAR_NAME2.length()); // Concatenate byte[] representations of RequestData objects and // variable names (see picture 1) int reqBuffSize = RequestData.SIZE * 2 / Byte.SIZE + req1.getWriteLength() + req2.getWriteLength(); ByteBuffer reqBuff = ByteBuffer.allocate(reqBuffSize); reqBuff.order(ByteOrder.LITTLE_ENDIAN); reqBuff.put(req1.toByteArray()); reqBuff.put(req2.toByteArray()); reqBuff.put(Convert.StringToByteArr(VAR_NAME1, false)); reqBuff.put(Convert.StringToByteArr(VAR_NAME2, false)); // Need to let a JNIByteBuffer wrap the byte[] to be able to send it jniReqBuff = new JNIByteBuffer(reqBuff.array()); The names of the variables whose handles we want to get are appended to the end of the byte array.

For communication, a port is opened and the local address is passed. If a transmission takes place, the port is assigned to the address by runtime system 1 beforehand. The parameters for the sum command consist of IndexGroup (0xf082) - call of the sum command, IndexOffset (0x2) - number of subcommands, ReadLength (0x18) - size specification of the data to be read, ReadData (pBuffRes) - memory that accepts read data, WriteLength (cbReq) - size specification of the data to be sent and WriteLength (pBuffReq) - memory that contains data to be sent.

// Open communication AdsCallDllFunction.adsPortOpen(); err = AdsCallDllFunction.getLocalAddress(addr); addr.setPort(AdsCallDllFunction.AMSPORT_R0_PLC_RTS1); if (err != 0) { System.out.println("Error: Open communication: 0x" + Long.toHexString(err)); } else { System.out.println("Success: Open communication!"); } err = AdsCallDllFunction.adsSyncReadWriteReq( addr, 0xf082, // ADS list-read-write command 0x2, // number of ADS-sub commands jniResBuff.getUsedBytesCount(), // we expect an ADS error // return-code for each ADS-sub command jniResBuff, // provide space for the response // containing the return codes jniReqBuff.getUsedBytesCount(), // send 48 bytes(IG1, TX1000 49 Version: 1.1