Samples: TcJavaToAds As a response of the sum command we receive an Ads error code (Err) per subcommand, as well as the requested value (Data). Accordingly the length of the buffer in this case is: 3 * 4 bytes (Error) + 7 bytes (The sum of all lengths of the expected responses). The sum command itself is called with the parameters IndexGroup: 0xF080 (sum command read), IndexOffset: 0x3 (number of subcommands), ResponseBuffer length, ResponseBuffer, RequestBuffer length, RequestBuffer.
// Create request buffer (see picture 1) JNIByteBuffer jniRequestBuffer = null; ByteBuffer requestBuffer = ByteBuffer.allocate(RequestData.SIZE * REQ_DATA.length); requestBuffer.order(ByteOrder.LITTLE_ENDIAN); for (int i = 0; i requestBuffer.put(REQ_DATA[i].toByteArray()); } // Need to let a JNIByteBuffer wrap the byte[] to be able to send it jniRequestBuffer = new JNIByteBuffer(requestBuffer.array()); // Create response buffer (see picture 2) JNIByteBuffer jniResponseBuffer = new JNIByteBuffer( REQ_DATA.length * RESP_ERR_LEN + DATA_LEN); // Read the values via sum command err = AdsCallDllFunction.adsSyncReadWriteReq( addr, 0xF080, REQ_DATA.length, jniResponseBuffer.getUsedBytesCount(), jniResponseBuffer, jniRequestBuffer.getUsedBytesCount(), jniRequestBuffer); if (err != 0) { System.out.println("Error:
Get values: 0x" + Long.toHexString(err)); } else { System.out.println("Success: Get values!"); // Evaluate the sub commands error codes and response values // (see picture) ByteBuffer responseBuffer = ByteBuffer.wrap(jniResponseBuffer.getByteArray()); responseBuffer.order(ByteOrder.LITTLE_ENDIAN); // In each loop the errPosition is increased by the Size of an // error (int) and the valPosition by the size of the // corresponding data type int[] respErrs = new int[REQ_DATA.length]; for (int i = 0; i respErrs[i] = responseBuffer.getInt(); } for (int i = 0; i String varName = REQ_DATA[i].getVarName(); int val = 0; if (respErrs[i] == 0) { switch (REQ_DATA[i].getLength()) { case 1:
val = (int) responseBuffer.get(); break; case 2: val = responseBuffer.getChar(); break; case 4: val = responseBuffer.getInt(); TX1000 53 Version: 1.1