beckhoff — 6.13 ADS sum command: read and write multiple variables

Samples: TcJavaToAds break; default: break; } System.out.println(varName + ": " + val + "\t"); } else { System.out.println(varName + ": Error: 0x" + Long.toHexString(err) + "\t"); } } } Write values To be able to write data, this data must only be appended to the RequestBuffer from the upper part (see picture). All other parameters remain unchanged. Only an adjustment of the sum command is necessary (see below). As a response of the sum command we get an Ads error code (Err) per subcommand, but this time no data, because we executed a write operation. Accordingly the length of the buffer in this case is: 3 * 4 bytes (Error).

For the sum command, the value for the IndexGroup must now be changed to 0xF081 (sum command write). //// Write values // Construct buffers.

Fill request buffer with the data from above // and append the data that is going to be written (see picture 3) byte[] requestBufferCopy = requestBuffer.array(); requestBuffer = ByteBuffer.allocate( requestBuffer.capacity() + DATA_LEN); requestBuffer.order(ByteOrder.LITTLE_ENDIAN); requestBuffer.put(requestBufferCopy); requestBuffer.putChar(CHAR_VAL); requestBuffer.put(BOOL_VAL); requestBuffer.putInt(INT_VAL); // Need to let a JNIByteBuffer wrap the byte[] to be able to send it jniRequestBuffer.setByteArray(requestBuffer.array(), true); // Adjust the length of the response buffer (compare pictures 2 & 4) jniResponseBuffer.setUsedBytesCount(8 * REQ_DATA.length, true); // Write the values via sum command err = AdsCallDllFunction.adsSyncReadWriteReq( addr, 0xF081, REQ_DATA.length, jniResponseBuffer.getUsedBytesCount(), jniResponseBuffer, jniRequestBuffer.getUsedBytesCount(), jniRequestBuffer); if (err != 0) { System.out.println("Error:

Write values: 0x" + Long.toHexString(err)); } else { System.out.println("Success: Write values!"); // Evaluate the sub command error codes ByteBuffer responseBuffer = ByteBuffer.wrap(jniResponseBuffer.getByteArray()); responseBuffer.order(ByteOrder.LITTLE_ENDIAN); for (int i = 0; i String varName = REQ_DATA[i].getVarName(); TX1000 54 Version: 1.1