Samples: TcJavaToAds 6.10 Reading SMB values from the TwinCAT I/O driver If only TwinCAT-CP is available instead of a TwinCAT PLC runtime environment, the SMB device can also be read out using the ADS client. The visualization allows constant monitoring of the desired temperature or fan values. Thus, it can be detected at an early stage whether the current temperature is approaching a critical value. The following is a sample of a possible implementation in Java (for correct operation, an SMB device must be entered in the current System Manager configuration) Unpack the sample program 'Reading SMB values from the TwinCAT I/O driver':
https:// infosys.beckhoff.com/content/1033/tcjavatoads/Resources/12475102859/.zip To execute the *.jar sample, the command 'java -classpath "Sample10.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.
import de.beckhoff.jni.Convert; import de.beckhoff.jni.JNIByteBuffer; import de.beckhoff.jni.tcads.AdsCallDllFunction; import de.beckhoff.jni.tcads.AdsState; import de.beckhoff.jni.tcads.AmsAddr; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.nio.ByteBuffer; import java.util.Timer; public class Main { final static short SMB_ID = 32; public static void main(String[] args) { long err = 0; AmsAddr addr = new AmsAddr(); Visualization visu = new Visualization(); visu.addWindowListener(new WindowAdapter() { // When the form is closed the ADS port is closed as well @Override public void windowClosing(WindowEvent e) { AdsCallDllFunction.adsPortClose(); } }); try { // 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!"); } //Gets the device count of devices appended to active configuration //if TwinCAT is in run mode AdsState adsState = new AdsState(); AdsState deviceState = new AdsState(); err = AdsCallDllFunction.adsSyncReadStateReq(addr, adsState, deviceState); if(err!=0) { visu.setInfoMsg("Error: Read device state: 0x" + Long.toHexString(err)); } if (adsState.getState() != AdsState.ADSSTATE_RUN ) { visu.setInfoMsg("Bad TwinCAT state:
" + "Please restart the application."); } else { //Get devices count JNIByteBuffer deviceCountBuff = new JNIByteBuffer(Integer.SIZE / Byte.SIZE); int devCount = 0; TX1000 44 Version: 1.1