├── .clang-format ├── .clang-tidy ├── .cspell.json ├── .editorconfig ├── .github └── workflows │ └── build.yml ├── .gitignore ├── .gitmodules ├── .vscode └── settings.json ├── LICENSE ├── README.md ├── bootstrap.bat ├── bootstrap.sh ├── bootstrap_full.bat ├── bootstrap_full.sh ├── cpp ├── AdsToJava.cpp ├── AdsToJava.h ├── CMakeLists.txt ├── JObjAdsDevName.cpp ├── JObjAdsDevName.h ├── JObjAdsNotificationAttrib.cpp ├── JObjAdsNotificationAttrib.h ├── JObjAdsNotificationHeader.cpp ├── JObjAdsNotificationHeader.h ├── JObjAdsState.cpp ├── JObjAdsState.h ├── JObjAdsVersion.cpp ├── JObjAdsVersion.h ├── JObjAmsAddr.cpp ├── JObjAmsAddr.h ├── JObjAmsNetId.cpp ├── JObjAmsNetId.h ├── JObjJNIBool.cpp ├── JObjJNIBool.h ├── JObjJNIByteBuffer.cpp ├── JObjJNIByteBuffer.h ├── JObjJNILong.cpp ├── JObjJNILong.h ├── JObjectBase.cpp ├── JObjectBase.h ├── StdAfx.h └── version.rc.in ├── package-lock.json ├── package.json ├── plc ├── SamplesPlc │ ├── .gitignore │ ├── Samples │ │ ├── DUTs │ │ │ └── PLCStruct.TcDUT │ │ ├── GVLs │ │ │ └── GVL.TcGVL │ │ ├── POUs │ │ │ └── MAIN.TcPOU │ │ ├── PlcTask.TcTTO │ │ ├── Samples.plcproj │ │ └── Samples.tmc │ ├── SamplesPlc.sln │ └── SamplesPlc.tsproj └── TestPlc │ ├── .gitignore │ ├── Test │ ├── POUs │ │ └── MAIN.TcPOU │ ├── PlcTask.TcTTO │ ├── Test.plcproj │ └── Test.tmc │ ├── TestPLC.sln │ └── TestPLC.tsproj ├── pom.xml ├── run ├── all_samples.bat ├── all_samples.sh ├── build_adslib.sh ├── build_cpp.bat ├── build_cpp.sh ├── build_cpp_full.bat ├── build_cpp_full.sh ├── build_doc.bat ├── build_doc.sh ├── build_java.bat ├── build_java.sh ├── build_java_full.bat ├── build_java_full.sh ├── build_samples.bat ├── build_samples.sh ├── check_dependencies.bat ├── check_dependencies.sh ├── check_dependencies_full.bat ├── check_dependencies_full.sh ├── clear.bat ├── clear.sh ├── copy_to_dist.bat ├── copy_to_dist.sh ├── lint.bat └── lint.sh ├── samples ├── MANIFEST.MF ├── adslib │ └── 02_AccessByVariableName │ │ └── Main.java └── tcadsdll │ ├── 02_AccessByVariableName │ └── Main.java │ ├── 03_AccessAnArray │ └── Main.java │ ├── 04_TransmittingStructures │ ├── Main.java │ └── TransferObject.java │ ├── 05_ReadingAVariableDeclaration │ ├── Main.java │ └── ValueString.java │ ├── 06_WriteFlagSynchronously │ └── Main.java │ ├── 07_ReadFlagSynchronously │ └── Main.java │ ├── 08_ReleaseVariableHandle │ └── Main.java │ ├── 09_EventDrivenReading │ ├── AdsListener.java │ └── Main.java │ ├── 11_EventDrivenDetectionOfSymbolTableChanges │ ├── AdsListener.java │ └── Main.java │ ├── 12_SumCommandReleaseVariableHandles │ ├── Main.java │ ├── ReleaseData.java │ └── RequestData.java │ └── 13_SumCommandReadingWritingVariables │ ├── Main.java │ └── RequestData.java └── src ├── main └── java │ └── de │ └── beckhoff │ └── jni │ ├── AdsConstants.java │ ├── Convert.java │ ├── JNIBool.java │ ├── JNIByteBuffer.java │ ├── JNILong.java │ └── tcads │ ├── AdsCallDllFunction.java │ ├── AdsCallbackObject.java │ ├── AdsDevName.java │ ├── AdsNotificationAttrib.java │ ├── AdsNotificationHeader.java │ ├── AdsState.java │ ├── AdsSymbolEntry.java │ ├── AdsVersion.java │ ├── AmsAddr.java │ ├── AmsNetId.java │ ├── CallbackListenerAdsRouter.java │ └── CallbackListenerAdsState.java └── test └── java └── de └── beckhoff └── jni ├── AllTests.java ├── convert └── test │ ├── AllTests.java │ ├── ConvertBoolTest.java │ ├── ConvertByteTest.java │ ├── ConvertCharTest.java │ ├── ConvertDoubleTest.java │ ├── ConvertExceptionTest.java │ ├── ConvertFloatTest.java │ ├── ConvertIntegerTest.java │ ├── ConvertLongTest.java │ ├── ConvertShortTest.java │ └── ConvertStringTest.java ├── jnibytebuffer └── test │ ├── AllTests.java │ ├── JNIByteBufferInitializationExceptionTest.java │ ├── JNIByteBufferInitializationTest.java │ └── JNIByteBufferSetTest.java ├── jnilong └── test │ ├── AllTests.java │ └── JNILongTest.java └── tcads ├── adscalldllfunction └── test │ ├── AdsAmsPortEnabledTest.java │ ├── AllTests.java │ ├── CallbackObjectTest.java │ ├── DeviceNotificationRequestTest.java │ ├── DeviceNotificationTest.java │ ├── FailPortOpenCloseTest.java │ ├── GetLocalAmsAddressTest.java │ ├── GetSetTimeoutTest.java │ ├── PortOpenCloseTest.java │ ├── ReadDeviceInfoRequestTest.java │ ├── ReadRequestTest.java │ ├── ReadStateRequestTest.java │ ├── ReadWriteRequestTest.java │ ├── RouterNotificationTest.java │ ├── WriteControlRequestTest.java │ ├── WriteRequestArrayTest.java │ └── WriteRequestTest.java ├── adscalldllfunctionex └── test │ ├── AdsAmsPortEnabledExTest.java │ ├── AllTests.java │ ├── DeviceNotificationRequestExTest.java │ ├── GetLocalAmsAddressExTest.java │ ├── GetSetTimeoutExTest.java │ ├── PortOpenCloseExTest.java │ ├── ReadDeviceInfoRequestExTest.java │ ├── ReadRequestEx2Test.java │ ├── ReadRequestExTest.java │ ├── ReadStateRequestExTest.java │ ├── ReadWriteRequestEx2Test.java │ ├── ReadWriteRequestExTest.java │ ├── WriteControlRequestExTest.java │ ├── WriteRequestExArrayTest.java │ └── WriteRequestExTest.java ├── adsdevicename └── test │ ├── AdsDevNameTest.java │ └── AllTests.java ├── adsnotificationattrib └── test │ ├── AdsNotificationAttribTest.java │ └── AllTests.java ├── adsnotificationheader └── test │ ├── AdsNotificationHeaderTest.java │ └── AllTests.java ├── adsstate └── test │ ├── AdsStateTest.java │ └── AllTests.java ├── adssymbolentry └── test │ ├── AdsSymbolEntryExceptionTest.java │ ├── AdsSymbolEntryTest.java │ └── AllTests.java ├── adsversion └── test │ ├── AdsVersionTest.java │ └── AllTests.java ├── amsaddr └── test │ ├── AllTests.java │ ├── AmsAddrStringTest.java │ └── AmsAddrTest.java └── amsnetid └── test ├── AllTests.java └── AmsNetIdTest.java /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | BasedOnStyle: LLVM 3 | IndentWidth: 4 4 | MaxEmptyLinesToKeep: 1 5 | KeepEmptyLinesAtTheStartOfBlocks: false 6 | --- 7 | Language: Java 8 | --- 9 | Language: Cpp 10 | DerivePointerAlignment: false 11 | PointerAlignment: Left 12 | ... 13 | -------------------------------------------------------------------------------- /.clang-tidy: -------------------------------------------------------------------------------- 1 | Checks: > 2 | *, 3 | -google-runtime-int, 4 | -fuchsia-trailing-return, 5 | -fuchsia-default-arguments-calls, 6 | -hicpp-vararg, 7 | -cppcoreguidelines-pro-type-vararg, 8 | -cppcoreguidelines-pro-type-union-access, 9 | -cppcoreguidelines-pro-type-static-cast-downcast, 10 | -cppcoreguidelines-pro-bounds-constant-array-index, 11 | -cppcoreguidelines-pro-type-reinterpret-cast, 12 | -cppcoreguidelines-pro-bounds-pointer-arithmetic, 13 | -bugprone-easily-swappable-parameters, 14 | -llvmlibc-*, 15 | -altera-*, 16 | -modernize-use-trailing-return-type, 17 | HeaderFilterRegex: 'cpp/*.h' 18 | WarningsAsErrors: '*' 19 | 20 | -------------------------------------------------------------------------------- /.cspell.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2", 3 | "language": "en", 4 | "words": [ 5 | "adstojava", 6 | "adslib", 7 | "amsnetid", 8 | "beckhoff", 9 | "bytewise", 10 | "camtool", 11 | "netid", 12 | "tcjavatoads", 13 | "twincat", 14 | "toolset", 15 | "msvc", 16 | "intellij", 17 | "netbeans" 18 | ], 19 | "ignoreWords": [ 20 | "apientry", 21 | "adstransmode", 22 | "adsstdcall", 23 | "adscalldllfunction", 24 | "adscalldllfunctionex", 25 | "adssymbolentry", 26 | "adsdevicename", 27 | "adsnotificationattrib", 28 | "adsnotificationheader", 29 | "fixedfileinfo", 30 | "jnibytebuffer", 31 | "jnilong", 32 | "loword", 33 | "symname", 34 | "amsaddr", 35 | "adsversion", 36 | "adsstate", 37 | "tcads", 38 | "jobject", 39 | "jclass", 40 | "ljclass", 41 | "jniexport", 42 | "jlong", 43 | "jnicall", 44 | "stdafx", 45 | "jdouble", 46 | "jfloat", 47 | "jint", 48 | "jshort", 49 | "jchar", 50 | "jbyte", 51 | "jboolean", 52 | "addressn", 53 | "jmethod", 54 | "portnumber", 55 | "geti", 56 | "adssymbolflag", 57 | "filetime", 58 | "winsock", 59 | "adssym", 60 | "ioff", 61 | "igroup", 62 | "amsport", 63 | "bitvalue", 64 | "powergood", 65 | "powerfailure", 66 | "loadcfg", 67 | "savecfg", 68 | "winskerr", 69 | "adserr", 70 | "routererr", 71 | "adsigrp", 72 | "rterr", 73 | "adsioffs", 74 | "amsevent", 75 | "lbool", 76 | "adstrans", 77 | "hmsg", 78 | "readdata", 79 | "jfield", 80 | "ljbyte", 81 | "ljbyte", 82 | "jsize", 83 | "ljchar", 84 | "lcpp", 85 | "adsdll", 86 | "lmid", 87 | "ljobj", 88 | "lpbyte", 89 | "lpstr", 90 | "ljava", 91 | "multithreading", 92 | "adst" 93 | ], 94 | "ignorePaths": [ 95 | "cpp/ext_Lib/**" 96 | ], 97 | "ignoreRegExpList": [ 98 | "ROUTERERR_[A-Z_]+", 99 | "ADSIGRP_[A-Z_]+", 100 | "ADSERR_[A-Z_]+", 101 | "RTERR_[A-Z_]+", 102 | "ADSIOFFS_[A-Z_]+", 103 | "AMSEVENT_[A-Z_]+", 104 | "ADSTRANS_[A-Z_]+", 105 | "AMSPORT_[0-9A-Z_]+", 106 | "ADS_[A-Z_]+", 107 | "ADST_[A-Z]+", 108 | "WINSKERR_[A-Z_]+" 109 | ] 110 | } 111 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: https://EditorConfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | end_of_line = crlf 7 | insert_final_newline = true 8 | trim_trailing_whitespace = true 9 | charset = utf-8 10 | indent_style = space 11 | indent_size = 4 12 | tab_width = 4 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | build_win32/ 3 | build_x64/ 4 | target/ 5 | dist/ 6 | dependencies/ 7 | node_modules/ 8 | Testing/ 9 | samples/*/[0-9][0-9]_*/*.class 10 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "ADS"] 2 | path = adslib_for_linux 3 | url = https://github.com/Beckhoff/ADS.git 4 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "cmake.sourceDirectory": "${workspaceFolder}/cpp", 3 | "editor.formatOnSave": true, 4 | "files.associations": { 5 | "*.hmc": "cpp", 6 | "limits": "cpp", 7 | "xstring": "cpp" 8 | }, 9 | "search.exclude": { 10 | ".git": true, 11 | "node_modules": true, 12 | "build": true, 13 | "jdk": true, 14 | "target": true 15 | } 16 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Beckhoff 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /bootstrap.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | CALL run\check_dependencies.bat || exit /b %errorlevel% 4 | CALL run\clear.bat || exit /b %errorlevel% 5 | 6 | CALL run\build_cpp.bat || exit /b %errorlevel% 7 | CALL run\build_java.bat || exit /b %errorlevel% 8 | CALL run\build_doc.bat || exit /b %errorlevel% 9 | CALL run\build_samples.bat || exit /b %errorlevel% 10 | -------------------------------------------------------------------------------- /bootstrap.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | . ./run/check_dependencies.sh 5 | . ./run/clear.sh 6 | 7 | . ./run/build_adslib.sh 8 | . ./run/build_cpp.sh 9 | . ./run/build_java.sh 10 | . ./run/build_doc.sh 11 | . ./run/build_samples.sh 12 | -------------------------------------------------------------------------------- /bootstrap_full.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | CALL run\check_dependencies_full.bat || exit /b %errorlevel% 4 | CALL run\clear.bat || exit /b %errorlevel% 5 | 6 | REM CSpell is a NodeJS module 7 | CALL npm install || exit /b %errorlevel% 8 | 9 | CALL run\lint.bat || exit /b %errorlevel% 10 | 11 | CALL run\build_cpp_full.bat || exit /b %errorlevel% 12 | CALL run\build_java_full.bat || exit /b %errorlevel% 13 | CALL run\build_doc.bat || exit /b %errorlevel% 14 | CALL run\build_samples.bat || exit /b %errorlevel% 15 | -------------------------------------------------------------------------------- /bootstrap_full.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | . ./run/check_dependencies_full.sh 5 | . ./run/clear.sh 6 | 7 | npm install # CSpell is a NodeJS module 8 | . ./run/lint.sh 9 | 10 | . ./run/build_cpp_full.sh 11 | . ./run/build_java_full.sh 12 | . ./run/build_doc.sh 13 | . ./run/build_samples.sh 14 | -------------------------------------------------------------------------------- /cpp/JObjAdsDevName.cpp: -------------------------------------------------------------------------------- 1 | #include "JObjAdsDevName.h" 2 | #include "JObjectBase.h" 3 | #include "jni.h" 4 | 5 | JObjAdsDevName::JObjAdsDevName(JNIEnv* lEnv, jobject lJObject) 6 | : JObjectBase(lEnv, lJObject) {} 7 | 8 | void JObjAdsDevName::setValuesInJObject(const char** pAdsDevName) { 9 | setJObjectValueString("mDevName", pAdsDevName); 10 | } 11 | 12 | void JObjAdsDevName::getValuesOutJObject(const char** pAdsDevName) { 13 | getJObjectValueString("mDevName", pAdsDevName); 14 | } 15 | -------------------------------------------------------------------------------- /cpp/JObjAdsDevName.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "JObjectBase.h" 3 | #include "StdAfx.h" 4 | #include "jni.h" 5 | 6 | class JObjAdsDevName : public JObjectBase { 7 | public: 8 | JObjAdsDevName(JNIEnv* lEnv, jobject lJObject); 9 | ~JObjAdsDevName() = default; 10 | 11 | void setValuesInJObject(const char** pAdsDevName); 12 | void getValuesOutJObject(const char** pAdsDevName); 13 | }; 14 | -------------------------------------------------------------------------------- /cpp/JObjAdsNotificationAttrib.cpp: -------------------------------------------------------------------------------- 1 | #include "JObjAdsNotificationAttrib.h" 2 | #include "JObjectBase.h" 3 | #include "jni.h" 4 | #include "jni_md.h" 5 | #ifdef USE_OPENSOURCE_ADSLIB 6 | #include "standalone/AdsDef.h" 7 | #else 8 | #include "TcAdsAPI.h" 9 | #endif 10 | 11 | JObjAdsNotificationAttrib::JObjAdsNotificationAttrib(JNIEnv* lEnv, 12 | jobject lJObject) 13 | : JObjectBase(lEnv, lJObject) {} 14 | 15 | void JObjAdsNotificationAttrib::setValuesInJObject( 16 | AdsNotificationAttrib* pAdsNotificationAttrib) { 17 | setJObjectValue("mCbLength", 18 | static_cast(pAdsNotificationAttrib->cbLength)); 19 | 20 | // determine mNTransMode 21 | int lTransMode = 0; 22 | switch (pAdsNotificationAttrib->nTransMode) { 23 | case ADSTRANS_NOTRANS: 24 | lTransMode = 0; 25 | break; 26 | case ADSTRANS_CLIENTCYCLE: 27 | lTransMode = 1; 28 | break; 29 | case ADSTRANS_CLIENT1REQ: 30 | lTransMode = 2; 31 | break; 32 | case ADSTRANS_SERVERCYCLE: 33 | lTransMode = 3; 34 | break; 35 | case ADSTRANS_SERVERONCHA: 36 | lTransMode = 4; 37 | break; 38 | default: 39 | break; 40 | } 41 | 42 | setJObjectValue("mNTransMode", static_cast(lTransMode)); 43 | setJObjectValue("mNMaxDelay", 44 | static_cast(pAdsNotificationAttrib->nMaxDelay)); 45 | setJObjectValue("mNCycleTime", 46 | static_cast(pAdsNotificationAttrib->nCycleTime)); 47 | setJObjectValue("mDwChangeFilter", 48 | static_cast(pAdsNotificationAttrib->dwChangeFilter)); 49 | } 50 | 51 | void JObjAdsNotificationAttrib::getValuesOutJObject( 52 | AdsNotificationAttrib* pAdsNotificationAttrib) { 53 | unsigned long lULong = 0; 54 | getJObjectValue("mCbLength", &lULong); 55 | pAdsNotificationAttrib->cbLength = lULong; 56 | 57 | // determine mNTransMode 58 | int lInt = 0; 59 | getJObjectValue("mNTransMode", &lInt); 60 | ADSTRANSMODE lADSTRANSMODE = ADSTRANS_NOTRANS; 61 | switch (lInt) { 62 | case 0: 63 | lADSTRANSMODE = ADSTRANS_NOTRANS; 64 | break; 65 | case 1: 66 | lADSTRANSMODE = ADSTRANS_CLIENTCYCLE; 67 | break; 68 | case 2: 69 | lADSTRANSMODE = ADSTRANS_CLIENT1REQ; 70 | break; 71 | case 3: 72 | lADSTRANSMODE = ADSTRANS_SERVERCYCLE; 73 | break; 74 | case 4: 75 | lADSTRANSMODE = ADSTRANS_SERVERONCHA; 76 | break; 77 | default: 78 | break; 79 | } 80 | 81 | pAdsNotificationAttrib->nTransMode = lADSTRANSMODE; 82 | 83 | getJObjectValue("mNMaxDelay", &lULong); 84 | pAdsNotificationAttrib->nMaxDelay = lULong; 85 | 86 | getJObjectValue("mNCycleTime", &lULong); 87 | pAdsNotificationAttrib->nCycleTime = lULong; 88 | 89 | getJObjectValue("mDwChangeFilter", &lULong); 90 | pAdsNotificationAttrib->dwChangeFilter = lULong; 91 | } 92 | -------------------------------------------------------------------------------- /cpp/JObjAdsNotificationAttrib.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "JObjectBase.h" 3 | #include "StdAfx.h" 4 | #include "jni.h" 5 | 6 | class JObjAdsNotificationAttrib : public JObjectBase { 7 | public: 8 | JObjAdsNotificationAttrib(JNIEnv* lEnv, jobject lJObject); 9 | ~JObjAdsNotificationAttrib() = default; 10 | 11 | void setValuesInJObject(AdsNotificationAttrib* pAdsNotificationAttrib); 12 | void getValuesOutJObject(AdsNotificationAttrib* pAdsNotificationAttrib); 13 | }; 14 | -------------------------------------------------------------------------------- /cpp/JObjAdsNotificationHeader.cpp: -------------------------------------------------------------------------------- 1 | #include "JObjAdsNotificationHeader.h" 2 | #include "JObjectBase.h" 3 | #include "jni.h" 4 | #include "jni_md.h" 5 | #ifdef USE_OPENSOURCE_ADSLIB 6 | #include "standalone/AdsDef.h" 7 | #else 8 | #include "TcAdsAPI.h" 9 | #endif 10 | #include 11 | 12 | JObjAdsNotificationHeader::JObjAdsNotificationHeader(JNIEnv* lEnv, 13 | jobject lJObject) 14 | : JObjectBase(lEnv, lJObject) {} 15 | 16 | void JObjAdsNotificationHeader::setValuesInJObject( 17 | const AdsNotificationHeader* pAdsNotificationHeader) { 18 | setJObjectValue("mHNotification", 19 | static_cast(pAdsNotificationHeader->hNotification)); 20 | setJObjectValue("mNTimeStamp", 21 | static_cast(pAdsNotificationHeader->nTimeStamp)); 22 | const auto* data_ptr = reinterpret_cast( 23 | &pAdsNotificationHeader->cbSampleSize) + 24 | sizeof(pAdsNotificationHeader->cbSampleSize); 25 | setJObjectArray("data", data_ptr, false); 26 | } 27 | -------------------------------------------------------------------------------- /cpp/JObjAdsNotificationHeader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "JObjectBase.h" 3 | #include "StdAfx.h" 4 | #include "jni.h" 5 | 6 | class JObjAdsNotificationHeader : public JObjectBase { 7 | public: 8 | JObjAdsNotificationHeader(JNIEnv* lEnv, jobject lJObject); 9 | ~JObjAdsNotificationHeader() = default; 10 | 11 | void 12 | setValuesInJObject(const AdsNotificationHeader* pAdsNotificationHeader); 13 | }; 14 | -------------------------------------------------------------------------------- /cpp/JObjAdsState.cpp: -------------------------------------------------------------------------------- 1 | #include "JObjAdsState.h" 2 | #include "JObjectBase.h" 3 | #include "jni.h" 4 | 5 | JObjAdsState::JObjAdsState(JNIEnv* lEnv, jobject lJObject) 6 | : JObjectBase(lEnv, lJObject) {} 7 | 8 | void JObjAdsState::setValuesInJObject(const unsigned short* pAdsState) { 9 | setJObjectValue("mState", static_cast(*pAdsState)); 10 | } 11 | 12 | void JObjAdsState::getValuesOutJObject(unsigned short* pAdsState) { 13 | short lShort = 0; 14 | getJObjectValue("mState", &lShort); 15 | *pAdsState = lShort; 16 | } -------------------------------------------------------------------------------- /cpp/JObjAdsState.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "JObjectBase.h" 3 | #include "StdAfx.h" 4 | #include "jni.h" 5 | 6 | class JObjAdsState : public JObjectBase { 7 | public: 8 | JObjAdsState(JNIEnv* lEnv, jobject lJObject); 9 | ~JObjAdsState() = default; 10 | 11 | void setValuesInJObject(const unsigned short* pAdsState); 12 | void getValuesOutJObject(unsigned short* pAdsState); 13 | }; 14 | -------------------------------------------------------------------------------- /cpp/JObjAdsVersion.cpp: -------------------------------------------------------------------------------- 1 | #include "JObjAdsVersion.h" 2 | #include "JObjectBase.h" 3 | #include "jni.h" 4 | #ifdef USE_OPENSOURCE_ADSLIB 5 | #include "standalone/AdsDef.h" 6 | #else 7 | #include "TcAdsAPI.h" 8 | #endif 9 | 10 | JObjAdsVersion::JObjAdsVersion(JNIEnv* lEnv, jobject lJObject) 11 | : JObjectBase(lEnv, lJObject) {} 12 | 13 | void JObjAdsVersion::setValuesInJObject(AdsVersion* pAdsVersion) { 14 | setJObjectValue("mVersion", static_cast(pAdsVersion->version)); 15 | setJObjectValue("mRevision", static_cast(pAdsVersion->revision)); 16 | setJObjectValue("mBuild", static_cast(pAdsVersion->build)); 17 | } 18 | 19 | void JObjAdsVersion::getValuesOutJObject(AdsVersion* pAdsVersion) { 20 | char lChar = '\0'; 21 | 22 | getJObjectValue("mVersion", &lChar); 23 | pAdsVersion->version = lChar; 24 | 25 | getJObjectValue("mRevision", &lChar); 26 | pAdsVersion->revision = lChar; 27 | 28 | short lShort = 0; 29 | getJObjectValue("mBuild", &lShort); 30 | pAdsVersion->build = lShort; 31 | } -------------------------------------------------------------------------------- /cpp/JObjAdsVersion.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "JObjectBase.h" 3 | #include "StdAfx.h" 4 | #include "jni.h" 5 | 6 | class JObjAdsVersion : public JObjectBase { 7 | public: 8 | JObjAdsVersion(JNIEnv* lEnv, jobject lJObject); 9 | ~JObjAdsVersion() = default; 10 | 11 | void setValuesInJObject(AdsVersion* pAdsVersion); 12 | void getValuesOutJObject(AdsVersion* pAdsVersion); 13 | }; 14 | -------------------------------------------------------------------------------- /cpp/JObjAmsAddr.cpp: -------------------------------------------------------------------------------- 1 | #include "JObjAmsAddr.h" 2 | #include "JObjAmsNetId.h" 3 | #include "JObjectBase.h" 4 | #include "StdAfx.h" 5 | #include "jni.h" 6 | #include "jni_md.h" 7 | #ifdef USE_OPENSOURCE_ADSLIB 8 | #include "standalone/AdsDef.h" 9 | #else 10 | #include "TcAdsAPI.h" 11 | #endif 12 | #include 13 | #include 14 | #include 15 | 16 | JObjAmsAddr::JObjAmsAddr(JNIEnv* lEnv, jobject lJObject) 17 | : JObjectBase(lEnv, lJObject) {} 18 | 19 | void JObjAmsAddr::setValuesInJObject(const AmsAddr* pAddr) { 20 | setJObjectValue("mPort", static_cast(pAddr->port)); 21 | 22 | // set both versions of the AmsNetId. 23 | // on failure, only abort the current version and try the other one. 24 | jfieldID netId_field = 25 | mEnv->GetFieldID(mJClass, "mNetId", "Lde/beckhoff/jni/tcads/AmsNetId;"); 26 | 27 | jobject netId_obj = mEnv->GetObjectField(mJObject, netId_field); 28 | if (netId_obj != nullptr) { 29 | JObjAmsNetId ljObjAmsNetId(mEnv, netId_obj); 30 | ljObjAmsNetId.setValuesInJObject(&(pAddr->netId)); 31 | } 32 | 33 | for (size_t i = 0; i < sizeof(pAddr->netId.b) / sizeof(pAddr->netId.b[0]); 34 | ++i) { 35 | setJObjectValue(("mNetIdPart" + std::to_string(i)).c_str(), 36 | static_cast(pAddr->netId.b[i])); 37 | } 38 | } 39 | 40 | void JObjAmsAddr::getValuesOutJObject(PAmsAddr pAddr) { 41 | int lInt = 0; 42 | getJObjectValue("mPort", &lInt); 43 | pAddr->port = (lInt < std::numeric_limits::min() || 44 | lInt > std::numeric_limits::max()) 45 | ? 0 46 | : static_cast(lInt); 47 | 48 | // get the AmsNetId values either from the AmsNetId object or the char 49 | // members of AmsAddr. use the latter approach only if the first one 50 | // fails. 51 | 52 | jfieldID netId_field = 53 | mEnv->GetFieldID(mJClass, "mNetId", "Lde/beckhoff/jni/tcads/AmsNetId;"); 54 | 55 | jobject netId_obj = mEnv->GetObjectField(mJObject, netId_field); 56 | if (netId_obj != nullptr) { 57 | JObjAmsNetId ljObjAmsNetId(mEnv, netId_obj); 58 | ljObjAmsNetId.getValuesOutJObject(&(pAddr->netId)); 59 | } else { 60 | for (size_t i = 0; i < sizeof(pAddr->netId.b) / sizeof(unsigned char); 61 | ++i) { 62 | char lChar = '\0'; 63 | getJObjectValue(("mNetIdPart" + std::to_string(i)).c_str(), &lChar); 64 | pAddr->netId.b[i] = lChar; 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /cpp/JObjAmsAddr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "JObjAmsNetId.h" 3 | #include "JObjectBase.h" 4 | #include "StdAfx.h" 5 | #include "jni.h" 6 | 7 | class JObjAmsAddr : public JObjectBase { 8 | public: 9 | JObjAmsAddr(JNIEnv* lEnv, jobject lJObject); 10 | ~JObjAmsAddr() = default; 11 | 12 | void setValuesInJObject(const AmsAddr* pAddr); 13 | void getValuesOutJObject(PAmsAddr pAddr); 14 | }; 15 | -------------------------------------------------------------------------------- /cpp/JObjAmsNetId.cpp: -------------------------------------------------------------------------------- 1 | #include "JObjAmsNetId.h" 2 | #include "JObjectBase.h" 3 | #include "StdAfx.h" 4 | #include "jni.h" 5 | #ifdef USE_OPENSOURCE_ADSLIB 6 | #include "standalone/AdsDef.h" 7 | #else 8 | #include "TcAdsAPI.h" 9 | #endif 10 | 11 | JObjAmsNetId::JObjAmsNetId(JNIEnv* lEnv, jobject lJObject) 12 | : JObjectBase(lEnv, lJObject) {} 13 | 14 | void JObjAmsNetId::setValuesInJObject(const AmsNetId* pNetId) { 15 | setJObjectArray("mB", &pNetId->b[0], true); 16 | } 17 | 18 | void JObjAmsNetId::getValuesOutJObject(PAmsNetId pNetId) { 19 | getJObjectArray("mB", &pNetId->b[0], true); 20 | } 21 | -------------------------------------------------------------------------------- /cpp/JObjAmsNetId.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "JObjectBase.h" 3 | #include "StdAfx.h" 4 | #include "jni.h" 5 | 6 | class JObjAmsNetId : public JObjectBase { 7 | public: 8 | JObjAmsNetId(JNIEnv* lEnv, jobject lJObject); 9 | ~JObjAmsNetId() = default; 10 | 11 | void setValuesInJObject(const AmsNetId* pNetId); 12 | void getValuesOutJObject(PAmsNetId pNetId); 13 | }; 14 | -------------------------------------------------------------------------------- /cpp/JObjJNIBool.cpp: -------------------------------------------------------------------------------- 1 | #include "JObjJNIBool.h" 2 | #include "JObjectBase.h" 3 | #include "jni.h" 4 | 5 | JObjJNIBool::JObjJNIBool(JNIEnv* lEnv, jobject lJObject) 6 | : JObjectBase(lEnv, lJObject) {} 7 | 8 | void JObjJNIBool::setValuesInJObject(const bool* pBool) { 9 | setJObjectValue("mBool", static_cast(*pBool)); 10 | } 11 | 12 | void JObjJNIBool::getValuesOutJObject(bool* pBool) { 13 | getJObjectValue("mBool", pBool); 14 | } -------------------------------------------------------------------------------- /cpp/JObjJNIBool.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "JObjectBase.h" 3 | #include "jni.h" 4 | 5 | class JObjJNIBool : public JObjectBase { 6 | public: 7 | JObjJNIBool(JNIEnv* lEnv, jobject lJObject); 8 | ~JObjJNIBool() = default; 9 | 10 | void setValuesInJObject(const bool* pBool); 11 | void getValuesOutJObject(bool* pBool); 12 | }; 13 | -------------------------------------------------------------------------------- /cpp/JObjJNIByteBuffer.cpp: -------------------------------------------------------------------------------- 1 | #include "JObjJNIByteBuffer.h" 2 | #include "JObjectBase.h" 3 | #include "jni.h" 4 | 5 | JObjJNIByteBuffer::JObjJNIByteBuffer(JNIEnv* lEnv, jobject lJObject) 6 | : JObjectBase(lEnv, lJObject) {} 7 | 8 | void JObjJNIByteBuffer::setValuesInJObject(unsigned char* pByteArray) { 9 | setJObjectArray("mByteArray", pByteArray, false); 10 | } 11 | 12 | void JObjJNIByteBuffer::getValuesOutJObject(unsigned char* pByteArray) { 13 | getJObjectArray("mByteArray", pByteArray, false); 14 | } -------------------------------------------------------------------------------- /cpp/JObjJNIByteBuffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "JObjectBase.h" 3 | #include "jni.h" 4 | 5 | class JObjJNIByteBuffer : public JObjectBase { 6 | public: 7 | JObjJNIByteBuffer(JNIEnv* lEnv, jobject lJObject); 8 | ~JObjJNIByteBuffer() = default; 9 | 10 | void setValuesInJObject(unsigned char* pByteArray); 11 | void getValuesOutJObject(unsigned char* pByteArray); 12 | }; 13 | -------------------------------------------------------------------------------- /cpp/JObjJNILong.cpp: -------------------------------------------------------------------------------- 1 | #include "JObjJNILong.h" 2 | #include "JObjectBase.h" 3 | #include "jni.h" 4 | #include "jni_md.h" 5 | 6 | JObjJNILong::JObjJNILong(JNIEnv* lEnv, jobject lJObject) 7 | : JObjectBase(lEnv, lJObject) {} 8 | 9 | void JObjJNILong::setValuesInJObject(const long* pLong) { 10 | setJObjectValue("mLong", static_cast(*pLong)); 11 | } 12 | 13 | void JObjJNILong::getValuesOutJObject(long* pLong) { 14 | getJObjectValue("mLong", pLong); 15 | } 16 | 17 | void JObjJNILong::setValuesInJObject(const unsigned long* pULong) { 18 | setJObjectValue("mLong", static_cast(*pULong)); 19 | } 20 | 21 | void JObjJNILong::getValuesOutJObject(unsigned long* pULong) { 22 | getJObjectValue("mLong", pULong); 23 | } 24 | -------------------------------------------------------------------------------- /cpp/JObjJNILong.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "JObjectBase.h" 3 | #include "jni.h" 4 | 5 | class JObjJNILong : public JObjectBase { 6 | public: 7 | JObjJNILong(JNIEnv* lEnv, jobject lJObject); 8 | ~JObjJNILong() = default; 9 | 10 | void setValuesInJObject(const long* pLong); 11 | void getValuesOutJObject(long* pLong); 12 | 13 | void setValuesInJObject(const unsigned long* pULong); 14 | void getValuesOutJObject(unsigned long* pULong); 15 | }; 16 | -------------------------------------------------------------------------------- /cpp/JObjectBase.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "jni.h" 3 | #include 4 | 5 | class JObjectBase { 6 | protected: 7 | JNIEnv* mEnv; 8 | jobject mJObject; 9 | jclass mJClass; 10 | 11 | public: 12 | JObjectBase(JNIEnv* lEnv, jobject lJObject); 13 | ~JObjectBase() = default; 14 | 15 | // set native Value 16 | void setJObjectValue(const char* lFieldName, jboolean lValue); 17 | void setJObjectValue(const char* lFieldName, jbyte lValue); 18 | 19 | void setJObjectValue(const char* lFieldName, jchar lValue); 20 | void setJObjectValue(const char* lFieldName, jshort lValue); 21 | void setJObjectValue(const char* lFieldName, jint lValue); 22 | void setJObjectValue(const char* lFieldName, jlong lValue); 23 | 24 | void setJObjectValue(const char* lFieldName, jfloat lValue); 25 | void setJObjectValue(const char* lFieldName, jdouble lValue); 26 | 27 | // get native Value 28 | void getJObjectValue(const char* lFieldName, bool* lValue); 29 | void getJObjectValue(const char* lFieldName, unsigned char* lValue); 30 | 31 | void getJObjectValue(const char* lFieldName, char* lValue); 32 | void getJObjectValue(const char* lFieldName, short* lValue); 33 | void getJObjectValue(const char* lFieldName, int* lValue); 34 | 35 | #ifdef _MSC_VER // clang treats long and int64_t as the same type and gives a 36 | // redefinition error 37 | void getJObjectValue(const char* lFieldName, long* lValue); 38 | #endif 39 | 40 | void getJObjectValue(const char* lFieldName, unsigned long* lValue); 41 | void getJObjectValue(const char* lFieldName, int64_t* lValue); 42 | 43 | void getJObjectValue(const char* lFieldName, float* lValue); 44 | void getJObjectValue(const char* lFieldName, double* lValue); 45 | 46 | // get/set native arrays 47 | void setJObjectArray(const char* lFieldName, const unsigned char* lValue, 48 | bool isJCharArray); 49 | void getJObjectArray(const char* lFieldName, unsigned char* lValue, 50 | bool isJCharArray); 51 | 52 | // get/set native strings 53 | void setJObjectValueString(const char* lFieldName, const char** lValue); 54 | void getJObjectValueString(const char* lFieldName, const char** lValue); 55 | 56 | jstring getJStringFromPChar(char* lText); 57 | }; 58 | -------------------------------------------------------------------------------- /cpp/version.rc.in: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | 4 | #define APSTUDIO_READONLY_SYMBOLS 5 | ///////////////////////////////////////////////////////////////////////////// 6 | // 7 | // Generated from the TEXTINCLUDE 2 resource. 8 | // 9 | #include "winres.h" 10 | 11 | ///////////////////////////////////////////////////////////////////////////// 12 | #undef APSTUDIO_READONLY_SYMBOLS 13 | 14 | ///////////////////////////////////////////////////////////////////////////// 15 | // English (United States) resources 16 | 17 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 18 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 19 | 20 | ///////////////////////////////////////////////////////////////////////////// 21 | // 22 | // Version 23 | // 24 | 25 | VS_VERSION_INFO VERSIONINFO 26 | FILEVERSION @ADSTOJAVA_FILE_VERSION_CS@ 27 | PRODUCTVERSION @ADSTOJAVA_FILE_VERSION_CS@ 28 | FILEFLAGSMASK 0x3fL 29 | #ifdef _DEBUG 30 | FILEFLAGS 0x1L 31 | #else 32 | FILEFLAGS 0x0L 33 | #endif 34 | FILEOS 0x40004L 35 | FILETYPE 0x1L 36 | FILESUBTYPE 0x0L 37 | BEGIN 38 | BLOCK "StringFileInfo" 39 | BEGIN 40 | BLOCK "040904b0" 41 | BEGIN 42 | VALUE "CompanyName", "Beckhoff Automation GmbH & Co. KG" 43 | VALUE "FileDescription", "AdsToJava" 44 | VALUE "FileVersion", "@ADSTOJAVA_FILE_VERSION@" 45 | VALUE "InternalName", "" 46 | VALUE "LegalCopyright", "Beckhoff Automation GmbH & Co. KG" 47 | VALUE "OriginalFilename", "" 48 | VALUE "ProductName", "AdsToJava" 49 | VALUE "ProductVersion", "@ADSTOJAVA_FILE_VERSION@" 50 | END 51 | END 52 | BLOCK "VarFileInfo" 53 | BEGIN 54 | VALUE "Translation", 0x409, 1200 55 | END 56 | END 57 | 58 | #endif // English (United States) resources 59 | ///////////////////////////////////////////////////////////////////////////// 60 | 61 | 62 | 63 | #ifndef APSTUDIO_INVOKED 64 | ///////////////////////////////////////////////////////////////////////////// 65 | // 66 | // Generated from the TEXTINCLUDE 3 resource. 67 | // 68 | 69 | 70 | ///////////////////////////////////////////////////////////////////////////// 71 | #endif // not APSTUDIO_INVOKED 72 | 73 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "cspell": "^8.10.0" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /plc/SamplesPlc/.gitignore: -------------------------------------------------------------------------------- 1 | # Some usual suspects 2 | *.bak 3 | *.bin 4 | *.zip 5 | 6 | # TwinCAT files 7 | *.compiled-library 8 | *.compileinfo 9 | *.tmcRefac 10 | *.library 11 | *.project.~u 12 | *.tclrs 13 | *.tnzip 14 | *.tpy 15 | *.tpzip 16 | *.tsproj.bk? 17 | *.tszip 18 | *.xti.bk? 19 | LineIDs.dbg 20 | _Boot/ 21 | _CompileInfo/ 22 | _Libraries/ 23 | _ModuleInstall/ 24 | _Deployment/ 25 | _Repository/ 26 | 27 | # User-specific files 28 | *.suo 29 | -------------------------------------------------------------------------------- /plc/SamplesPlc/Samples/DUTs/PLCStruct.TcDUT: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 14 | 15 | -------------------------------------------------------------------------------- /plc/SamplesPlc/Samples/GVLs/GVL.TcGVL: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 30 | 31 | -------------------------------------------------------------------------------- /plc/SamplesPlc/Samples/POUs/MAIN.TcPOU: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 34 | 35 | = 0 THEN 57 | bVar01 := TRUE; 58 | bVar02 := FALSE; 59 | END_IF 60 | IF i >= 100 THEN 61 | bVar01 := FALSE; 62 | bVar02 := TRUE; 63 | END_IF 64 | IF i >= 200 THEN 65 | i := 0; 66 | END_IF 67 | ]]> 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /plc/SamplesPlc/Samples/PlcTask.TcTTO: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 10000 6 | 20 7 | 8 | MAIN 9 | 10 | {5b4d0cca-7108-4c7c-b37c-d780c74ec72d} 11 | {0fdbd686-5c49-4753-a80f-bdc7b9d5dab7} 12 | {ed724b11-9a88-4000-82c5-ddfbe585af03} 13 | {31b2eae7-8447-420e-98d4-fce534af3fd4} 14 | {fc535ce5-0c48-4e8f-92f8-03bbe0791acd} 15 | 16 | -------------------------------------------------------------------------------- /plc/SamplesPlc/Samples/Samples.plcproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1.0.0.0 4 | 2.0 5 | {2960d003-cdea-49fa-9507-1c23a70797cb} 6 | True 7 | true 8 | true 9 | false 10 | Samples 11 | 3.1.4023.0 12 | {a7f52dfd-5303-4b0b-af5e-4fbf8b7db48c} 13 | {c2c1d624-77e5-4a01-88ec-4e76bfc91154} 14 | {508f0dc5-3599-4570-b569-0419804fd60a} 15 | {8251445f-cb03-4ac0-899e-f13ff4e271e1} 16 | {1632ba25-4485-4e54-a38c-4fe2a71f0a97} 17 | {7fd60ef3-9a41-4cee-bd17-fa9dc00c0601} 18 | 19 | 20 | 21 | Code 22 | 23 | 24 | Code 25 | true 26 | 27 | 28 | Code 29 | 30 | 31 | Code 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | Tc2_Standard, * (Beckhoff Automation GmbH) 43 | Tc2_Standard 44 | 45 | 46 | Tc2_System, * (Beckhoff Automation GmbH) 47 | Tc2_System 48 | 49 | 50 | Tc3_Module, * (Beckhoff Automation GmbH) 51 | Tc3_Module 52 | 53 | 54 | 55 | 56 | Content 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | "<ProjectRoot>" 65 | 66 | 67 | 68 | 69 | 70 | System.Collections.Hashtable 71 | {54dd0eac-a6d8-46f2-8c27-2f43c7e49861} 72 | System.String 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /plc/SamplesPlc/SamplesPlc.tsproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | PlcTask 8 | 9 | 10 | 11 | 12 | 13 | 14 | Samples Instance 15 | {08500001-0000-0000-F000-000000000064} 16 | 17 | PlcTask Outputs 18 | 19 | GVL.bVar01 20 | 21 | BIT 22 | 23 | 24 | GVL.bVar02 25 | BIT 26 | 27 | 28 | 29 | 30 | 0 31 | PlcTask 32 | 33 | #x02010030 34 | 35 | 20 36 | 10000000 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /plc/TestPlc/.gitignore: -------------------------------------------------------------------------------- 1 | # Some usual suspects 2 | *.bak 3 | *.bin 4 | *.zip 5 | 6 | # TwinCAT files 7 | *.compiled-library 8 | *.compileinfo 9 | *.tmcRefac 10 | *.library 11 | *.project.~u 12 | *.tclrs 13 | *.tnzip 14 | *.tpy 15 | *.tpzip 16 | *.tsproj.bk? 17 | *.tszip 18 | *.xti.bk? 19 | LineIDs.dbg 20 | _Boot/ 21 | _CompileInfo/ 22 | _Libraries/ 23 | _ModuleInstall/ 24 | _Deployment/ 25 | _Repository/ 26 | 27 | # User-specific files 28 | *.suo 29 | -------------------------------------------------------------------------------- /plc/TestPlc/Test/POUs/MAIN.TcPOU: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /plc/TestPlc/Test/PlcTask.TcTTO: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 10000 6 | 20 7 | 8 | MAIN 9 | 10 | {8c283658-0b32-43a1-9c8f-ef3687eed3f2} 11 | {172a43c9-d149-41b2-84d1-b2bc56d7b5eb} 12 | {78517e21-1ea2-4474-a4fa-f0d94019e3ed} 13 | {74b024e2-55d5-462f-84a7-74594bfe82ce} 14 | {47c08ce3-c693-47e1-b8f0-d4faad197287} 15 | 16 | 17 | -------------------------------------------------------------------------------- /plc/TestPlc/TestPLC.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.32126.315 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{B1E792BE-AA5F-4E3C-8C82-674BF9C0715B}") = "TestPLC", "TestPLC.tsproj", "{2A4D10E1-C455-43B0-96A5-459652D74CEA}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|TwinCAT CE7 (ARMV7) = Debug|TwinCAT CE7 (ARMV7) 11 | Debug|TwinCAT OS (ARMT2) = Debug|TwinCAT OS (ARMT2) 12 | Debug|TwinCAT RT (x64) = Debug|TwinCAT RT (x64) 13 | Debug|TwinCAT RT (x86) = Debug|TwinCAT RT (x86) 14 | Release|TwinCAT CE7 (ARMV7) = Release|TwinCAT CE7 (ARMV7) 15 | Release|TwinCAT OS (ARMT2) = Release|TwinCAT OS (ARMT2) 16 | Release|TwinCAT RT (x64) = Release|TwinCAT RT (x64) 17 | Release|TwinCAT RT (x86) = Release|TwinCAT RT (x86) 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {2A4D10E1-C455-43B0-96A5-459652D74CEA}.Debug|TwinCAT CE7 (ARMV7).ActiveCfg = Debug|TwinCAT CE7 (ARMV7) 21 | {2A4D10E1-C455-43B0-96A5-459652D74CEA}.Debug|TwinCAT CE7 (ARMV7).Build.0 = Debug|TwinCAT CE7 (ARMV7) 22 | {2A4D10E1-C455-43B0-96A5-459652D74CEA}.Debug|TwinCAT OS (ARMT2).ActiveCfg = Debug|TwinCAT OS (ARMT2) 23 | {2A4D10E1-C455-43B0-96A5-459652D74CEA}.Debug|TwinCAT OS (ARMT2).Build.0 = Debug|TwinCAT OS (ARMT2) 24 | {2A4D10E1-C455-43B0-96A5-459652D74CEA}.Debug|TwinCAT RT (x64).ActiveCfg = Debug|TwinCAT RT (x64) 25 | {2A4D10E1-C455-43B0-96A5-459652D74CEA}.Debug|TwinCAT RT (x64).Build.0 = Debug|TwinCAT RT (x64) 26 | {2A4D10E1-C455-43B0-96A5-459652D74CEA}.Debug|TwinCAT RT (x86).ActiveCfg = Debug|TwinCAT RT (x86) 27 | {2A4D10E1-C455-43B0-96A5-459652D74CEA}.Debug|TwinCAT RT (x86).Build.0 = Debug|TwinCAT RT (x86) 28 | {2A4D10E1-C455-43B0-96A5-459652D74CEA}.Release|TwinCAT CE7 (ARMV7).ActiveCfg = Release|TwinCAT CE7 (ARMV7) 29 | {2A4D10E1-C455-43B0-96A5-459652D74CEA}.Release|TwinCAT CE7 (ARMV7).Build.0 = Release|TwinCAT CE7 (ARMV7) 30 | {2A4D10E1-C455-43B0-96A5-459652D74CEA}.Release|TwinCAT OS (ARMT2).ActiveCfg = Release|TwinCAT OS (ARMT2) 31 | {2A4D10E1-C455-43B0-96A5-459652D74CEA}.Release|TwinCAT OS (ARMT2).Build.0 = Release|TwinCAT OS (ARMT2) 32 | {2A4D10E1-C455-43B0-96A5-459652D74CEA}.Release|TwinCAT RT (x64).ActiveCfg = Release|TwinCAT RT (x64) 33 | {2A4D10E1-C455-43B0-96A5-459652D74CEA}.Release|TwinCAT RT (x64).Build.0 = Release|TwinCAT RT (x64) 34 | {2A4D10E1-C455-43B0-96A5-459652D74CEA}.Release|TwinCAT RT (x86).ActiveCfg = Release|TwinCAT RT (x86) 35 | {2A4D10E1-C455-43B0-96A5-459652D74CEA}.Release|TwinCAT RT (x86).Build.0 = Release|TwinCAT RT (x86) 36 | {DA1FDEE5-DC2F-4F14-8623-168292372630}.Debug|TwinCAT CE7 (ARMV7).ActiveCfg = Debug|TwinCAT CE7 (ARMV7) 37 | {DA1FDEE5-DC2F-4F14-8623-168292372630}.Debug|TwinCAT CE7 (ARMV7).Build.0 = Debug|TwinCAT CE7 (ARMV7) 38 | {DA1FDEE5-DC2F-4F14-8623-168292372630}.Debug|TwinCAT OS (ARMT2).ActiveCfg = Debug|TwinCAT OS (ARMT2) 39 | {DA1FDEE5-DC2F-4F14-8623-168292372630}.Debug|TwinCAT OS (ARMT2).Build.0 = Debug|TwinCAT OS (ARMT2) 40 | {DA1FDEE5-DC2F-4F14-8623-168292372630}.Debug|TwinCAT RT (x64).ActiveCfg = Debug|TwinCAT RT (x64) 41 | {DA1FDEE5-DC2F-4F14-8623-168292372630}.Debug|TwinCAT RT (x64).Build.0 = Debug|TwinCAT RT (x64) 42 | {DA1FDEE5-DC2F-4F14-8623-168292372630}.Debug|TwinCAT RT (x86).ActiveCfg = Debug|TwinCAT RT (x86) 43 | {DA1FDEE5-DC2F-4F14-8623-168292372630}.Debug|TwinCAT RT (x86).Build.0 = Debug|TwinCAT RT (x86) 44 | {DA1FDEE5-DC2F-4F14-8623-168292372630}.Release|TwinCAT CE7 (ARMV7).ActiveCfg = Release|TwinCAT CE7 (ARMV7) 45 | {DA1FDEE5-DC2F-4F14-8623-168292372630}.Release|TwinCAT CE7 (ARMV7).Build.0 = Release|TwinCAT CE7 (ARMV7) 46 | {DA1FDEE5-DC2F-4F14-8623-168292372630}.Release|TwinCAT OS (ARMT2).ActiveCfg = Release|TwinCAT OS (ARMT2) 47 | {DA1FDEE5-DC2F-4F14-8623-168292372630}.Release|TwinCAT OS (ARMT2).Build.0 = Release|TwinCAT OS (ARMT2) 48 | {DA1FDEE5-DC2F-4F14-8623-168292372630}.Release|TwinCAT RT (x64).ActiveCfg = Release|TwinCAT RT (x64) 49 | {DA1FDEE5-DC2F-4F14-8623-168292372630}.Release|TwinCAT RT (x64).Build.0 = Release|TwinCAT RT (x64) 50 | {DA1FDEE5-DC2F-4F14-8623-168292372630}.Release|TwinCAT RT (x86).ActiveCfg = Release|TwinCAT RT (x86) 51 | {DA1FDEE5-DC2F-4F14-8623-168292372630}.Release|TwinCAT RT (x86).Build.0 = Release|TwinCAT RT (x86) 52 | EndGlobalSection 53 | GlobalSection(SolutionProperties) = preSolution 54 | HideSolutionNode = FALSE 55 | EndGlobalSection 56 | GlobalSection(ExtensibilityGlobals) = postSolution 57 | SolutionGuid = {A8871A9B-CAAD-4605-9758-36964C94F0EA} 58 | EndGlobalSection 59 | EndGlobal 60 | -------------------------------------------------------------------------------- /plc/TestPlc/TestPLC.tsproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | PlcTask 8 | 9 | 10 | 11 | 12 | 13 | 14 | Test Instance 15 | {08500001-0000-0000-F000-000000000064} 16 | 17 | 18 | 0 19 | PlcTask 20 | 21 | #x02010030 22 | 23 | 20 24 | 10000000 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | de.beckhoff.jni 5 | TcJavaToAds 6 | 3.1.0 7 | 8 | 9 | UTF-8 10 | 1.8 11 | 1.8 12 | 13 | 14 | 15 | 16 | junit 17 | junit 18 | 4.13.1 19 | test 20 | 21 | 22 | 23 | 24 | 25 | 26 | com.github.spotbugs 27 | spotbugs-maven-plugin 28 | 4.8.6.1 29 | 30 | 31 | 32 | com.h3xstream.findsecbugs 33 | findsecbugs-plugin 34 | 1.13.0 35 | 36 | 37 | 38 | 39 | 40 | org.jacoco 41 | jacoco-maven-plugin 42 | 0.8.12 43 | 44 | 45 | 46 | prepare-agent 47 | 48 | 49 | 50 | report 51 | prepare-package 52 | 53 | report 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /run/all_samples.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | SET PATH=%cd%\dist\;%PATH% 4 | 5 | echo "Starting sample 02_AccessByVariableName..." 6 | java -jar dist\02_AccessByVariableName.jar || exit /b %errorlevel% 7 | echo -e "\nStarting sample 03_AccessAnArray..." 8 | java -jar dist\03_AccessAnArray.jar || exit /b %errorlevel% 9 | echo -e "\nStarting sample 04_TransmittingStructures..." 10 | java -jar dist\04_TransmittingStructures.jar || exit /b %errorlevel% 11 | echo -e "\nStarting sample 05_ReadingAVariableDeclaration..." 12 | java -jar dist\05_ReadingAVariableDeclaration.jar || exit /b %errorlevel% 13 | echo -e "\nStarting sample 06_WriteFlagSynchronously..." 14 | java -jar dist\06_WriteFlagSynchronously.jar || exit /b %errorlevel% 15 | echo -e "\nStarting sample 07_ReadFlagSynchronously..." 16 | java -jar dist\07_ReadFlagSynchronously.jar || exit /b %errorlevel% 17 | echo -e "\nStarting sample 08_ReleaseVariableHandle..." 18 | java -jar dist\08_ReleaseVariableHandle.jar || exit /b %errorlevel% 19 | echo -e "\nStarting sample 09_EventDrivenReading..." 20 | java -jar dist\09_EventDrivenReading.jar || exit /b %errorlevel% 21 | echo -e "\nStarting sample 11_EventDrivenDetectionOfSymbolTableChanges..." 22 | java -jar dist\11_EventDrivenDetectionOfSymbolTableChanges.jar || exit /b %errorlevel% 23 | echo -e "\nStarting sample 12_SumCommandReleaseVariableHandles..." 24 | java -jar dist\12_SumCommandReleaseVariableHandles.jar || exit /b %errorlevel% 25 | echo -e "\nStarting sample 13_SumCommandReadingWritingVariables..." 26 | java -jar dist\13_SumCommandReadingWritingVariables.jar || exit /b %errorlevel% 27 | -------------------------------------------------------------------------------- /run/all_samples.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | export PATH=$(pwd)/dist:$PATH 5 | export LD_LIBRARY_PATH=$(pwd)/dist:$LD_LIBRARY_PATH 6 | 7 | OSCHECK="$(uname -s)" 8 | USE_OPENSOURCE_ADSLIB=false 9 | case "${OSCHECK}" in 10 | MINGW*) USE_OPENSOURCE_ADSLIB=false ;; 11 | FreeBSD) USE_OPENSOURCE_ADSLIB=false ;; 12 | *) USE_OPENSOURCE_ADSLIB=true ;; 13 | esac 14 | 15 | if [ "$USE_OPENSOURCE_ADSLIB" = true ] ; then 16 | echo "Starting sample 02_AccessByVariableName_adslib..." 17 | java -jar ./dist/02_AccessByVariableName_adslib.jar 18 | else 19 | echo "Starting sample 02_AccessByVariableName..." 20 | java -jar ./dist/02_AccessByVariableName.jar 21 | echo "Starting sample 02_AccessByVariableName..." 22 | java -jar ./dist/02_AccessByVariableName.jar 23 | echo -e "\nStarting sample 03_AccessAnArray..." 24 | java -jar ./dist/03_AccessAnArray.jar 25 | echo -e "\nStarting sample 04_TransmittingStructures..." 26 | java -jar ./dist/04_TransmittingStructures.jar 27 | echo -e "\nStarting sample 05_ReadingAVariableDeclaration..." 28 | java -jar ./dist/05_ReadingAVariableDeclaration.jar 29 | echo -e "\nStarting sample 06_WriteFlagSynchronously..." 30 | java -jar ./dist/06_WriteFlagSynchronously.jar 31 | echo -e "\nStarting sample 07_ReadFlagSynchronously..." 32 | java -jar ./dist/07_ReadFlagSynchronously.jar 33 | echo -e "\nStarting sample 08_ReleaseVariableHandle..." 34 | java -jar ./dist/08_ReleaseVariableHandle.jar 35 | echo -e "\nStarting sample 09_EventDrivenReading..." 36 | java -jar ./dist/09_EventDrivenReading.jar 37 | echo -e "\nStarting sample 11_EventDrivenDetectionOfSymbolTableChanges..." 38 | java -jar ./dist/11_EventDrivenDetectionOfSymbolTableChanges.jar 39 | echo -e "\nStarting sample 12_SumCommandReleaseVariableHandles..." 40 | java -jar ./dist/12_SumCommandReleaseVariableHandles.jar 41 | echo -e "\nStarting sample 13_SumCommandReadingWritingVariables..." 42 | java -jar ./dist/13_SumCommandReadingWritingVariables.jar 43 | fi -------------------------------------------------------------------------------- /run/build_adslib.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | OSCHECK="$(uname -s)" 5 | USE_OPENSOURCE_ADSLIB=false 6 | case "${OSCHECK}" in 7 | MINGW*) USE_OPENSOURCE_ADSLIB=false ;; 8 | FreeBSD) USE_OPENSOURCE_ADSLIB=false ;; 9 | *) USE_OPENSOURCE_ADSLIB=true ;; 10 | esac 11 | 12 | if [ "$USE_OPENSOURCE_ADSLIB" = true ] ; then 13 | cd adslib_for_linux 14 | cmake -S . -B build 15 | cmake --build build 16 | cd .. 17 | # cmake -H./adslib_for_linux/ -B./adslib_for_linux/build 18 | # cmake --build ./adslib_for_linux/build -j 14 19 | fi -------------------------------------------------------------------------------- /run/build_cpp.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | IF EXIST build ( 4 | rmdir /q /s build || exit /b %errorlevel% 5 | ) 6 | IF EXIST build_win32 ( 7 | rmdir /q /s build_win32 || exit /b %errorlevel% 8 | ) 9 | IF EXIST build_x64 ( 10 | rmdir /q /s build_x64 || exit /b %errorlevel% 11 | ) 12 | 13 | setlocal enabledelayedexpansion 14 | 15 | set vs_versions="Visual Studio 17 2022" "Visual Studio 16 2019" "Visual Studio 15 2017" "Visual Studio 14 2015" 16 | set newest_available= 17 | for %%v in (%vs_versions%) do ( 18 | cmake --help | findstr /C:%%v > nul 19 | if not errorlevel 1 ( 20 | set newest_available=%%v 21 | goto version_found 22 | ) 23 | ) 24 | :version_found 25 | 26 | if not %newest_available% == "" ( 27 | echo Newest available Visual Studio generator: %newest_available% 28 | 29 | mkdir build_win32 || exit /b %errorlevel% 30 | cmake -Hcpp -Bbuild_win32 -G %newest_available% -A Win32 || exit /b %errorlevel% 31 | cmake --build build_win32 --config Release --target ALL_BUILD -j 14|| exit /b %errorlevel% 32 | 33 | mkdir build_x64|| exit /b %errorlevel% 34 | cmake -Hcpp -Bbuild_x64 -G %newest_available% -A x64 || exit /b %errorlevel% 35 | cmake --build build_x64 --config Release --target ALL_BUILD -j 14 || exit /b %errorlevel% 36 | 37 | CALL run\copy_to_dist.bat 38 | ) else ( 39 | echo No Visual Studio generator found. 40 | ) 41 | -------------------------------------------------------------------------------- /run/build_cpp.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | if [ -d "./build" ]; then 5 | rm -rd ./build 6 | fi 7 | if [ -d "./build_win32" ]; then 8 | rm -rd ./build_win32 9 | fi 10 | if [ -d "./build_x64" ]; then 11 | rm -rd ./build_x64 12 | fi 13 | 14 | if [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]]; then 15 | visual_studio_versions=("Visual Studio 17 2022" "Visual Studio 16 2019" "Visual Studio 15 2017") 16 | newest_available="" 17 | for version in "${visual_studio_versions[@]}"; do 18 | if cmake --help | grep -q "$version"; then 19 | newest_available="$version" 20 | break 21 | fi 22 | done 23 | 24 | if [ -n "$newest_available" ]; then 25 | echo "Newest available Visual Studio generator: $newest_available" 26 | 27 | mkdir ./build_win32 28 | cmake -H./cpp -B./build_win32 -G "$newest_available" -A Win32 29 | cmake --build ./build_win32 --config Release --target ALL_BUILD -j 14 30 | 31 | mkdir ./build_x64 32 | cmake -H./cpp -B./build_x64 -G "$newest_available" -A x64 33 | cmake --build ./build_x64 --config Release --target ALL_BUILD -j 14 34 | else 35 | echo "No Visual Studio generator found." 36 | fi 37 | else 38 | mkdir ./build 39 | cmake -H./cpp -B./build -G "Ninja" 40 | cmake --build ./build --config Release -j 14 41 | fi 42 | 43 | . ./run/copy_to_dist.sh 44 | -------------------------------------------------------------------------------- /run/build_cpp_full.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | IF EXIST build ( 4 | rmdir /q /s build || exit /b %errorlevel% 5 | ) 6 | IF EXIST build_win32 ( 7 | rmdir /q /s build_win32 || exit /b %errorlevel% 8 | ) 9 | IF EXIST build_x64 ( 10 | rmdir /q /s build_x64 || exit /b %errorlevel% 11 | ) 12 | 13 | mkdir build_win32 || exit /b %errorlevel% 14 | cmake -Hcpp -Bbuild_win32 -G "Visual Studio 17 2022" -A Win32 || exit /b %errorlevel% 15 | cmake --build build_win32 --config Release --target ALL_BUILD -j 14|| exit /b %errorlevel% 16 | 17 | mkdir build_x64|| exit /b %errorlevel% 18 | cmake -Hcpp -Bbuild_x64 -G "Visual Studio 17 2022" -A x64 || exit /b %errorlevel% 19 | cmake --build build_x64 --config Release --target ALL_BUILD -j 14 || exit /b %errorlevel% 20 | 21 | CALL run\copy_to_dist.bat 22 | -------------------------------------------------------------------------------- /run/build_cpp_full.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | if [ -d "./build" ]; then 5 | rm -rd ./build 6 | fi 7 | if [ -d "./build_win32" ]; then 8 | rm -rd ./build_win32 9 | fi 10 | if [ -d "./build_x64" ]; then 11 | rm -rd ./build_x64 12 | fi 13 | 14 | if [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]]; then 15 | mkdir ./build_win32 16 | cmake -H./cpp -B./build_win32 -G "Visual Studio 17 2022" -A Win32 -DSTRICT_WARNINGS=ON 17 | cmake --build ./build_win32 --config Release --target ALL_BUILD -j 14 18 | 19 | mkdir ./build_x64 20 | cmake -H./cpp -B./build_x64 -G "Visual Studio 17 2022" -A x64 -DSTRICT_WARNINGS=ON 21 | cmake --build ./build_x64 --config Release --target ALL_BUILD -j 14 22 | else 23 | mkdir ./build 24 | cmake -H./cpp -B./build -G "Ninja" -DSTRICT_WARNINGS=ON 25 | cmake --build ./build --config Release -j 14 26 | fi 27 | 28 | . ./run/copy_to_dist.sh 29 | -------------------------------------------------------------------------------- /run/build_doc.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | IF NOT EXIST dist ( 4 | mkdir dist || exit /b %errorlevel% 5 | ) 6 | 7 | IF EXIST dist\doc ( 8 | rmdir /q /s dist\doc || exit /b %errorlevel% 9 | ) 10 | mkdir dist\doc || exit /b %errorlevel% 11 | 12 | javadoc -d dist\doc -sourcepath src\main\java -subpackages de.beckhoff.jni || exit /b %errorlevel% 13 | -------------------------------------------------------------------------------- /run/build_doc.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | if ! [ -d "./dist" ]; then 5 | mkdir ./dist 6 | fi 7 | 8 | if [ -d "./dist/doc" ]; then 9 | rm -rd ./dist/doc 10 | fi 11 | mkdir ./dist/doc 12 | 13 | javadoc -d ./dist/doc -sourcepath ./src/main/java -subpackages de.beckhoff.jni 14 | -------------------------------------------------------------------------------- /run/build_java.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | SET PATH=%cd%\dist\;%PATH% 4 | 5 | REM this call also runs all the tests and create coverage report 6 | REM (https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html) 7 | CALL mvn.cmd package -Dmaven.test.skip -f "pom.xml" || exit /b %errorlevel% 8 | 9 | xcopy target\TcJavaToAds-3.1.0.jar dist\ || exit /b %errorlevel% 10 | -------------------------------------------------------------------------------- /run/build_java.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | # this call also runs all the tests and create coverage report 5 | # (https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html) 6 | mvn package -Dmaven.test.skip -f "pom.xml" 7 | 8 | cp ./target/TcJavaToAds-3.1.0.jar ./dist/ 9 | -------------------------------------------------------------------------------- /run/build_java_full.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | SET PATH=%cd%\dist\;%PATH% 4 | 5 | CALL mvn.cmd spotbugs:check -f "pom.xml" || exit /b %errorlevel% 6 | 7 | REM this call also runs all the tests and create coverage report 8 | REM (https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html) 9 | CALL mvn.cmd package -f "pom.xml" || exit /b %errorlevel% 10 | 11 | xcopy target\TcJavaToAds-3.1.0.jar dist\ || exit /b %errorlevel% 12 | -------------------------------------------------------------------------------- /run/build_java_full.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | export PATH=$(pwd)/dist:$PATH 5 | export LD_LIBRARY_PATH=$(pwd)/dist:$LD_LIBRARY_PATH 6 | 7 | # apply patches depending on the installed java version 8 | java_version=$(java -version 2>&1) 9 | echo "Java version: $java_version" 10 | if [[ "$java_version" == *" 1.8"* ]]; then 11 | echo "Applying patch: we need to use isAccessible before Java 9" 12 | sed -i '' -e 's/canAccess(null)/isAccessible()/' './src/test/java/de/beckhoff/jni/tcads/amsaddr/test/AmsAddrTest.java' 13 | function cleanup { 14 | echo "Removing patch: prefer the newer canAccess method instead of isAccessible" 15 | sed -i '' -e 's/isAccessible()/canAccess(null)/' './src/test/java/de/beckhoff/jni/tcads/amsaddr/test/AmsAddrTest.java' 16 | } 17 | trap cleanup EXIT 18 | fi 19 | 20 | java -XshowSettings:properties -version 21 | 22 | mvn spotbugs:check -f "pom.xml" 23 | 24 | # this call also runs all the tests and create coverage report 25 | # (https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html) 26 | mvn package -f "pom.xml" 27 | 28 | cp ./target/TcJavaToAds-3.1.0.jar ./dist/ 29 | -------------------------------------------------------------------------------- /run/check_dependencies.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | WHERE java >NUL 2>NUL 4 | IF %ERRORLEVEL% NEQ 0 ( 5 | echo "Command 'java' does not exist. Install OpenJDK or some other Java Development Kit." 6 | exit /b %errorlevel% 7 | ) 8 | 9 | WHERE javac >NUL 2>NUL 10 | IF %ERRORLEVEL% NEQ 0 ( 11 | echo "Command 'javac' does not exist. Install OpenJDK or some other Java Development Kit." 12 | exit /b %errorlevel% 13 | ) 14 | 15 | WHERE jar >NUL 2>NUL 16 | IF %ERRORLEVEL% NEQ 0 ( 17 | echo "Command 'jar' does not exist. Install OpenJDK or some other Java Development Kit." 18 | exit /b %errorlevel% 19 | ) 20 | 21 | WHERE javadoc >NUL 2>NUL 22 | IF %ERRORLEVEL% NEQ 0 ( 23 | echo "Command 'javadoc' does not exist. Install OpenJDK or some other Java Development Kit." 24 | exit /b %errorlevel% 25 | ) 26 | 27 | WHERE mvn >NUL 2>NUL 28 | IF %ERRORLEVEL% NEQ 0 ( 29 | echo "Command 'mvn' does not exist. Install Apache Maven." 30 | exit /b %errorlevel% 31 | ) 32 | 33 | WHERE cmake >NUL 2>NUL 34 | IF %ERRORLEVEL% NEQ 0 ( 35 | echo "Command 'cmake' does not exist. Install CMake." 36 | exit /b %errorlevel% 37 | ) 38 | -------------------------------------------------------------------------------- /run/check_dependencies.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | if ! command -v java &> /dev/null 5 | then 6 | >&2 echo "Command 'java' does not exist. Install OpenJDK or some other Java Development Kit." 7 | exit 1 8 | fi 9 | 10 | if ! command -v javac &> /dev/null 11 | then 12 | >&2 echo "Command 'javac' does not exist. Install OpenJDK or some other Java Development Kit." 13 | exit 1 14 | fi 15 | 16 | if ! command -v jar &> /dev/null 17 | then 18 | >&2 echo "Command 'jar' does not exist. Install OpenJDK or some other Java Development Kit." 19 | exit 1 20 | fi 21 | 22 | if ! command -v javadoc &> /dev/null 23 | then 24 | >&2 echo "Command 'javadoc' does not exist. Install OpenJDK or some other Java Development Kit." 25 | exit 1 26 | fi 27 | 28 | if ! command -v mvn &> /dev/null 29 | then 30 | >&2 echo "Command 'mvn' does not exist. Install Apache Maven." 31 | exit 1 32 | fi 33 | 34 | if ! command -v cmake &> /dev/null 35 | then 36 | >&2 echo "Command 'cmake' does not exist. Install CMake." 37 | exit 1 38 | fi 39 | 40 | if [ -n "$JAVA_HOME" ]; then 41 | echo "JAVA_HOME is $JAVA_HOME" 42 | else 43 | java_version=$(java -version 2>&1) 44 | echo "Java version: $java_version" 45 | if [[ "$java_version" == *" 1.8"* ]] && [[ -d /usr/local/openjdk8 ]]; then 46 | export JAVA_HOME=/usr/local/openjdk8 47 | echo "The JAVA_HOME environment variable is not set. Automatically setting it to $JAVA_HOME." 48 | else 49 | java_major_version=$(java -version 2>&1 | awk -F '"' '/version/ {print $2}' | awk -F '.' '{sub("^$", "0", $2); print $1}') 50 | if [[ -d "/usr/lib/jvm/java-$java_major_version-openjdk/" ]]; then 51 | export JAVA_HOME="/usr/lib/jvm/java-$java_major_version-openjdk/" 52 | echo "The JAVA_HOME environment variable is not set. Automatically setting it to $JAVA_HOME." 53 | else 54 | echo "Please set the JAVA_HOME environment variable." 55 | fi 56 | fi 57 | fi -------------------------------------------------------------------------------- /run/check_dependencies_full.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | CALL run/check_dependencies.bat 4 | 5 | WHERE npm >NUL 2>NUL 6 | IF %ERRORLEVEL% NEQ 0 ( 7 | echo "Command 'npm' does not exist. Install NodeJS including the Node Package Manager (NPM)." 8 | exit /b %errorlevel% 9 | ) 10 | 11 | WHERE clang-format >NUL 2>NUL 12 | IF %ERRORLEVEL% NEQ 0 ( 13 | echo"Command 'clang-format' does not exist. Install Clang Format." 14 | exit /b %errorlevel% 15 | ) 16 | -------------------------------------------------------------------------------- /run/check_dependencies_full.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | . ./run/check_dependencies.sh 5 | 6 | if ! command -v npm &> /dev/null 7 | then 8 | >&2 echo "Command 'npm' does not exist. Install NodeJS including the Node Package Manager (NPM)." 9 | exit 1 10 | fi 11 | 12 | if ! command -v clang-format &> /dev/null 13 | then 14 | >&2 echo "Command 'clang-format' does not exist. Install Clang Format." 15 | exit 1 16 | fi 17 | -------------------------------------------------------------------------------- /run/clear.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | IF EXIST dist ( 4 | rmdir /q /s dist || exit /b %errorlevel% 5 | ) 6 | IF EXIST build ( 7 | rmdir /q /s build || exit /b %errorlevel% 8 | ) 9 | IF EXIST build_win32 ( 10 | rmdir /q /s build_win32 || exit /b %errorlevel% 11 | ) 12 | IF EXIST build_x64 ( 13 | rmdir /q /s build_x64 || exit /b %errorlevel% 14 | ) 15 | IF EXIST target ( 16 | rmdir /q /s target || exit /b %errorlevel% 17 | ) 18 | -------------------------------------------------------------------------------- /run/clear.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | if [ -d "./dist" ]; then 5 | rm -rd ./dist 6 | fi 7 | 8 | if [ -d "./build" ]; then 9 | rm -rd ./build 10 | fi 11 | if [ -d "./build_win32" ]; then 12 | rm -rd ./build_win32 13 | fi 14 | if [ -d "./build_x64" ]; then 15 | rm -rd ./build_x64 16 | fi 17 | 18 | if [ -d "./target" ]; then 19 | rm -rd ./target 20 | fi 21 | -------------------------------------------------------------------------------- /run/copy_to_dist.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | IF EXIST dist rmdir /q /s dist 4 | mkdir dist || exit /b %errorlevel% 5 | 6 | IF EXIST build_x64 ( 7 | xcopy build_x64\Release\*.dll dist\ || exit /b %errorlevel% 8 | ) ELSE ( 9 | IF EXIST build_win32 ( 10 | xcopy build_win32\Release\*.dll dist\ || exit /b %errorlevel% 11 | ) ELSE ( 12 | IF EXIST build ( 13 | xcopy build\Release\*.dll dist\ || exit /b %errorlevel% 14 | ) 15 | ) 16 | ) 17 | -------------------------------------------------------------------------------- /run/copy_to_dist.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | if [ -d "./dist" ]; then 5 | rm -rd ./dist 6 | fi 7 | mkdir ./dist 8 | 9 | if [ -d "./build_x64" ]; then 10 | cp ./build_x64/Release/*.dll ./dist/ 11 | elif [ -d "./build_win32" ]; then 12 | cp ./build_win32/Release/*.dll ./dist/ 13 | elif [ -d "./build" ]; then 14 | cp ./build/*.so ./dist/ 15 | if [ -d "./build/Release" ]; then 16 | cp ./build/Release/*.dll ./dist/ 17 | fi 18 | 19 | OSCHECK="$(uname -s)" 20 | USE_OPENSOURCE_ADSLIB=false 21 | case "${OSCHECK}" in 22 | MINGW*) USE_OPENSOURCE_ADSLIB=false ;; 23 | FreeBSD) USE_OPENSOURCE_ADSLIB=false ;; 24 | *) USE_OPENSOURCE_ADSLIB=true ;; 25 | esac 26 | 27 | if [ "$USE_OPENSOURCE_ADSLIB" = true ] ; then 28 | cp ./adslib_for_linux/build/AdsLib/*.so ./dist/ 29 | fi 30 | fi 31 | -------------------------------------------------------------------------------- /run/lint.bat: -------------------------------------------------------------------------------- 1 | REM TODO: format c++ code automatically. see lint.sh for reference. 2 | 3 | REM perform spell check on all source files 4 | CALL node_modules\.bin\cspell.cmd cpp\*.h cpp\*.cpp src\**\*.java samples\**\*.java || exit /b %errorlevel% 5 | -------------------------------------------------------------------------------- /run/lint.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | # format c++ code automatically using https://clang.llvm.org/docs/ClangFormat.html 5 | find ./cpp/ -maxdepth 1 -type f -iname *.h -o -iname *.cpp | xargs clang-format -i 6 | find ./src/ -type f -iname *.java | xargs clang-format -i 7 | find ./samples/*/[0-9][0-9]_*/ -type f -iname *.java | xargs clang-format -i 8 | 9 | # perform spell check on all source files 10 | ./node_modules/.bin/cspell ./cpp/*.h ./cpp/*.cpp ./src/**/*.java ./samples/**/*.java 11 | -------------------------------------------------------------------------------- /samples/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Main-Class: Main 3 | Class-Path: TcJavaToAds-3.1.0.jar 4 | -------------------------------------------------------------------------------- /samples/adslib/02_AccessByVariableName/Main.java: -------------------------------------------------------------------------------- 1 | import de.beckhoff.jni.Convert; 2 | import de.beckhoff.jni.JNIByteBuffer; 3 | import de.beckhoff.jni.JNILong; 4 | import de.beckhoff.jni.tcads.AdsCallDllFunction; 5 | import de.beckhoff.jni.tcads.AmsAddr; 6 | 7 | public class Main { 8 | public static void main(String[] args) { 9 | long err; 10 | JNIByteBuffer handleBuff = new JNIByteBuffer(Integer.SIZE / Byte.SIZE); 11 | JNIByteBuffer symbolBuff = 12 | new JNIByteBuffer(Convert.StringToByteArr("MAIN.PLCVar", true)); 13 | JNIByteBuffer dataBuff = new JNIByteBuffer(Integer.SIZE / Byte.SIZE); 14 | 15 | // Open communication 16 | long port = AdsCallDllFunction.adsPortOpenEx(); 17 | if (port == 0) { 18 | System.out.println("Error: Unable to open an ADS port."); 19 | } 20 | 21 | AmsAddr addr = new AmsAddr(); 22 | addr.setNetIdStringEx("X.X.X.X.1.1"); // ADJUST THIS VALUE! 23 | addr.setPort(851); 24 | 25 | // Uncomment and adjust if automatic AMS NetId deduction is 26 | // not working as expected: 27 | // { 28 | // AmsAddr local = new AmsAddr(); 29 | // local.setNetIdStringEx("Y.Y.Y.Y.1.1"); 30 | // AdsCallDllFunction.adsSetLocalAddress(local.getNetId()); 31 | // } 32 | 33 | // Since the AMS routing isn't handled by the TwinCAT AMS Router, 34 | // we need to tell the AdsLib which IP address is associated with the 35 | // AMS NetId. 36 | AdsCallDllFunction.adsAddLocalRoute(addr.getNetId(), 37 | "X.X.X.X"); // ADJUST THIS VALUE! 38 | 39 | // Get handle by symbol name 40 | JNILong lengthReturn = new JNILong(); 41 | err = AdsCallDllFunction.adsSyncReadWriteReqEx2( 42 | port, addr, AdsCallDllFunction.ADSIGRP_SYM_HNDBYNAME, 0x0, 43 | handleBuff.getUsedBytesCount(), handleBuff, 44 | symbolBuff.getUsedBytesCount(), symbolBuff, lengthReturn); 45 | if (err != 0) { 46 | System.out.println("Error: Get handle: 0x" + Long.toHexString(err)); 47 | } else { 48 | System.out.println("Success: Get handle!"); 49 | } 50 | 51 | // Handle: byte[] to int 52 | int hdlBuffToInt = Convert.ByteArrToInt(handleBuff.getByteArray()); 53 | 54 | // Read value by handle 55 | lengthReturn = new JNILong(); 56 | err = AdsCallDllFunction.adsSyncReadReqEx2( 57 | port, addr, AdsCallDllFunction.ADSIGRP_SYM_VALBYHND, hdlBuffToInt, 58 | 0x4, dataBuff, lengthReturn); 59 | if (err != 0) { 60 | System.out.println("Error: Read by handle: 0x" + 61 | Long.toHexString(err)); 62 | } else { 63 | // Data: byte[] to int 64 | int intVal = Convert.ByteArrToInt(dataBuff.getByteArray()); 65 | System.out.println("Success: PLCVar value: " + intVal); 66 | } 67 | 68 | // Release handle 69 | err = AdsCallDllFunction.adsSyncWriteReqEx( 70 | port, addr, AdsCallDllFunction.ADSIGRP_SYM_RELEASEHND, 0, 71 | handleBuff.getUsedBytesCount(), handleBuff); 72 | 73 | if (err != 0) { 74 | System.out.println("Error: Release Handle: 0x" + 75 | Long.toHexString(err)); 76 | } else { 77 | System.out.println("Success: Release Handle!"); 78 | } 79 | 80 | // Remove the associating between the AMS NetId and the IP address of 81 | // our target system 82 | AdsCallDllFunction.adsDelLocalRoute(addr.getNetId()); 83 | 84 | // Close communication 85 | err = AdsCallDllFunction.adsPortCloseEx(port); 86 | if (err != 0) { 87 | System.out.println("Error: Close Communication: 0x" + 88 | Long.toHexString(err)); 89 | } 90 | 91 | try { 92 | System.in.read(); 93 | } catch (Exception e) { 94 | System.out.println("Error: Close program"); 95 | } 96 | } 97 | } -------------------------------------------------------------------------------- /samples/tcadsdll/02_AccessByVariableName/Main.java: -------------------------------------------------------------------------------- 1 | import de.beckhoff.jni.Convert; 2 | import de.beckhoff.jni.JNIByteBuffer; 3 | import de.beckhoff.jni.tcads.AdsCallDllFunction; 4 | import de.beckhoff.jni.tcads.AmsAddr; 5 | 6 | public class Main { 7 | public static void main(String[] args) { 8 | long err; 9 | AmsAddr addr = new AmsAddr(); 10 | JNIByteBuffer handleBuff = new JNIByteBuffer(Integer.SIZE / Byte.SIZE); 11 | JNIByteBuffer symbolBuff = 12 | new JNIByteBuffer(Convert.StringToByteArr("MAIN.PLCVar", true)); 13 | JNIByteBuffer dataBuff = new JNIByteBuffer(Integer.SIZE / Byte.SIZE); 14 | 15 | // Open communication 16 | AdsCallDllFunction.adsPortOpen(); 17 | err = AdsCallDllFunction.getLocalAddress(addr); 18 | addr.setPort(851); 19 | 20 | if (err != 0) { 21 | System.out.println("Error: Open communication: 0x" + 22 | Long.toHexString(err)); 23 | } else { 24 | System.out.println("Success: Open communication!"); 25 | } 26 | 27 | // Get handle by symbol name 28 | err = AdsCallDllFunction.adsSyncReadWriteReq( 29 | addr, AdsCallDllFunction.ADSIGRP_SYM_HNDBYNAME, 0x0, 30 | handleBuff.getUsedBytesCount(), handleBuff, 31 | symbolBuff.getUsedBytesCount(), symbolBuff); 32 | if (err != 0) { 33 | System.out.println("Error: Get handle: 0x" + Long.toHexString(err)); 34 | } else { 35 | System.out.println("Success: Get handle!"); 36 | } 37 | 38 | // Handle: byte[] to int 39 | int hdlBuffToInt = Convert.ByteArrToInt(handleBuff.getByteArray()); 40 | 41 | // Read value by handle 42 | err = AdsCallDllFunction.adsSyncReadReq( 43 | addr, AdsCallDllFunction.ADSIGRP_SYM_VALBYHND, hdlBuffToInt, 0x4, 44 | dataBuff); 45 | if (err != 0) { 46 | System.out.println("Error: Read by handle: 0x" + 47 | Long.toHexString(err)); 48 | } else { 49 | // Data: byte[] to int 50 | int intVal = Convert.ByteArrToInt(dataBuff.getByteArray()); 51 | System.out.println("Success: PLCVar value: " + intVal); 52 | } 53 | 54 | // Release handle 55 | err = AdsCallDllFunction.adsSyncWriteReq( 56 | addr, AdsCallDllFunction.ADSIGRP_SYM_RELEASEHND, 0, 57 | handleBuff.getUsedBytesCount(), handleBuff); 58 | 59 | if (err != 0) { 60 | System.out.println("Error: Release Handle: 0x" + 61 | Long.toHexString(err)); 62 | } else { 63 | System.out.println("Success: Release Handle!"); 64 | } 65 | 66 | // Close communication 67 | err = AdsCallDllFunction.adsPortClose(); 68 | if (err != 0) { 69 | System.out.println("Error: Close Communication: 0x" + 70 | Long.toHexString(err)); 71 | } 72 | 73 | try { 74 | System.in.read(); 75 | } catch (Exception e) { 76 | System.out.println("Error: Close program"); 77 | } 78 | } 79 | } -------------------------------------------------------------------------------- /samples/tcadsdll/03_AccessAnArray/Main.java: -------------------------------------------------------------------------------- 1 | import de.beckhoff.jni.Convert; 2 | import de.beckhoff.jni.JNIByteBuffer; 3 | import de.beckhoff.jni.tcads.AdsCallDllFunction; 4 | import de.beckhoff.jni.tcads.AmsAddr; 5 | 6 | public class Main { 7 | public static void main(String[] args) { 8 | long err; 9 | AmsAddr addr = new AmsAddr(); 10 | JNIByteBuffer dataBuff = new JNIByteBuffer(200); 11 | 12 | // Open communication 13 | AdsCallDllFunction.adsPortOpen(); 14 | err = AdsCallDllFunction.getLocalAddress(addr); 15 | addr.setPort(851); 16 | 17 | if (err != 0) { 18 | System.out.println("Error: Open communication: 0x" + 19 | Long.toHexString(err)); 20 | } else { 21 | System.out.println("Success: Open communication!"); 22 | } 23 | 24 | // Read value by IndexGroup and IndexOffset 25 | err = AdsCallDllFunction.adsSyncReadReq(addr, 26 | 0x4020, // Index Group 27 | 0x0, // Index Offset 28 | 200, dataBuff); 29 | if (err != 0) { 30 | System.out.println("Error: Read by handle: 0x" + 31 | Long.toHexString(err)); 32 | } else { 33 | for (int i = 0; i < dataBuff.getUsedBytesCount(); i = i + 2) { 34 | // PLC datatype int consists of two bytes. Get them. 35 | byte lowByte = dataBuff.getByteArray()[i]; 36 | byte highByte = dataBuff.getByteArray()[i + 1]; 37 | // Create new byte[]. Little endian! 38 | byte[] valBytes = {lowByte, highByte}; 39 | // Integer value: byte[] to int 40 | int valInt = Convert.ByteArrToShort(valBytes); 41 | System.out.println("Value of PLCVar[" + i / 2 + "]: " + valInt); 42 | } 43 | } 44 | 45 | // Close communication 46 | err = AdsCallDllFunction.adsPortClose(); 47 | if (err != 0) { 48 | System.out.println("Error: Close Communication: 0x" + 49 | Long.toHexString(err)); 50 | } 51 | 52 | try { 53 | System.in.read(); 54 | } catch (Exception e) { 55 | System.out.println("Error: Close program"); 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /samples/tcadsdll/04_TransmittingStructures/Main.java: -------------------------------------------------------------------------------- 1 | import de.beckhoff.jni.JNIByteBuffer; 2 | import de.beckhoff.jni.tcads.AdsCallDllFunction; 3 | import de.beckhoff.jni.tcads.AmsAddr; 4 | import java.nio.ByteBuffer; 5 | import java.nio.ByteOrder; 6 | 7 | public class Main { 8 | public static void main(String[] args) { 9 | long err; 10 | AmsAddr addr = new AmsAddr(); 11 | 12 | TransferObject transfer = new TransferObject(); // See additional class 13 | JNIByteBuffer dataBuff = new JNIByteBuffer(19); 14 | 15 | // Open communication 16 | AdsCallDllFunction.adsPortOpen(); 17 | err = AdsCallDllFunction.getLocalAddress(addr); 18 | addr.setPort(851); 19 | 20 | if (err != 0) { 21 | System.out.println("Error: Open communication: 0x" + 22 | Long.toHexString(err)); 23 | } else { 24 | System.out.println("Success: Open communication!"); 25 | } 26 | 27 | // Use JNIByteBuffer as a backing array for ByteBuffer 28 | ByteBuffer bb = ByteBuffer.wrap(dataBuff.getByteArray()); 29 | 30 | // Write elements to buffer. Little Endian! 31 | bb.order(ByteOrder.LITTLE_ENDIAN); 32 | 33 | bb.putShort(transfer.getShortVal()); 34 | bb.putInt(transfer.getIntVal()); 35 | bb.put(transfer.getByteVal()); 36 | bb.putDouble(transfer.getDoubleVal()); 37 | bb.putFloat(transfer.getFloatVal()); 38 | 39 | // Write struct to PLC 40 | err = AdsCallDllFunction.adsSyncWriteReq(addr, 41 | 0x4020, // Index Group 42 | 0x0, // Index Offset 43 | 19, dataBuff); 44 | if (err != 0) { 45 | System.out.println("Error: Write request: 0x" + 46 | Long.toHexString(err)); 47 | } else { 48 | System.out.println("Success: Write struct!"); 49 | } 50 | 51 | // Close communication 52 | err = AdsCallDllFunction.adsPortClose(); 53 | if (err != 0) { 54 | System.out.println("Error: Close Communication: 0x" + 55 | Long.toHexString(err)); 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /samples/tcadsdll/04_TransmittingStructures/TransferObject.java: -------------------------------------------------------------------------------- 1 | public class TransferObject { 2 | private short shortVal; 3 | private int intVal; 4 | private byte byteVal; 5 | private double doubleVal; 6 | private float floatVal; 7 | 8 | public TransferObject() { 9 | this.shortVal = Short.MAX_VALUE; 10 | this.intVal = Integer.MIN_VALUE; 11 | this.byteVal = 3; 12 | this.doubleVal = 4.1234; 13 | this.floatVal = 5.4321f; 14 | } 15 | 16 | public short getShortVal() { return shortVal; } 17 | public int getIntVal() { return intVal; } 18 | public byte getByteVal() { return byteVal; } 19 | public double getDoubleVal() { return doubleVal; } 20 | public float getFloatVal() { return floatVal; } 21 | } 22 | -------------------------------------------------------------------------------- /samples/tcadsdll/05_ReadingAVariableDeclaration/ValueString.java: -------------------------------------------------------------------------------- 1 | public class ValueString { 2 | private int value; 3 | private String label; 4 | 5 | ValueString(int value, String label) { 6 | this.value = value; 7 | this.label = label; 8 | } 9 | 10 | public int getValue() { return value; } 11 | 12 | public String getLabel() { return label; } 13 | } 14 | -------------------------------------------------------------------------------- /samples/tcadsdll/06_WriteFlagSynchronously/Main.java: -------------------------------------------------------------------------------- 1 | 2 | import de.beckhoff.jni.Convert; 3 | import de.beckhoff.jni.JNIByteBuffer; 4 | import de.beckhoff.jni.tcads.AdsCallDllFunction; 5 | import de.beckhoff.jni.tcads.AmsAddr; 6 | 7 | public class Main { 8 | public static void main(String[] args) { 9 | try { 10 | long err; 11 | AmsAddr addr = new AmsAddr(); 12 | 13 | // Open communication 14 | AdsCallDllFunction.adsPortOpen(); 15 | err = AdsCallDllFunction.getLocalAddress(addr); 16 | addr.setPort(851); 17 | 18 | if (err != 0) { 19 | System.out.println("Error: Open communication: 0x" + 20 | Long.toHexString(err)); 21 | } else { 22 | System.out.println("Success: Open communication!"); 23 | } 24 | 25 | // Specify IndexGroup, IndexOffset and write PLCVar 26 | err = AdsCallDllFunction.adsSyncWriteReq( 27 | addr, 28 | 0x4020, // Index Group 29 | 0x0, // Index Offset 30 | Integer.SIZE / Byte.SIZE, 31 | new JNIByteBuffer(Convert.IntToByteArr(1024))); 32 | if (err != 0) { 33 | System.out.println("Error: Write by address: 0x" + 34 | Long.toHexString(err)); 35 | } 36 | 37 | // Close communication 38 | err = AdsCallDllFunction.adsPortClose(); 39 | if (err != 0) { 40 | System.out.println("Error: Close Communication: 0x" + 41 | Long.toHexString(err)); 42 | } 43 | 44 | System.out.println("Press enter to continue.."); 45 | System.in.read(); 46 | } catch (Exception ex) { 47 | System.out.println(ex.getMessage()); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /samples/tcadsdll/07_ReadFlagSynchronously/Main.java: -------------------------------------------------------------------------------- 1 | import de.beckhoff.jni.JNIByteBuffer; 2 | import de.beckhoff.jni.tcads.AdsCallDllFunction; 3 | import de.beckhoff.jni.tcads.AmsAddr; 4 | import java.nio.ByteBuffer; 5 | import java.nio.ByteOrder; 6 | 7 | public class Main { 8 | public static void main(String[] args) { 9 | try { 10 | long err; 11 | AmsAddr addr = new AmsAddr(); 12 | JNIByteBuffer buff = new JNIByteBuffer(Integer.SIZE / Byte.SIZE); 13 | ByteBuffer bb = ByteBuffer.allocate(0); 14 | 15 | // Open communication 16 | AdsCallDllFunction.adsPortOpen(); 17 | err = AdsCallDllFunction.getLocalAddress(addr); 18 | addr.setPort(851); 19 | 20 | if (err != 0) { 21 | System.out.println("Error: Open communication: 0x" + 22 | Long.toHexString(err)); 23 | } else { 24 | System.out.println("Success: Open communication!"); 25 | } 26 | 27 | // Specify IndexGroup, IndexOffset and read PLCVar 28 | err = AdsCallDllFunction.adsSyncReadReq(addr, 29 | 0x4020, // Index Group 30 | 0x0, // Index Offset 31 | buff.getUsedBytesCount(), 32 | buff); 33 | if (err != 0) { 34 | System.out.println("Error: Read by address: 0x" + 35 | Long.toHexString(err)); 36 | } else { 37 | bb = ByteBuffer.wrap(buff.getByteArray()); 38 | bb.order(ByteOrder.LITTLE_ENDIAN); 39 | 40 | System.out.println("" + bb.getInt()); 41 | } 42 | 43 | // Close communication 44 | err = AdsCallDllFunction.adsPortClose(); 45 | if (err != 0) { 46 | System.out.println("Error: Close Communication: 0x" + 47 | Long.toHexString(err)); 48 | } 49 | 50 | System.out.println("Press enter to continue.."); 51 | System.in.read(); 52 | } catch (Exception ex) { 53 | System.out.println(ex.getMessage()); 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /samples/tcadsdll/08_ReleaseVariableHandle/Main.java: -------------------------------------------------------------------------------- 1 | import de.beckhoff.jni.Convert; 2 | import de.beckhoff.jni.JNIByteBuffer; 3 | import de.beckhoff.jni.tcads.AdsCallDllFunction; 4 | import de.beckhoff.jni.tcads.AmsAddr; 5 | 6 | public class Main { 7 | public static void main(String[] args) { 8 | long err; 9 | AmsAddr addr = new AmsAddr(); 10 | JNIByteBuffer symBuff; 11 | JNIByteBuffer handleBuff = new JNIByteBuffer(Integer.SIZE / Byte.SIZE); 12 | 13 | try { 14 | // Open communication 15 | AdsCallDllFunction.adsPortOpen(); 16 | err = AdsCallDllFunction.getLocalAddress(addr); 17 | addr.setPort(851); 18 | 19 | if (err != 0) { 20 | System.out.println("Error: Open communication: 0x" + 21 | Long.toHexString(err)); 22 | } else { 23 | System.out.println("Success: Open communication!"); 24 | } 25 | 26 | // Convert Symbol name to byte buffer 27 | symBuff = 28 | new JNIByteBuffer(Convert.StringToByteArr("MAIN.PLCVar", true)); 29 | 30 | // Get handle via symbol name 31 | err = AdsCallDllFunction.adsSyncReadWriteReq( 32 | addr, AdsCallDllFunction.ADSIGRP_SYM_HNDBYNAME, 0, 33 | handleBuff.getUsedBytesCount(), 34 | handleBuff, // buffer for getting handle 35 | symBuff.getUsedBytesCount(), 36 | symBuff); // buffer containing symbol name 37 | 38 | if (err != 0) { 39 | System.out.println("Error: Get Handle: 0x" + 40 | Long.toHexString(err)); 41 | } else { 42 | System.out.println("Success: Get Handle!"); 43 | } 44 | 45 | // Release handle 46 | err = AdsCallDllFunction.adsSyncWriteReq( 47 | addr, AdsCallDllFunction.ADSIGRP_SYM_RELEASEHND, 0, 48 | handleBuff.getUsedBytesCount(), handleBuff); 49 | 50 | if (err != 0) { 51 | System.out.println("Error: Release Handle: 0x" + 52 | Long.toHexString(err)); 53 | } else { 54 | System.out.println("Success: Handle removed!"); 55 | } 56 | 57 | // Close communication 58 | err = AdsCallDllFunction.adsPortClose(); 59 | if (err != 0) { 60 | System.out.println("Error: Close Communication: 0x" + 61 | Long.toHexString(err)); 62 | } 63 | 64 | System.out.println("Press enter to continue.."); 65 | System.in.read(); 66 | 67 | } catch (Exception ex) { 68 | System.out.println(ex.getMessage()); 69 | } 70 | } 71 | } -------------------------------------------------------------------------------- /samples/tcadsdll/09_EventDrivenReading/AdsListener.java: -------------------------------------------------------------------------------- 1 | import de.beckhoff.jni.Convert; 2 | import de.beckhoff.jni.tcads.AdsNotificationHeader; 3 | import de.beckhoff.jni.tcads.AmsAddr; 4 | import de.beckhoff.jni.tcads.CallbackListenerAdsState; 5 | import java.util.Date; 6 | 7 | public class AdsListener implements CallbackListenerAdsState { 8 | private final static long SPAN = 11644473600000L; 9 | 10 | // Callback function 11 | public void onEvent(AmsAddr addr, AdsNotificationHeader notification, 12 | long user) { 13 | // The PLC timestamp is coded in Windows FILETIME. 14 | // Nano secs since 01.01.1601. 15 | long dateInMillis = notification.getNTimeStamp(); 16 | 17 | // Date accepts milliseconds since 01.01.1970. 18 | // Convert to milliseconds and subtract span. 19 | Date notificationDate = new Date(dateInMillis / 10000 - SPAN); 20 | 21 | System.out.println("Value:\t\t" + 22 | Convert.ByteArrToInt(notification.getData())); 23 | System.out.println("Notification:\t" + notification.getHNotification()); 24 | System.out.println("Time:\t\t" + notificationDate.toString()); 25 | System.out.println("User:\t\t" + user); 26 | System.out.println("ServerNetID:\t" + addr.getNetIdString() + "\n"); 27 | } 28 | } -------------------------------------------------------------------------------- /samples/tcadsdll/09_EventDrivenReading/Main.java: -------------------------------------------------------------------------------- 1 | import de.beckhoff.jni.AdsConstants; 2 | import de.beckhoff.jni.JNILong; 3 | import de.beckhoff.jni.tcads.AdsCallDllFunction; 4 | import de.beckhoff.jni.tcads.AdsCallbackObject; 5 | import de.beckhoff.jni.tcads.AdsNotificationAttrib; 6 | import de.beckhoff.jni.tcads.AmsAddr; 7 | 8 | public class Main { 9 | public static void main(String[] args) { 10 | try { 11 | long err; 12 | AmsAddr addr = new AmsAddr(); 13 | JNILong notification = new JNILong(); 14 | 15 | // Open communication 16 | AdsCallDllFunction.adsPortOpen(); 17 | err = AdsCallDllFunction.getLocalAddress(addr); 18 | addr.setPort(851); 19 | 20 | if (err != 0) { 21 | System.out.println("Error: Open communication: 0x" + 22 | Long.toHexString(err)); 23 | } else { 24 | System.out.println("Success: Open communication!"); 25 | } 26 | 27 | // Specify attributes of the notificationRequest 28 | AdsNotificationAttrib attr = new AdsNotificationAttrib(); 29 | attr.setCbLength(Integer.SIZE / Byte.SIZE); 30 | attr.setNTransMode(AdsConstants.ADSTRANS_SERVERONCHA); 31 | attr.setDwChangeFilter(10000000); // 1 sec 32 | attr.setNMaxDelay(20000000); // 2 sec 33 | 34 | // Create and add listener 35 | AdsListener listener = new AdsListener(); 36 | AdsCallbackObject callObject = new AdsCallbackObject(); 37 | callObject.addListenerCallbackAdsState(listener); 38 | 39 | // Create notificationHandle 40 | err = AdsCallDllFunction.adsSyncAddDeviceNotificationReq( 41 | addr, 42 | 0x4020, // IndexGroup 43 | 0x0, // IndexOffset 44 | attr, // The defined AdsNotificationAttrib object 45 | 42, // Choose arbitrary number 46 | notification); 47 | if (err != 0) { 48 | System.out.println("Error: Add notification: 0x" + 49 | Long.toHexString(err)); 50 | } 51 | 52 | // Read as long as user does not press return 53 | System.out.println("Press enter to continue.."); 54 | System.in.read(); 55 | 56 | // Delete notificationHandle 57 | err = AdsCallDllFunction.adsSyncDelDeviceNotificationReq( 58 | addr, notification); 59 | if (err != 0) { 60 | System.out.println("Error: Remove notification with handle 0x" + 61 | Long.toHexString(notification.getLong()) + 62 | ": result was 0x" + Long.toHexString(err)); 63 | } 64 | 65 | // Delete listener 66 | callObject.removeListenerCallbackAdsState(listener); 67 | 68 | // Close communication 69 | err = AdsCallDllFunction.adsPortClose(); 70 | if (err != 0) { 71 | System.out.println("Error: Close Communication: 0x" + 72 | Long.toHexString(err)); 73 | } 74 | } catch (Exception ex) { 75 | System.out.println(ex.getMessage()); 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /samples/tcadsdll/11_EventDrivenDetectionOfSymbolTableChanges/AdsListener.java: -------------------------------------------------------------------------------- 1 | import de.beckhoff.jni.tcads.AdsNotificationHeader; 2 | import de.beckhoff.jni.tcads.AmsAddr; 3 | import de.beckhoff.jni.tcads.CallbackListenerAdsState; 4 | 5 | public class AdsListener implements CallbackListenerAdsState { 6 | // Callback function 7 | @Override 8 | public void onEvent(AmsAddr addr, AdsNotificationHeader notification, 9 | long user) { 10 | System.out.println("The symbol table has changed!"); 11 | } 12 | } -------------------------------------------------------------------------------- /samples/tcadsdll/11_EventDrivenDetectionOfSymbolTableChanges/Main.java: -------------------------------------------------------------------------------- 1 | import de.beckhoff.jni.AdsConstants; 2 | import de.beckhoff.jni.JNILong; 3 | import de.beckhoff.jni.tcads.AdsCallDllFunction; 4 | import de.beckhoff.jni.tcads.AdsCallbackObject; 5 | import de.beckhoff.jni.tcads.AdsNotificationAttrib; 6 | import de.beckhoff.jni.tcads.AmsAddr; 7 | 8 | public class Main { 9 | public static void main(String[] args) { 10 | long err = 0; 11 | AmsAddr addr = new AmsAddr(); 12 | 13 | try { 14 | // Open communication 15 | AdsCallDllFunction.adsPortOpen(); 16 | err = AdsCallDllFunction.getLocalAddress(addr); 17 | addr.setPort(851); 18 | 19 | if (err != 0) { 20 | System.out.println("Error: Open communication: 0x" + 21 | Long.toHexString(err)); 22 | } else { 23 | System.out.println("Success: Open communication!"); 24 | } 25 | 26 | JNILong notification = new JNILong(); 27 | 28 | AdsNotificationAttrib attr = new AdsNotificationAttrib(); 29 | attr.setCbLength(1); 30 | attr.setNTransMode(AdsConstants.ADSTRANS_SERVERONCHA); 31 | attr.setNMaxDelay(5000000); 32 | attr.setNCycleTime(5000000); 33 | 34 | // Create and add listener 35 | AdsListener listener = new AdsListener(); 36 | AdsCallbackObject callObject = new AdsCallbackObject(); 37 | callObject.addListenerCallbackAdsState(listener); 38 | 39 | err = AdsCallDllFunction.adsSyncAddDeviceNotificationReq( 40 | addr, 41 | AdsCallDllFunction.ADSIGRP_SYM_VERSION, // IndexGroup 42 | 0, // IndexOffset 43 | attr, // The defined AdsNotificationAttrib object 44 | 0, // Choose arbitrary number 45 | notification); 46 | if (err != 0) { 47 | System.out.println("Error: Add notification: 0x" + 48 | Long.toHexString(err)); 49 | } 50 | 51 | // Read as long as user does not press return 52 | System.out.println("Press enter to continue..\n"); 53 | System.in.read(); 54 | 55 | // Delete notificationHandle 56 | err = AdsCallDllFunction.adsSyncDelDeviceNotificationReq( 57 | addr, notification); 58 | 59 | if (err != 0) { 60 | System.out.println("Error: Remove notification with handle 0x" + 61 | Long.toHexString(notification.getLong()) + 62 | ": result was 0x" + Long.toHexString(err)); 63 | } 64 | 65 | // Delete listener 66 | callObject.removeListenerCallbackAdsState(listener); 67 | 68 | // Close communication 69 | err = AdsCallDllFunction.adsPortClose(); 70 | if (err != 0) { 71 | System.out.println("Error: Close Communication: 0x" + 72 | Long.toHexString(err)); 73 | } 74 | 75 | } catch (Exception ex) { 76 | System.out.println(ex.getMessage()); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /samples/tcadsdll/12_SumCommandReleaseVariableHandles/ReleaseData.java: -------------------------------------------------------------------------------- 1 | 2 | import java.nio.ByteBuffer; 3 | import java.nio.ByteOrder; 4 | 5 | public class ReleaseData { 6 | /** 7 | * the classes size in bits. 8 | */ 9 | public static final int SIZE = Integer.SIZE * 3; 10 | private int indexGroup; 11 | private int indexOffset; 12 | private int length; 13 | 14 | public ReleaseData() { 15 | this.indexGroup = 0; 16 | this.indexOffset = 0; 17 | this.length = 0; 18 | } 19 | 20 | public void setIndexGroup(int indexGroup) { this.indexGroup = indexGroup; } 21 | 22 | public int getIndexGroup() { return indexGroup; } 23 | 24 | public void setIndexOffset(int indexOffset) { 25 | this.indexOffset = indexOffset; 26 | } 27 | 28 | public int getIndexOffset() { return indexOffset; } 29 | 30 | public void setLength(int length) { this.length = length; } 31 | 32 | public int getLength() { return length; } 33 | 34 | public byte[] toByteArray() { 35 | ByteBuffer tempBuff = ByteBuffer.allocate(SIZE / 8); 36 | tempBuff.order(ByteOrder.LITTLE_ENDIAN); 37 | 38 | tempBuff.putInt(this.indexGroup); 39 | tempBuff.putInt(this.indexOffset); 40 | tempBuff.putInt(this.length); 41 | 42 | return tempBuff.array(); 43 | } 44 | } -------------------------------------------------------------------------------- /samples/tcadsdll/12_SumCommandReleaseVariableHandles/RequestData.java: -------------------------------------------------------------------------------- 1 | 2 | import java.nio.ByteBuffer; 3 | import java.nio.ByteOrder; 4 | 5 | public class RequestData { 6 | /** 7 | * the classes size in bits. 8 | */ 9 | public static final int SIZE = Integer.SIZE * 4; 10 | private int indexGroup; 11 | private int indexOffset; 12 | private int readLength; 13 | private int writeLength; 14 | 15 | public RequestData() { 16 | this.indexGroup = 0; 17 | this.indexOffset = 0; 18 | this.readLength = 0; 19 | this.writeLength = 0; 20 | } 21 | 22 | public void setIndexGroup(int indexGroup) { this.indexGroup = indexGroup; } 23 | 24 | public int getIndexGroup() { return indexGroup; } 25 | 26 | public void setIndexOffset(int indexOffset) { 27 | this.indexOffset = indexOffset; 28 | } 29 | 30 | public int getIndexOffset() { return indexOffset; } 31 | 32 | public void setReadLength(int readLength) { this.readLength = readLength; } 33 | 34 | public int getReadLength() { return readLength; } 35 | 36 | public void setWriteLength(int writeLength) { 37 | this.writeLength = writeLength; 38 | } 39 | 40 | public int getWriteLength() { return writeLength; } 41 | 42 | public byte[] toByteArray() { 43 | ByteBuffer tempBuff = ByteBuffer.allocate(SIZE / 8); 44 | tempBuff.order(ByteOrder.LITTLE_ENDIAN); 45 | 46 | tempBuff.putInt(this.indexGroup); 47 | tempBuff.putInt(this.indexOffset); 48 | tempBuff.putInt(this.readLength); 49 | tempBuff.putInt(this.writeLength); 50 | 51 | return tempBuff.array(); 52 | } 53 | } -------------------------------------------------------------------------------- /samples/tcadsdll/13_SumCommandReadingWritingVariables/RequestData.java: -------------------------------------------------------------------------------- 1 | 2 | import java.nio.ByteBuffer; 3 | import java.nio.ByteOrder; 4 | 5 | public class RequestData { 6 | /** 7 | * the classes size in bits. 8 | */ 9 | public static final int SIZE = Integer.SIZE * 3 / 8; 10 | private String varName; 11 | private int indexGroup; 12 | private int indexOffset; 13 | private int length; 14 | 15 | public RequestData(String varName, int indexGroup, int indexOffset, 16 | int length) { 17 | this.varName = varName; 18 | this.indexGroup = indexGroup; 19 | this.indexOffset = indexOffset; 20 | this.length = length; 21 | } 22 | 23 | public String getVarName() { return this.varName; } 24 | 25 | public int getLength() { return this.length; } 26 | 27 | public byte[] toByteArray() { 28 | ByteBuffer tempBuff = ByteBuffer.allocate(SIZE); 29 | tempBuff.order(ByteOrder.LITTLE_ENDIAN); 30 | 31 | tempBuff.putInt(this.indexGroup); 32 | tempBuff.putInt(this.indexOffset); 33 | tempBuff.putInt(this.length); 34 | 35 | return tempBuff.array(); 36 | } 37 | } -------------------------------------------------------------------------------- /src/main/java/de/beckhoff/jni/AdsConstants.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni; 2 | 3 | /** 4 | * This class contains constants determining at what time the 5 | * AdsSyncNotification-Events are fired. 6 | * 7 | * @author Beckhoff Automation 8 | */ 9 | public class AdsConstants { 10 | /** 11 | * The AdsSyncNotification-Event is not fired. 12 | */ 13 | public final static int ADSTRANS_NOTRANS = 0; 14 | /** 15 | * Client triggered cyclic AdsNotification event. 16 | */ 17 | public final static int ADSTRANS_CLIENTCYCLE = 1; 18 | /** 19 | * The AdsNotification event is fired when data changes triggered by the 20 | * client. 21 | */ 22 | public final static int ADSTRANS_CLIENT1REQ = 2; 23 | /** 24 | * The AdsNotification event is fired when data changes triggered by the 25 | * client. 26 | */ 27 | public final static int ADSTRANS_CLIENTONCHA = 28 | 2; // the alternative name for ADSTRANS_CLIENT1REQ 29 | /** 30 | * The AdsSyncNotification-Event is fired cyclically. 31 | */ 32 | public final static int ADSTRANS_SERVERCYCLE = 3; 33 | /** 34 | * The AdsSyncNotification-Event is fired when the data changes. 35 | */ 36 | public final static int ADSTRANS_SERVERONCHA = 4; 37 | 38 | /** 39 | * Private constructor to suppress instantiation. 40 | */ 41 | private AdsConstants() {} 42 | } -------------------------------------------------------------------------------- /src/main/java/de/beckhoff/jni/JNIBool.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JNIBool.java 3 | */ 4 | package de.beckhoff.jni; 5 | 6 | /** 7 | * This is a Boolean related data type which can be used as a buffer for JNI 8 | * calls. 9 | * 10 | * @author Beckhoff Automation 11 | */ 12 | public class JNIBool { 13 | /** 14 | * field containing the long. 15 | */ 16 | private boolean mBool; 17 | 18 | /** 19 | * Class constructor. 20 | */ 21 | public JNIBool() { this.mBool = false; } 22 | 23 | /** 24 | * Class constructor specifying the initially contained boolean. 25 | * @param lbool 26 | * the initial value of type boolean. 27 | */ 28 | public JNIBool(boolean lbool) { this.mBool = lbool; } 29 | 30 | /** 31 | * Setter for field mBool. 32 | * @param lbool 33 | * the boolean value to be set. 34 | */ 35 | public void setBool(boolean lbool) { this.mBool = lbool; } 36 | 37 | /** 38 | * Getter for field mLong. 39 | * @return 40 | * the current boolean value of field mBool. 41 | */ 42 | public boolean getBool() { return this.mBool; } 43 | } -------------------------------------------------------------------------------- /src/main/java/de/beckhoff/jni/JNILong.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JNILong.java 3 | */ 4 | package de.beckhoff.jni; 5 | 6 | /** 7 | * This is a Long related data type which can be used as a buffer for JNI 8 | * calls. 9 | * 10 | * @author Beckhoff Automation 11 | */ 12 | public class JNILong { 13 | /** 14 | * Long field containing the long. 15 | */ 16 | private long mLong; 17 | 18 | /** 19 | * Class constructor. 20 | */ 21 | public JNILong() { this.mLong = 0L; } 22 | 23 | /** 24 | * Class constructor specifying the initially contained long. 25 | * @param lLong 26 | * the initial value of type long. 27 | */ 28 | public JNILong(long lLong) { this.mLong = lLong; } 29 | 30 | /** 31 | * Setter for field mLong. 32 | * @param lLong 33 | * the long value to be set. 34 | */ 35 | public void setLong(long lLong) { this.mLong = lLong; } 36 | 37 | /** 38 | * Getter for field mLong. 39 | * @return 40 | * the current long value of field mLong. 41 | */ 42 | public long getLong() { return this.mLong; } 43 | } -------------------------------------------------------------------------------- /src/main/java/de/beckhoff/jni/tcads/AdsDevName.java: -------------------------------------------------------------------------------- 1 | /* 2 | * AdsDevName.java 3 | */ 4 | 5 | package de.beckhoff.jni.tcads; 6 | 7 | /** 8 | * This object contain information about the ADS Device Name. 9 | * 10 | * @author Beckhoff Automation 11 | */ 12 | public class AdsDevName { 13 | /** 14 | * String field containing the device name. 15 | */ 16 | private String mDevName; 17 | 18 | /** 19 | * Class constructor. 20 | */ 21 | public AdsDevName() { this.mDevName = ""; } 22 | 23 | /** 24 | * Class constructor specifying the initially contained device name. 25 | * @param lDevName 26 | * the initial device name of type String. 27 | */ 28 | public AdsDevName(String lDevName) { this.mDevName = lDevName; } 29 | 30 | /** 31 | * Setter for field device name. 32 | * @param lDevName 33 | * the String value to be set. 34 | */ 35 | public void setDevName(String lDevName) { this.mDevName = lDevName; } 36 | 37 | /** 38 | * Getter for field device name. 39 | * @return 40 | * the current String value of field device name. 41 | */ 42 | public String getDevName() { return this.mDevName; } 43 | } -------------------------------------------------------------------------------- /src/main/java/de/beckhoff/jni/tcads/AdsNotificationHeader.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.tcads; 2 | 3 | /** 4 | * This object contains information about the event. 5 | * 6 | * @author Beckhoff Automation 7 | */ 8 | public class AdsNotificationHeader { 9 | /** 10 | * Long field containing the handle for the notification. Is specified when 11 | * the notification is defined. 12 | */ 13 | private long mHNotification; 14 | /** 15 | * Long field containing the time stamp in Windows FILETIME format. 16 | */ 17 | private long mNTimeStamp; 18 | /** 19 | * Byte[] field containing the transferred data. 20 | */ 21 | private byte[] data; 22 | 23 | /** 24 | * Class constructor specifying the initial byte[] length 25 | * @param length 26 | * the int value to be set. 27 | */ 28 | public AdsNotificationHeader(int length) { 29 | this.mHNotification = 0; 30 | this.mNTimeStamp = 0; 31 | data = new byte[length]; 32 | } 33 | 34 | /** 35 | * Getter for field handle (long containing the handle for the 36 | * notification.) 37 | * @return 38 | * the current long value of the field handle. 39 | */ 40 | public long getHNotification() { return mHNotification; } 41 | 42 | /** 43 | * Getter for field time stamp (long containing the time stamp in Windows 44 | * FILETIME format). 45 | * @return 46 | * the current long value of the field time stamp. 47 | */ 48 | public long getNTimeStamp() { return mNTimeStamp; } 49 | 50 | /** 51 | * Getter for field data (byte[] field containing the transferred data). 52 | * @return 53 | * the current byte[] of the field data. 54 | */ 55 | public byte[] getData() { return this.data.clone(); } 56 | } -------------------------------------------------------------------------------- /src/main/java/de/beckhoff/jni/tcads/AdsState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * AdsState.java 3 | */ 4 | package de.beckhoff.jni.tcads; 5 | 6 | /** 7 | * This object contains information about the ADS State. 8 | * 9 | * @author Beckhoff Automation 10 | */ 11 | public class AdsState { 12 | /** 13 | * ADS state: Invalidated state. 14 | */ 15 | public static final short ADSSTATE_INVALID = 0; 16 | /** 17 | * ADS state: Idle state. 18 | */ 19 | public static final short ADSSTATE_IDLE = 1; 20 | /** 21 | * ADS state: Reset state. 22 | */ 23 | public static final short ADSSTATE_RESET = 2; 24 | /** 25 | * ADS state: Initialize state. 26 | */ 27 | public static final short ADSSTATE_INIT = 3; 28 | /** 29 | * ADS state: Start state. 30 | */ 31 | public static final short ADSSTATE_START = 4; 32 | /** 33 | * ADS state: Run state. 34 | */ 35 | public static final short ADSSTATE_RUN = 5; 36 | /** 37 | * ADS state: Stop state. 38 | */ 39 | public static final short ADSSTATE_STOP = 6; 40 | /** 41 | * ADS state: Save Configuration state. 42 | */ 43 | public static final short ADSSTATE_SAVECFG = 7; 44 | /** 45 | * ADS state: Load Configuration state. 46 | */ 47 | public static final short ADSSTATE_LOADCFG = 8; 48 | /** 49 | * ADS state: Power failure state. 50 | */ 51 | public static final short ADSSTATE_POWERFAILURE = 9; 52 | /** 53 | * ADS state: Power good state. 54 | */ 55 | public static final short ADSSTATE_POWERGOOD = 10; 56 | /** 57 | * ADS state: Error state state. 58 | */ 59 | public static final short ADSSTATE_ERROR = 11; 60 | /** 61 | * ADS state: Shutting down state. 62 | */ 63 | public static final short ADSSTATE_SHUTDOWN = 12; 64 | /** 65 | * ADS state: Suspend state. 66 | */ 67 | public static final short ADSSTATE_SUSPEND = 13; 68 | /** 69 | * ADS state: Resume state. 70 | */ 71 | public static final short ADSSTATE_RESUME = 14; 72 | 73 | /** 74 | * Short field containing the current ADS state. 75 | */ 76 | private short mState; 77 | 78 | /** 79 | * Class constructor. 80 | */ 81 | public AdsState() { this.mState = 0; } 82 | 83 | /** 84 | * Setter for field state. 85 | * @param lState 86 | * the short value to be set. 87 | */ 88 | public void setState(short lState) { mState = lState; } 89 | 90 | /** 91 | * Getter for field state. 92 | * @return 93 | * the current short value of field state. 94 | */ 95 | public short getState() { return mState; } 96 | } -------------------------------------------------------------------------------- /src/main/java/de/beckhoff/jni/tcads/AdsVersion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * AdsVersion.java 3 | */ 4 | package de.beckhoff.jni.tcads; 5 | 6 | /** 7 | * This object contains information about the ADS Version. 8 | * 9 | * @author Beckhoff Automation 10 | */ 11 | public class AdsVersion { 12 | /** 13 | * char field containing the current version number. 14 | */ 15 | private char mVersion; 16 | /** 17 | * char field containing the current revision. 18 | */ 19 | private char mRevision; 20 | /** 21 | * short field containing the current build number. 22 | */ 23 | private short mBuild; 24 | 25 | /** 26 | * Class constructor 27 | */ 28 | public AdsVersion() { 29 | this.mVersion = 0; 30 | this.mRevision = 0; 31 | this.mBuild = 0; 32 | } 33 | 34 | /** 35 | * Getter for field version number (char containing the current version 36 | * number). 37 | * @return 38 | * the current char value of field version number. 39 | */ 40 | public char getVersion() { return mVersion; } 41 | 42 | /** 43 | * Getter for field revision (char containing the current revision). 44 | * @return 45 | * the current char value of field revision. 46 | */ 47 | public char getRevision() { return mRevision; } 48 | 49 | /** 50 | * Getter for field build number (short containing the current build 51 | * number). 52 | * @return 53 | * the current short value of field build number. 54 | */ 55 | public short getBuild() { return mBuild; } 56 | } -------------------------------------------------------------------------------- /src/main/java/de/beckhoff/jni/tcads/AmsNetId.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.tcads; 2 | 3 | import java.util.Arrays; 4 | 5 | /** 6 | * This object contains an AMS Net ID. 7 | * 8 | * @author Beckhoff Automation 9 | */ 10 | public class AmsNetId { 11 | /** 12 | * char[] field containing the AmsNetID in char representation. 13 | */ 14 | private char[] mB; 15 | 16 | /** 17 | * Class constructor. 18 | */ 19 | public AmsNetId() { this.mB = new char[6]; } 20 | 21 | /** 22 | * Class copy constructor. 23 | * @param id 24 | * another AmsNetId object. 25 | */ 26 | public AmsNetId(AmsNetId id) { this.mB = id.mB.clone(); } 27 | 28 | /** 29 | * Class constructor specifying the initially contained byte[]. Note the 30 | * length of the byte[] has exactly to be 6. 31 | * @param bytes 32 | * the initial byte[]. 33 | * @exception IllegalArgumentException 34 | * this is thrown when bytes.length != 6 35 | */ 36 | public AmsNetId(char[] bytes) { setCharArr(bytes); } 37 | 38 | /** 39 | * Getter for field amsNetID (char[] containing the AmsNetID in char 40 | * representation). 41 | * @return 42 | * the current byte[] of field amsNetID. 43 | */ 44 | public char[] getCharArr() { return this.mB.clone(); } 45 | 46 | /** 47 | * Setter for field amsNetID (char[] containing the AmsNetID in char 48 | * representation). Note the length of the byte[] has exactly to be 6. 49 | * @param bytes 50 | * the byte[] to be set. 51 | * @exception IllegalArgumentException 52 | * this is thrown when bytes.length != 6 53 | */ 54 | public void setCharArr(char[] bytes) { 55 | if (bytes.length == 6) 56 | this.mB = bytes.clone(); 57 | else 58 | throw new IllegalArgumentException("Setting the AmsNetId failed."); 59 | } 60 | 61 | /** 62 | * Setter for individual array elements of the field amsNetID (char[] 63 | * containing the AmsNetID in char representation). 64 | * @param b 65 | * the byte to be set. 66 | * @param index 67 | * the index of the byte to be set. 68 | * @exception IllegalArgumentException 69 | * this is thrown when the index is not valid 70 | */ 71 | public void setChar(char b, int index) { 72 | if (index >= 0 && index < 6) 73 | this.mB[index] = b; 74 | else 75 | throw new IllegalArgumentException( 76 | "Setting part of the AmsNetId failed."); 77 | } 78 | 79 | @Override 80 | public final boolean equals(Object o) { 81 | if (o == this) { 82 | return true; 83 | } 84 | if (!(o instanceof AmsNetId)) { 85 | return false; 86 | } 87 | return Arrays.equals(this.mB, ((AmsNetId)o).mB); 88 | } 89 | 90 | @Override 91 | public final int hashCode() { 92 | return Arrays.hashCode(this.mB); 93 | } 94 | } -------------------------------------------------------------------------------- /src/main/java/de/beckhoff/jni/tcads/CallbackListenerAdsRouter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * CallbackListenerAdsRouter.java 3 | */ 4 | package de.beckhoff.jni.tcads; 5 | 6 | /** 7 | * Objects have to implement this interface to be addable to an 8 | * AdsCallbackObject as a router event listener. 9 | * 10 | * @author Beckhoff Automation 11 | */ 12 | public interface CallbackListenerAdsRouter { 13 | /** 14 | * If this is a declared listener to an event. The onEvent method in invoked 15 | * whenever the event occurs. 16 | * @param nReason 17 | * the long representing the reason for the event occurrence. 18 | */ 19 | public void onEvent(long nReason); 20 | } -------------------------------------------------------------------------------- /src/main/java/de/beckhoff/jni/tcads/CallbackListenerAdsState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * CallbackListenerAdsState.java 3 | */ 4 | package de.beckhoff.jni.tcads; 5 | 6 | /** 7 | * Objects have to implement this interface to be addable to an 8 | * AdsCallbackObject as an event listener. 9 | * 10 | * @author Beckhoff Automation 11 | */ 12 | public interface CallbackListenerAdsState { 13 | /** 14 | * If this is a declared listener to an event. The onEvent method in invoked 15 | * whenever the event occurs. 16 | * @param pAddr 17 | * de.beckhoff.jni.tcads.AmsAddr object with the port number and the 18 | * NetId of the ADS server. 19 | * @param pNotification 20 | * de.beckhoff.jni.tcads.AdsNotificationHeader object that contains 21 | * information about the cause of the event. 22 | * @param hUser 23 | * the events associated user. 24 | */ 25 | public void onEvent(AmsAddr pAddr, AdsNotificationHeader pNotification, 26 | long hUser); 27 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/convert/test/AllTests.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.convert.test; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * 9 | * @author Beckhoff Automation 10 | */ 11 | public class AllTests extends TestCase { 12 | public static void main(String[] args) { 13 | junit.textui.TestRunner.run(AllTests.class); 14 | } 15 | 16 | public static Test suite() { 17 | TestSuite suite = new TestSuite(); 18 | suite.addTestSuite(ConvertByteTest.class); 19 | suite.addTestSuite(ConvertShortTest.class); 20 | suite.addTestSuite(ConvertIntegerTest.class); 21 | suite.addTestSuite(ConvertLongTest.class); 22 | suite.addTestSuite(ConvertFloatTest.class); 23 | suite.addTestSuite(ConvertDoubleTest.class); 24 | suite.addTestSuite(ConvertBoolTest.class); 25 | suite.addTestSuite(ConvertCharTest.class); 26 | suite.addTestSuite(ConvertStringTest.class); 27 | suite.addTestSuite(ConvertExceptionTest.class); 28 | 29 | return suite; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/convert/test/ConvertBoolTest.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.convert.test; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import de.beckhoff.jni.Convert; 6 | import junit.framework.TestCase; 7 | 8 | /** 9 | * 10 | * @author Beckhoff Automation 11 | */ 12 | public class ConvertBoolTest extends TestCase { 13 | private byte[] minData; 14 | private boolean minRepresentation; 15 | private byte[] maxData; 16 | private boolean maxRepresentation; 17 | 18 | public ConvertBoolTest(String name) { super(name); } 19 | 20 | @Override 21 | protected void setUp() { 22 | minData = new byte[] {(byte)0x00}; 23 | minRepresentation = Boolean.FALSE; 24 | 25 | maxData = new byte[] {(byte)0x01}; 26 | maxRepresentation = Boolean.TRUE; 27 | } 28 | 29 | @Override 30 | protected void tearDown() {} 31 | 32 | public void testConversionFromArray() { 33 | assertEquals("Conversion to boolean (minimum)", minRepresentation, 34 | Convert.ByteArrToBool(minData)); 35 | 36 | assertEquals("Conversion to boolean (maximum)", maxRepresentation, 37 | Convert.ByteArrToBool(maxData)); 38 | } 39 | 40 | public void testConversionToArray() { 41 | byte[] convertedData = Convert.BoolToByteArr(minRepresentation); 42 | assertArrayEquals("Conversion to byte array (minimum)", minData, 43 | convertedData); 44 | 45 | convertedData = Convert.BoolToByteArr(maxRepresentation); 46 | assertArrayEquals("Conversion to byte array (maximum)", maxData, 47 | convertedData); 48 | } 49 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/convert/test/ConvertByteTest.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.convert.test; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import de.beckhoff.jni.Convert; 6 | import junit.framework.TestCase; 7 | 8 | /** 9 | * 10 | * @author Beckhoff Automation 11 | */ 12 | public class ConvertByteTest extends TestCase { 13 | private byte[] minData; 14 | private byte minRepresentation; 15 | private byte[] maxData; 16 | private byte maxRepresentation; 17 | 18 | public ConvertByteTest(String name) { super(name); } 19 | 20 | @Override 21 | protected void setUp() { 22 | minData = new byte[] {(byte)0x80}; 23 | minRepresentation = Byte.MIN_VALUE; 24 | 25 | maxData = new byte[] {(byte)0x7f}; 26 | maxRepresentation = Byte.MAX_VALUE; 27 | } 28 | 29 | @Override 30 | protected void tearDown() {} 31 | 32 | public void testConversionFromArray() { 33 | assertEquals("Conversion to byte (minimum)", minRepresentation, 34 | Convert.ByteArrToByte(minData)); 35 | 36 | assertEquals("Conversion to byte (maximum)", maxRepresentation, 37 | Convert.ByteArrToByte(maxData)); 38 | } 39 | 40 | public void testConversionToArray() { 41 | byte[] convertedData = Convert.ByteToByteArr(minRepresentation); 42 | assertArrayEquals("Conversion to byte array (minimal)", minData, 43 | convertedData); 44 | 45 | convertedData = Convert.ByteToByteArr(maxRepresentation); 46 | assertArrayEquals("Conversion to byte array (maximal)", maxData, 47 | convertedData); 48 | } 49 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/convert/test/ConvertCharTest.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.convert.test; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import de.beckhoff.jni.Convert; 6 | import junit.framework.TestCase; 7 | 8 | /** 9 | * 10 | * @author Beckhoff Automation 11 | */ 12 | public class ConvertCharTest extends TestCase { 13 | private byte[] minData; 14 | private char minRepresentation; 15 | private byte[] maxData; 16 | private char maxRepresentation; 17 | private byte[] minLowSurrogateData; 18 | private char minLowSurrogate; 19 | private byte[] minHighSurrogateData; 20 | private char minHighSurrogate; 21 | private byte[] maxLowSurrogateData; 22 | private char maxLowSurrogate; 23 | private byte[] maxHighSurrogateData; 24 | private char maxHighSurrogate; 25 | 26 | public ConvertCharTest(String name) { super(name); } 27 | 28 | @Override 29 | protected void setUp() { 30 | minData = new byte[] {0x00, 0x00}; 31 | minRepresentation = Character.MIN_VALUE; 32 | 33 | maxData = new byte[] {(byte)0xff, (byte)0xff}; 34 | maxRepresentation = Character.MAX_VALUE; 35 | 36 | minLowSurrogateData = new byte[] {(byte)0xdc, (byte)0x00}; 37 | minLowSurrogate = Character.MIN_LOW_SURROGATE; 38 | 39 | minHighSurrogateData = new byte[] {(byte)0xd8, (byte)0x00}; 40 | minHighSurrogate = Character.MIN_HIGH_SURROGATE; 41 | 42 | maxLowSurrogateData = new byte[] {(byte)0xdf, (byte)0xff}; 43 | maxLowSurrogate = Character.MAX_LOW_SURROGATE; 44 | 45 | maxHighSurrogateData = new byte[] {(byte)0xdb, (byte)0xff}; 46 | maxHighSurrogate = Character.MAX_HIGH_SURROGATE; 47 | } 48 | 49 | @Override 50 | protected void tearDown() {} 51 | 52 | public void testConversionFromArray() { 53 | assertEquals("Conversion to char (MIN_VALUE)", minRepresentation, 54 | Convert.ByteArrToChar(minData)); 55 | 56 | assertEquals("Conversion to char (MAX_VALUE)", maxRepresentation, 57 | Convert.ByteArrToChar(maxData)); 58 | 59 | assertEquals("Conversion to char (MIN_LOW_SURROGATE)", minLowSurrogate, 60 | Convert.ByteArrToChar(minLowSurrogateData)); 61 | 62 | assertEquals("Conversion to char (MIN_HIGH_SURROGATE)", 63 | minHighSurrogate, 64 | Convert.ByteArrToChar(minHighSurrogateData)); 65 | 66 | assertEquals("Conversion to char (MAX_LOW_SURROGATE)", maxLowSurrogate, 67 | Convert.ByteArrToChar(maxLowSurrogateData)); 68 | 69 | assertEquals("Conversion to char (MAX_HIGH_SURROGATE)", 70 | maxHighSurrogate, 71 | Convert.ByteArrToChar(maxHighSurrogateData)); 72 | } 73 | 74 | public void testConversionToArray() { 75 | assertEquals("This function is not implemented for this character size", 76 | Character.SIZE / 8, 2); 77 | 78 | byte[] convertedData = Convert.CharToByteArr(minRepresentation); 79 | assertArrayEquals("Conversion to byte (MIN_VALUE)", minData, 80 | convertedData); 81 | 82 | convertedData = Convert.CharToByteArr(maxRepresentation); 83 | assertArrayEquals("Conversion to byte (MAX_VALUE)", maxData, 84 | convertedData); 85 | 86 | convertedData = Convert.CharToByteArr(minLowSurrogate); 87 | assertArrayEquals("Conversion to byte (MIN_LOW_SURROGATE)", 88 | minLowSurrogateData, convertedData); 89 | 90 | convertedData = Convert.CharToByteArr(minHighSurrogate); 91 | assertArrayEquals("Conversion to byte (MIN_HIGH_SURROGATE)", 92 | minHighSurrogateData, convertedData); 93 | 94 | convertedData = Convert.CharToByteArr(maxLowSurrogate); 95 | assertArrayEquals("Conversion to byte (MAX_LOW_SURROGATE)", 96 | maxLowSurrogateData, convertedData); 97 | 98 | convertedData = Convert.CharToByteArr(maxHighSurrogate); 99 | assertArrayEquals("Conversion to byte (MAX_HIGH_SURROGATE)", 100 | maxHighSurrogateData, convertedData); 101 | } 102 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/convert/test/ConvertDoubleTest.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.convert.test; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import de.beckhoff.jni.AllTests; 6 | import de.beckhoff.jni.Convert; 7 | import junit.framework.TestCase; 8 | 9 | /** 10 | * 11 | * @author Beckhoff Automation 12 | */ 13 | public class ConvertDoubleTest extends TestCase { 14 | private byte[] minData; 15 | private double minRepresentation; 16 | private byte[] maxData; 17 | private double maxRepresentation; 18 | 19 | public ConvertDoubleTest(String name) { super(name); } 20 | 21 | @Override 22 | protected void setUp() { 23 | minData = new byte[] {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 24 | minRepresentation = Double.MIN_VALUE; 25 | 26 | maxData = new byte[] {(byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, 27 | (byte)0xff, (byte)0xff, (byte)0xef, 0x7f}; 28 | maxRepresentation = Double.MAX_VALUE; 29 | } 30 | 31 | @Override 32 | protected void tearDown() {} 33 | 34 | public void testConversionFromArray() { 35 | assertEquals("Conversion to double (minimum)", minRepresentation, 36 | Convert.ByteArrToDouble(minData), 37 | AllTests.FLOAT_COMPARE_DELTA); 38 | 39 | assertEquals("Conversion to double (maximum)", maxRepresentation, 40 | Convert.ByteArrToDouble(maxData), 41 | AllTests.FLOAT_COMPARE_DELTA); 42 | } 43 | 44 | public void testConversionToArray() { 45 | byte[] convertedData = Convert.DoubleToByteArr(minRepresentation); 46 | assertArrayEquals("Conversion to byte array (minimum)", minData, 47 | convertedData); 48 | 49 | convertedData = Convert.DoubleToByteArr(maxRepresentation); 50 | assertArrayEquals("Conversion to byte array (maximum)", maxData, 51 | convertedData); 52 | } 53 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/convert/test/ConvertExceptionTest.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.convert.test; 2 | 3 | import de.beckhoff.jni.Convert; 4 | import junit.framework.TestCase; 5 | 6 | /** 7 | * 8 | * @author Beckhoff Automation 9 | */ 10 | public class ConvertExceptionTest extends TestCase { 11 | byte[] data; 12 | 13 | public void testConversionByteArgumentException() { 14 | data = new byte[] {0x6f, 0x6f}; 15 | 16 | try { 17 | Convert.ByteArrToByte(data); 18 | fail("IllegalArgumentException"); 19 | } catch (IllegalArgumentException ex) { 20 | } 21 | } 22 | 23 | public void testConversionShortArgumentException() { 24 | data = new byte[] {0x6f, 0x6f, 0x6f}; 25 | 26 | try { 27 | Convert.ByteArrToShort(data); 28 | fail("IllegalArgumentException"); 29 | } catch (IllegalArgumentException ex) { 30 | } 31 | } 32 | 33 | public void testConversionIntegerArgumentException() { 34 | data = new byte[] {0x6f, 0x6f, 0x6f, 0x6f, 0x6f}; 35 | 36 | try { 37 | Convert.ByteArrToInt(data); 38 | fail("IllegalArgumentException"); 39 | } catch (IllegalArgumentException ex) { 40 | } 41 | } 42 | 43 | public void testConversionLongArgumentException() { 44 | data = 45 | new byte[] {0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f}; 46 | 47 | try { 48 | Convert.ByteArrToLong(data); 49 | fail("IllegalArgumentException"); 50 | } catch (IllegalArgumentException ex) { 51 | } 52 | } 53 | 54 | public void testConversionFloatArgumentException() { 55 | data = new byte[] {0x6f, 0x6f, 0x6f, 0x6f, 0x6f}; 56 | 57 | try { 58 | Convert.ByteArrToFloat(data); 59 | fail("IllegalArgumentException"); 60 | } catch (IllegalArgumentException ex) { 61 | } 62 | } 63 | 64 | public void testConversionDoubleArgumentException() { 65 | data = 66 | new byte[] {0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f}; 67 | 68 | try { 69 | Convert.ByteArrToDouble(data); 70 | fail("IllegalArgumentException"); 71 | } catch (IllegalArgumentException ex) { 72 | } 73 | } 74 | 75 | public void testConversionCharArgumentException() { 76 | data = new byte[] {0x6f, 0x6f, 0x6f}; 77 | 78 | try { 79 | Convert.ByteArrToChar(data); 80 | fail("IllegalArgumentException"); 81 | } catch (IllegalArgumentException ex) { 82 | } 83 | } 84 | 85 | public void testConversionBoolArgumentException() { 86 | data = new byte[] {0x6f, 0x6f}; 87 | 88 | try { 89 | Convert.ByteArrToBool(data); 90 | fail("IllegalArgumentException"); 91 | } catch (IllegalArgumentException ex) { 92 | } 93 | } 94 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/convert/test/ConvertFloatTest.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.convert.test; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import de.beckhoff.jni.AllTests; 6 | import de.beckhoff.jni.Convert; 7 | import junit.framework.TestCase; 8 | 9 | /** 10 | * 11 | * @author Beckhoff Automation 12 | */ 13 | public class ConvertFloatTest extends TestCase { 14 | private byte[] minData; 15 | private float minRepresentation; 16 | private byte[] maxData; 17 | private float maxRepresentation; 18 | 19 | public ConvertFloatTest(String name) { super(name); } 20 | 21 | @Override 22 | protected void setUp() { 23 | minData = new byte[] {0x01, 0x00, 0x00, 0x00}; 24 | minRepresentation = Float.MIN_VALUE; 25 | 26 | maxData = new byte[] {(byte)0xff, (byte)0xff, 0x7f, 0x7f}; 27 | maxRepresentation = Float.MAX_VALUE; 28 | } 29 | 30 | @Override 31 | protected void tearDown() {} 32 | 33 | public void testConversionFromArray() { 34 | assertEquals("Conversion to float (minimum)", minRepresentation, 35 | Convert.ByteArrToFloat(minData), 36 | AllTests.FLOAT_COMPARE_DELTA); 37 | 38 | assertEquals("Conversion to float (maximum)", maxRepresentation, 39 | Convert.ByteArrToFloat(maxData), 40 | AllTests.FLOAT_COMPARE_DELTA); 41 | } 42 | 43 | public void testConversionToArray() { 44 | byte[] convertedData = Convert.FloatToByteArr(minRepresentation); 45 | assertArrayEquals("Conversion to byte array (minimum)", minData, 46 | convertedData); 47 | 48 | convertedData = Convert.FloatToByteArr(maxRepresentation); 49 | assertArrayEquals("Conversion to byte array (maximum)", maxData, 50 | convertedData); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/convert/test/ConvertIntegerTest.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.convert.test; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import de.beckhoff.jni.Convert; 6 | import junit.framework.TestCase; 7 | 8 | /** 9 | * 10 | * @author Beckhoff Automation 11 | */ 12 | public class ConvertIntegerTest extends TestCase { 13 | private byte[] minData; 14 | private int minRepresentation; 15 | private byte[] maxData; 16 | private int maxRepresentation; 17 | 18 | public ConvertIntegerTest(String name) { super(name); } 19 | 20 | @Override 21 | protected void setUp() { 22 | minData = new byte[] {0x00, 0x00, 0x00, (byte)0x80}; 23 | minRepresentation = Integer.MIN_VALUE; 24 | 25 | maxData = new byte[] {(byte)0xff, (byte)0xff, (byte)0xff, 0x7f}; 26 | maxRepresentation = Integer.MAX_VALUE; 27 | } 28 | 29 | @Override 30 | protected void tearDown() {} 31 | 32 | public void testConversionFromArray() { 33 | assertEquals("Conversion to int (minimum)", minRepresentation, 34 | Convert.ByteArrToInt(minData)); 35 | 36 | assertEquals("Conversion to int (maximum)", maxRepresentation, 37 | Convert.ByteArrToInt(maxData)); 38 | } 39 | 40 | public void testConversionToArray() { 41 | byte[] convertedData = Convert.IntToByteArr(minRepresentation); 42 | assertArrayEquals("Conversion to byte array (minimum)", minData, 43 | convertedData); 44 | 45 | convertedData = Convert.IntToByteArr(maxRepresentation); 46 | assertArrayEquals("Conversion to byte array (maximum)", maxData, 47 | convertedData); 48 | } 49 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/convert/test/ConvertLongTest.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.convert.test; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import de.beckhoff.jni.Convert; 6 | import junit.framework.TestCase; 7 | 8 | /** 9 | * 10 | * @author Beckhoff Automation 11 | */ 12 | public class ConvertLongTest extends TestCase { 13 | private byte[] minData; 14 | private long minRepresentation; 15 | private byte[] maxData; 16 | private long maxRepresentation; 17 | 18 | public ConvertLongTest(String name) { super(name); } 19 | 20 | @Override 21 | protected void setUp() { 22 | minData = 23 | new byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte)0x80}; 24 | minRepresentation = Long.MIN_VALUE; 25 | 26 | maxData = new byte[] {(byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, 27 | (byte)0xff, (byte)0xff, (byte)0xff, 0x7f}; 28 | maxRepresentation = Long.MAX_VALUE; 29 | } 30 | 31 | @Override 32 | protected void tearDown() {} 33 | 34 | public void testConversionFromArray() { 35 | assertEquals("Conversion to long (minimum)", minRepresentation, 36 | Convert.ByteArrToLong(minData)); 37 | 38 | assertEquals("Conversion to long (maximum)", maxRepresentation, 39 | Convert.ByteArrToLong(maxData)); 40 | } 41 | 42 | public void testConversionToArray() { 43 | byte[] convertedData = Convert.LongToByteArr(minRepresentation); 44 | assertArrayEquals("Conversion to byte array (minimum)", minData, 45 | convertedData); 46 | 47 | convertedData = Convert.LongToByteArr(maxRepresentation); 48 | assertArrayEquals("Conversion to byte array (maximum)", maxData, 49 | convertedData); 50 | } 51 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/convert/test/ConvertShortTest.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.convert.test; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import de.beckhoff.jni.Convert; 6 | import junit.framework.TestCase; 7 | 8 | /** 9 | * 10 | * @author Beckhoff Automation 11 | */ 12 | public class ConvertShortTest extends TestCase { 13 | private byte[] minData; 14 | private short minRepresentation; 15 | private byte[] maxData; 16 | private short maxRepresentation; 17 | 18 | public ConvertShortTest(String name) { super(name); } 19 | 20 | @Override 21 | protected void setUp() { 22 | minData = new byte[] {0x00, (byte)0x80}; 23 | minRepresentation = Short.MIN_VALUE; 24 | 25 | maxData = new byte[] {(byte)0xff, 0x7f}; 26 | maxRepresentation = Short.MAX_VALUE; 27 | } 28 | 29 | @Override 30 | protected void tearDown() {} 31 | 32 | public void testConversionFromArray() { 33 | assertEquals("Conversion to short (minimum)", minRepresentation, 34 | Convert.ByteArrToShort(minData)); 35 | 36 | assertEquals("Conversion to short (maximum)", maxRepresentation, 37 | Convert.ByteArrToShort(maxData)); 38 | } 39 | 40 | public void testConversionToArray() { 41 | byte[] convertedData = Convert.ShortToByteArr(minRepresentation); 42 | assertArrayEquals("Conversion to byte array (minimum)", minData, 43 | convertedData); 44 | 45 | convertedData = Convert.ShortToByteArr(maxRepresentation); 46 | assertArrayEquals("Conversion to byte array (maximum)", maxData, 47 | convertedData); 48 | } 49 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/convert/test/ConvertStringTest.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.convert.test; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import de.beckhoff.jni.Convert; 6 | import junit.framework.TestCase; 7 | 8 | /** 9 | * 10 | * @author Beckhoff Automation 11 | */ 12 | public class ConvertStringTest extends TestCase { 13 | private final static byte[] DATA = new byte[] { 14 | 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x20, 0x54, 0x65, 0x73, 0x74}; 15 | private final static byte[] DATA_ZERO_BYTE = new byte[] { 16 | 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x20, 0x54, 0x65, 0x73, 0x74, 0x00}; 17 | private final static String REPRESENTATION = "String Test"; 18 | 19 | public ConvertStringTest(String name) { super(name); } 20 | 21 | @Override 22 | protected void setUp() {} 23 | 24 | @Override 25 | protected void tearDown() {} 26 | 27 | public void testConversionFromArray() { 28 | assertEquals("Conversion to String", REPRESENTATION, 29 | Convert.ByteArrToString(DATA)); 30 | assertEquals("Conversion to String with terminating zero byte", 31 | REPRESENTATION, Convert.ByteArrToString(DATA_ZERO_BYTE)); 32 | } 33 | 34 | public void testConversionToArray0() { 35 | byte[] convertedData = Convert.StringToByteArr("", true); 36 | assertArrayEquals("Conversion0 to byte array", new byte[] {0x00}, 37 | convertedData); 38 | } 39 | 40 | public void testConversionToArray1() { 41 | byte[] convertedData = Convert.StringToByteArr(REPRESENTATION); 42 | assertArrayEquals("Conversion1 to byte array", DATA, convertedData); 43 | } 44 | 45 | public void testConversionToArray2() { 46 | byte[] convertedData = Convert.StringToByteArr(REPRESENTATION, true); 47 | assertArrayEquals("Conversion2 to byte array", DATA_ZERO_BYTE, 48 | convertedData); 49 | } 50 | 51 | public void testConversionToArray3() { 52 | byte[] convertedData = Convert.StringToByteArr(REPRESENTATION, false); 53 | assertArrayEquals("Conversion3 to byte array", DATA, convertedData); 54 | } 55 | 56 | public void testConversionToArray4() { 57 | byte[] convertedData = 58 | Convert.StringToByteArr(REPRESENTATION, false, "xxx"); 59 | assertEquals("Conversion4 to byte array", 0, convertedData.length); 60 | } 61 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/jnibytebuffer/test/AllTests.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.jnibytebuffer.test; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * 9 | * @author Beckhoff Automation 10 | */ 11 | public class AllTests extends TestCase { 12 | public static void main(String[] args) { 13 | junit.textui.TestRunner.run(AllTests.class); 14 | } 15 | 16 | public static Test suite() { 17 | TestSuite suite = new TestSuite(); 18 | suite.addTestSuite(JNIByteBufferInitializationTest.class); 19 | suite.addTestSuite(JNIByteBufferInitializationExceptionTest.class); 20 | suite.addTestSuite(JNIByteBufferSetTest.class); 21 | 22 | return suite; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/jnibytebuffer/test/JNIByteBufferInitializationExceptionTest.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.jnibytebuffer.test; 2 | 3 | import de.beckhoff.jni.JNIByteBuffer; 4 | import junit.framework.TestCase; 5 | 6 | /** 7 | * 8 | * @author Beckhoff Automation 9 | */ 10 | public class JNIByteBufferInitializationExceptionTest extends TestCase { 11 | final static byte[] TEST_BYTE_ARR = new byte[] { 12 | 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x20, 0x54, 0x65, 0x73, 0x74, 0x00}; 13 | final static int TEST_BYTE_ARR_LEN = TEST_BYTE_ARR.length; 14 | final static int NEGATIVE_ARR_LEN = -4; 15 | 16 | public void testInitializationNegativeLength() { 17 | try { 18 | JNIByteBuffer byteBuffer = 19 | new JNIByteBuffer(TEST_BYTE_ARR, NEGATIVE_ARR_LEN, true); 20 | fail("IllegalArgumentException expected"); 21 | } catch (IllegalArgumentException ex) { 22 | } 23 | } 24 | 25 | public void testInitializationNullBuff() { 26 | try { 27 | JNIByteBuffer byteBuffer = 28 | new JNIByteBuffer(null, TEST_BYTE_ARR_LEN, true); 29 | fail("IllegalArgumentException expected"); 30 | } catch (IllegalArgumentException e) { 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/jnilong/test/AllTests.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.jnilong.test; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * 9 | * @author Beckhoff Automation 10 | */ 11 | public class AllTests extends TestCase { 12 | public static void main(String[] args) { 13 | junit.textui.TestRunner.run(AllTests.class); 14 | } 15 | 16 | public static Test suite() { 17 | TestSuite suite = new TestSuite(); 18 | suite.addTestSuite(JNILongTest.class); 19 | 20 | return suite; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/jnilong/test/JNILongTest.java: -------------------------------------------------------------------------------- 1 | 2 | package de.beckhoff.jni.jnilong.test; 3 | 4 | import de.beckhoff.jni.JNILong; 5 | import junit.framework.TestCase; 6 | 7 | /** 8 | * 9 | * @author Beckhoff Automation 10 | */ 11 | public class JNILongTest extends TestCase { 12 | static final long INIT_LONG = 12345678; 13 | static final long NEW_LONG = 87654321; 14 | private JNILong jniLong; 15 | 16 | public JNILongTest(String name) { super(name); } 17 | 18 | @Override 19 | protected void setUp() { 20 | jniLong = new JNILong(12345678); 21 | } 22 | 23 | @Override 24 | protected void tearDown() {} 25 | 26 | public void testInitialization() { 27 | assertEquals("Test initial long", INIT_LONG, jniLong.getLong()); 28 | } 29 | 30 | public void testSetLong() { 31 | jniLong.setLong(NEW_LONG); 32 | assertEquals("Test new long", NEW_LONG, jniLong.getLong()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/tcads/adscalldllfunction/test/AdsAmsPortEnabledTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package de.beckhoff.jni.tcads.adscalldllfunction.test; 7 | 8 | import de.beckhoff.jni.AllTests; 9 | import de.beckhoff.jni.JNIBool; 10 | import de.beckhoff.jni.tcads.AdsCallDllFunction; 11 | import de.beckhoff.jni.tcads.AmsAddr; 12 | import junit.framework.TestCase; 13 | 14 | /** 15 | * 16 | * @author Beckhoff Automation 17 | */ 18 | public class AdsAmsPortEnabledTest extends TestCase { 19 | private final static boolean PORT_OPEN = true; 20 | 21 | long port; 22 | long err; 23 | AmsAddr addr; 24 | JNIBool bool; 25 | 26 | public AdsAmsPortEnabledTest(String name) { super(name); } 27 | 28 | @Override 29 | protected void setUp() { 30 | err = 0; 31 | addr = new AmsAddr(); 32 | 33 | port = AdsCallDllFunction.adsPortOpen(); 34 | err = AdsCallDllFunction.getLocalAddress(addr); 35 | addr.setPort(AllTests.DEVICE_PORT); 36 | } 37 | 38 | @Override 39 | protected void tearDown() { 40 | AdsCallDllFunction.adsPortClose(); 41 | } 42 | 43 | public void testPortEnabled1() { 44 | if ((port >= AllTests.ADS_PORTNUMBER_MIN) & 45 | (port <= AllTests.ADS_PORTNUMBER_MAX) & (err == 0)) { 46 | if (AdsCallDllFunction.jniWrapperDllVersionNot1()) { 47 | bool = new JNIBool(); 48 | err = AdsCallDllFunction.adsAmsPortEnabled(bool); 49 | 50 | assertEquals("PortEnabled1 check error", 51 | AdsCallDllFunction.ADSERR_NO_ERR, err); 52 | 53 | assertEquals("PortEnabled1 check value", PORT_OPEN, 54 | bool.getBool()); 55 | } else { 56 | bool = new JNIBool(); 57 | err = AdsCallDllFunction.adsAmsPortEnabled(bool); 58 | 59 | assertEquals("PortEnabled1 check error (service not supported)", 60 | AdsCallDllFunction.ADSERR_SRVICE_NOT_SUPP, err); 61 | } 62 | } else { 63 | fail(); 64 | } 65 | } 66 | 67 | public void testPortEnabled2() { 68 | if ((port >= AllTests.ADS_PORTNUMBER_MIN) & 69 | (port <= AllTests.ADS_PORTNUMBER_MAX) & (err == 0)) { 70 | if (AdsCallDllFunction.jniWrapperDllVersionNot1()) { 71 | // Close the port 72 | err = AdsCallDllFunction.adsPortClose(); 73 | 74 | bool = new JNIBool(); 75 | err = AdsCallDllFunction.adsAmsPortEnabled(bool); 76 | 77 | assertEquals("PortEnabled2 check error", 78 | AdsCallDllFunction.ADSERR_ADSPORT_CLOSED, err); 79 | 80 | assertEquals("PortEnabled2 check value", !PORT_OPEN, 81 | bool.getBool()); 82 | } else { 83 | // Do no test since it's already covered above 84 | } 85 | } else { 86 | fail(); 87 | } 88 | } 89 | 90 | public void testPortEnabledLongNull() { 91 | if ((port >= AllTests.ADS_PORTNUMBER_MIN) & 92 | (port <= AllTests.ADS_PORTNUMBER_MAX) & (err == 0)) { 93 | bool = null; 94 | err = AdsCallDllFunction.adsAmsPortEnabled(bool); 95 | 96 | assertEquals("PortEnabled check error", 97 | AdsCallDllFunction.ADSERR_INV_PARAM_VALS2, err); 98 | } else { 99 | fail(); 100 | } 101 | } 102 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/tcads/adscalldllfunction/test/AllTests.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.tcads.adscalldllfunction.test; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * 9 | * @author Beckhoff Automation 10 | */ 11 | public class AllTests extends TestCase { 12 | public static void main(String[] args) { 13 | junit.textui.TestRunner.run(AllTests.class); 14 | } 15 | 16 | public static Test suite() { 17 | TestSuite suite = new TestSuite(); 18 | 19 | suite.addTestSuite(PortOpenCloseTest.class); 20 | suite.addTestSuite(GetLocalAmsAddressTest.class); 21 | suite.addTestSuite(ReadRequestTest.class); 22 | suite.addTestSuite(WriteRequestTest.class); 23 | suite.addTestSuite(WriteRequestArrayTest.class); 24 | suite.addTestSuite(ReadWriteRequestTest.class); 25 | suite.addTestSuite(ReadStateRequestTest.class); 26 | suite.addTestSuite(ReadDeviceInfoRequestTest.class); 27 | suite.addTestSuite(WriteControlRequestTest.class); 28 | suite.addTestSuite(GetSetTimeoutTest.class); 29 | suite.addTestSuite(DeviceNotificationTest.class); 30 | suite.addTestSuite(RouterNotificationTest.class); 31 | suite.addTestSuite(CallbackObjectTest.class); 32 | suite.addTestSuite(AdsAmsPortEnabledTest.class); 33 | suite.addTestSuite(FailPortOpenCloseTest.class); 34 | 35 | return suite; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/tcads/adscalldllfunction/test/FailPortOpenCloseTest.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.tcads.adscalldllfunction.test; 2 | 3 | import de.beckhoff.jni.tcads.AdsCallDllFunction; 4 | import junit.framework.TestCase; 5 | 6 | /** 7 | * 8 | * @author Beckhoff Automation 9 | */ 10 | public class FailPortOpenCloseTest extends TestCase { 11 | long port, err; 12 | 13 | public FailPortOpenCloseTest(String name) { super(name); } 14 | 15 | @Override 16 | protected void setUp() { 17 | port = 0; 18 | err = 0; 19 | } 20 | 21 | @Override 22 | protected void tearDown() {} 23 | 24 | public void testCloseWithoutOpen() { 25 | err = AdsCallDllFunction.adsPortClose(); 26 | assertEquals("Fail Ads PortClose (without prior PortOpen)", 27 | AdsCallDllFunction.ADSERR_ADSPORT_CLOSED, err); 28 | } 29 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/tcads/adscalldllfunction/test/GetLocalAmsAddressTest.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.tcads.adscalldllfunction.test; 2 | 3 | import de.beckhoff.jni.AllTests; 4 | import de.beckhoff.jni.tcads.AdsCallDllFunction; 5 | import de.beckhoff.jni.tcads.AmsAddr; 6 | import java.util.Arrays; 7 | import junit.framework.TestCase; 8 | 9 | /** 10 | * 11 | * @author Beckhoff Automation 12 | */ 13 | public class GetLocalAmsAddressTest extends TestCase { 14 | AmsAddr addr; 15 | long port, err; 16 | 17 | public GetLocalAmsAddressTest(String name) { super(name); } 18 | 19 | @Override 20 | protected void setUp() { 21 | addr = new AmsAddr(); 22 | err = 0; 23 | port = AdsCallDllFunction.adsPortOpen(); 24 | } 25 | 26 | @Override 27 | protected void tearDown() { 28 | AdsCallDllFunction.adsPortClose(); 29 | } 30 | 31 | public void testGetLocalAddress() { 32 | if ((port >= AllTests.ADS_PORTNUMBER_MIN) & 33 | (port <= AllTests.ADS_PORTNUMBER_MAX)) { 34 | err = AdsCallDllFunction.getLocalAddress(addr); 35 | 36 | assertEquals("Test GetLocalAmsAddr error value", 37 | AdsCallDllFunction.ADSERR_NO_ERR, err); 38 | 39 | String netId = addr.getNetIdString(); 40 | String[] parts = netId.split("\\."); 41 | assertEquals("Test number of parts of the AMS Net ID", 6, 42 | parts.length); 43 | assertFalse("127.0.0.1.1.1" == netId); 44 | assertFalse("0.0.0.0.1.1" == netId); 45 | assertFalse("0.0.0.0.0.0" == netId); 46 | } else { 47 | fail("ADS port out of range: " + Long.toString(port)); 48 | } 49 | } 50 | 51 | public void testGetLocalAddressPortClosed() { 52 | AdsCallDllFunction.adsPortClose(); 53 | 54 | err = AdsCallDllFunction.getLocalAddress(addr); 55 | assertEquals("Fail GetLocalAmsAddr (port is closed)", 56 | AdsCallDllFunction.ADSERR_ADSPORT_CLOSED, err); 57 | } 58 | 59 | public void testGetLocalAddressAddrNull() { 60 | if ((port >= AllTests.ADS_PORTNUMBER_MIN) & 61 | (port <= AllTests.ADS_PORTNUMBER_MAX)) { 62 | addr = null; 63 | 64 | err = AdsCallDllFunction.getLocalAddress(addr); 65 | assertEquals("Fail GetLocalAmsAddr (addr is null)", 66 | AdsCallDllFunction.ADSERR_INV_AMS_NETID, err); 67 | } else { 68 | fail("ADS port out of range: " + Long.toString(port)); 69 | } 70 | } 71 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/tcads/adscalldllfunction/test/GetSetTimeoutTest.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.tcads.adscalldllfunction.test; 2 | 3 | import de.beckhoff.jni.AllTests; 4 | import de.beckhoff.jni.JNIByteBuffer; 5 | import de.beckhoff.jni.JNILong; 6 | import de.beckhoff.jni.tcads.AdsCallDllFunction; 7 | import de.beckhoff.jni.tcads.AmsAddr; 8 | import junit.framework.TestCase; 9 | 10 | /** 11 | * 12 | * @author Beckhoff Automation 13 | */ 14 | public class GetSetTimeoutTest extends TestCase { 15 | static final long ADS_TIMEOUT_DEFAULT = 5000; 16 | static final long ADS_TIMEOUT_CHANGED = 2500; 17 | static final long ZERO_VAL = 0; 18 | 19 | AmsAddr addr; 20 | JNIByteBuffer buffer; 21 | JNILong timeout; 22 | long port, err; 23 | 24 | public GetSetTimeoutTest(String name) { super(name); } 25 | 26 | @Override 27 | protected void setUp() { 28 | err = 0; 29 | addr = new AmsAddr(); 30 | 31 | port = AdsCallDllFunction.adsPortOpen(); 32 | err = AdsCallDllFunction.getLocalAddress(addr); 33 | addr.setPort(AllTests.DEVICE_PORT); 34 | } 35 | 36 | @Override 37 | protected void tearDown() { 38 | AdsCallDllFunction.adsPortClose(); 39 | } 40 | 41 | public void testGetTimeout() { 42 | if ((port >= AllTests.ADS_PORTNUMBER_MIN) & 43 | (port <= AllTests.ADS_PORTNUMBER_MAX) & (err == 0)) { 44 | if (AdsCallDllFunction.jniWrapperDllVersionNot1()) { 45 | timeout = new JNILong(); 46 | err = AdsCallDllFunction.adsSyncGetTimeout(timeout); 47 | 48 | assertEquals("Test SetTimeout error value", 49 | AdsCallDllFunction.ADSERR_NO_ERR, err); 50 | 51 | assertEquals("Test GetTimeout timeout-value", 52 | ADS_TIMEOUT_DEFAULT, timeout.getLong()); 53 | } else { 54 | timeout = new JNILong(); 55 | err = AdsCallDllFunction.adsSyncGetTimeout(timeout); 56 | 57 | assertEquals( 58 | "Test SetTimeout error value (service not supported)", 59 | AdsCallDllFunction.ADSERR_SRVICE_NOT_SUPP, err); 60 | } 61 | } 62 | } 63 | 64 | public void testSetTimeout() { 65 | if ((port >= AllTests.ADS_PORTNUMBER_MIN) & 66 | (port <= AllTests.ADS_PORTNUMBER_MAX)) { 67 | if (AdsCallDllFunction.jniWrapperDllVersionNot1()) { 68 | err = AdsCallDllFunction.adsSyncSetTimeout(ADS_TIMEOUT_CHANGED); 69 | 70 | assertEquals("Test SetTimeout error value", 71 | AdsCallDllFunction.ADSERR_NO_ERR, err); 72 | 73 | timeout = new JNILong(); 74 | err = AdsCallDllFunction.adsSyncGetTimeout(timeout); 75 | 76 | assertEquals("Test GetTimeout timeout-value", 77 | ADS_TIMEOUT_CHANGED, timeout.getLong()); 78 | } else { 79 | // Do no test since it's already covered above 80 | } 81 | } else { 82 | fail("ADS port out of range: " + Long.toString(port)); 83 | } 84 | } 85 | 86 | public void testSetTimeoutBuffNull() { 87 | if ((port >= AllTests.ADS_PORTNUMBER_MIN) & 88 | (port <= AllTests.ADS_PORTNUMBER_MAX) & (err == 0)) { 89 | timeout = null; 90 | err = AdsCallDllFunction.adsSyncGetTimeout(timeout); 91 | 92 | assertEquals("SetTimeout buffer null error value", 93 | AdsCallDllFunction.ADSERR_INV_PARAM_VALS2, err); 94 | } else { 95 | fail(); 96 | } 97 | } 98 | 99 | public void testSetTimeoutInvTimeout() { 100 | if ((port >= AllTests.ADS_PORTNUMBER_MIN) & 101 | (port <= AllTests.ADS_PORTNUMBER_MAX)) { 102 | err = AdsCallDllFunction.adsSyncSetTimeout(0); 103 | 104 | assertEquals("Fail SetTimeout error value", 105 | AdsCallDllFunction.ADSERR_INV_CLIENT_TIMEOUT, err); 106 | } else { 107 | fail("ADS port out of range: " + Long.toString(port)); 108 | } 109 | } 110 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/tcads/adscalldllfunction/test/PortOpenCloseTest.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.tcads.adscalldllfunction.test; 2 | 3 | import de.beckhoff.jni.AllTests; 4 | import de.beckhoff.jni.tcads.AdsCallDllFunction; 5 | import junit.framework.TestCase; 6 | 7 | /** 8 | * 9 | * @author Beckhoff Automation 10 | */ 11 | public class PortOpenCloseTest extends TestCase { 12 | long port, err; 13 | 14 | public PortOpenCloseTest(String name) { super(name); } 15 | 16 | @Override 17 | protected void setUp() { 18 | port = 0; 19 | err = 0; 20 | } 21 | 22 | @Override 23 | protected void tearDown() {} 24 | 25 | public void testPortOpenClose() { 26 | port = AdsCallDllFunction.adsPortOpen(); 27 | assertTrue("Test Ads PortOpen", 28 | ((port >= AllTests.ADS_PORTNUMBER_MIN) & 29 | (port <= AllTests.ADS_PORTNUMBER_MAX))); 30 | 31 | err = AdsCallDllFunction.adsPortClose(); 32 | assertEquals("Test Ads PortClose", AdsCallDllFunction.ADSERR_NO_ERR, 33 | err); 34 | } 35 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/tcads/adscalldllfunction/test/ReadDeviceInfoRequestTest.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.tcads.adscalldllfunction.test; 2 | 3 | import de.beckhoff.jni.AllTests; 4 | import de.beckhoff.jni.JNIByteBuffer; 5 | import de.beckhoff.jni.tcads.AdsCallDllFunction; 6 | import de.beckhoff.jni.tcads.AdsDevName; 7 | import de.beckhoff.jni.tcads.AdsVersion; 8 | import de.beckhoff.jni.tcads.AmsAddr; 9 | import junit.framework.TestCase; 10 | 11 | /** 12 | * 13 | * @author Beckhoff Automation 14 | */ 15 | public class ReadDeviceInfoRequestTest extends TestCase { 16 | AmsAddr addr; 17 | JNIByteBuffer buffer; 18 | long port, err; 19 | 20 | AdsDevName deviceName; 21 | AdsVersion version; 22 | 23 | public ReadDeviceInfoRequestTest(String name) { super(name); } 24 | 25 | @Override 26 | protected void setUp() { 27 | err = 0; 28 | addr = new AmsAddr(); 29 | deviceName = new AdsDevName(); 30 | version = new AdsVersion(); 31 | 32 | port = AdsCallDllFunction.adsPortOpen(); 33 | addr.setNetIdStringEx(AllTests.DEVICE_AMSADDR); 34 | addr.setPort(AllTests.DEVICE_PORT); 35 | } 36 | 37 | @Override 38 | protected void tearDown() { 39 | AdsCallDllFunction.adsPortClose(); 40 | } 41 | 42 | public void testReadDeviceInfoRequest() { 43 | err = AdsCallDllFunction.adsSyncReadDeviceInfoReq(addr, deviceName, 44 | version); 45 | 46 | assertEquals("ReadDeviceInfoRequest test", 47 | AdsCallDllFunction.ADSERR_NO_ERR, err); 48 | 49 | assertEquals("ReadDeviceInfoRequest (DeviceName)", AllTests.DEVICE_NAME, 50 | deviceName.getDevName()); 51 | } 52 | 53 | public void tetsReadStateRequestAddrNull() { 54 | addr = null; 55 | err = AdsCallDllFunction.adsSyncReadDeviceInfoReq(addr, deviceName, 56 | version); 57 | 58 | assertEquals("ReadDeviceInfoRequest address null test", 59 | AdsCallDllFunction.ADSERR_INV_AMS_NETID, err); 60 | } 61 | 62 | public void testReadStateRequestAdsStateNull() { 63 | deviceName = null; 64 | err = AdsCallDllFunction.adsSyncReadDeviceInfoReq(addr, deviceName, 65 | version); 66 | 67 | assertEquals("ReadDeviceInfoRequest ads device name null", 68 | AdsCallDllFunction.ADSERR_INV_PARAM_VALS2, err); 69 | } 70 | 71 | public void testReadStateRequestDeviceStateNull() { 72 | version = null; 73 | err = AdsCallDllFunction.adsSyncReadDeviceInfoReq(addr, deviceName, 74 | version); 75 | 76 | assertEquals("ReadDeviceInfoRequest ads version null", 77 | AdsCallDllFunction.ADSERR_INV_PARAM_VALS2, err); 78 | } 79 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/tcads/adscalldllfunction/test/ReadStateRequestTest.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.tcads.adscalldllfunction.test; 2 | 3 | import de.beckhoff.jni.AllTests; 4 | import de.beckhoff.jni.JNIByteBuffer; 5 | import de.beckhoff.jni.tcads.AdsCallDllFunction; 6 | import de.beckhoff.jni.tcads.AdsState; 7 | import de.beckhoff.jni.tcads.AmsAddr; 8 | import junit.framework.TestCase; 9 | 10 | /** 11 | * 12 | * @author Beckhoff Automation 13 | */ 14 | public class ReadStateRequestTest extends TestCase { 15 | AmsAddr addr; 16 | JNIByteBuffer buffer; 17 | long port, err; 18 | 19 | private final int ZERO_VAL = 0; 20 | AdsState ads_state, device_state; 21 | 22 | public ReadStateRequestTest(String name) { super(name); } 23 | 24 | @Override 25 | protected void setUp() { 26 | err = 0; 27 | addr = new AmsAddr(); 28 | ads_state = new AdsState(); 29 | device_state = new AdsState(); 30 | 31 | port = AdsCallDllFunction.adsPortOpen(); 32 | addr.setNetIdStringEx(AllTests.DEVICE_AMSADDR); 33 | addr.setPort(AllTests.DEVICE_PORT); 34 | } 35 | 36 | @Override 37 | protected void tearDown() { 38 | AdsCallDllFunction.adsPortClose(); 39 | } 40 | 41 | public void testReadStateRequest() { 42 | err = AdsCallDllFunction.adsSyncReadStateReq(addr, ads_state, 43 | device_state); 44 | 45 | assertEquals("ReadStateRequest test", AdsCallDllFunction.ADSERR_NO_ERR, 46 | err); 47 | 48 | assertEquals("ReadStateRequest ads-state", AdsState.ADSSTATE_RUN, 49 | ads_state.getState()); 50 | 51 | assertEquals("ReadStateRequest ads-state", ZERO_VAL, 52 | device_state.getState()); 53 | } 54 | 55 | public void tetsReadStateRequestAddrNull() { 56 | addr = null; 57 | err = AdsCallDllFunction.adsSyncReadStateReq(addr, ads_state, 58 | device_state); 59 | 60 | assertEquals("ReadStateRequest address null test", 61 | AdsCallDllFunction.ADSERR_INV_AMS_NETID, err); 62 | } 63 | 64 | public void testReadStateRequestAdsStateNull() { 65 | ads_state = null; 66 | err = AdsCallDllFunction.adsSyncReadStateReq(addr, ads_state, 67 | device_state); 68 | 69 | assertEquals("ReadStateRequest ads state null", 70 | AdsCallDllFunction.ADSERR_INV_PARAM_VALS2, err); 71 | } 72 | 73 | public void testReadStateRequestDeviceStateNull() { 74 | ads_state = null; 75 | err = AdsCallDllFunction.adsSyncReadStateReq(addr, ads_state, 76 | device_state); 77 | 78 | assertEquals("ReadStateRequest device state null", 79 | AdsCallDllFunction.ADSERR_INV_PARAM_VALS2, err); 80 | } 81 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/tcads/adscalldllfunction/test/RouterNotificationTest.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.tcads.adscalldllfunction.test; 2 | 3 | import de.beckhoff.jni.AllTests; 4 | import de.beckhoff.jni.tcads.AdsCallDllFunction; 5 | import de.beckhoff.jni.tcads.AmsAddr; 6 | import junit.framework.TestCase; 7 | 8 | /** 9 | * 10 | * @author Beckhoff Automation 11 | */ 12 | public class RouterNotificationTest extends TestCase { 13 | AmsAddr addr; 14 | long port, err; 15 | 16 | public RouterNotificationTest(String name) { super(name); } 17 | 18 | @Override 19 | protected void setUp() { 20 | err = 0; 21 | addr = new AmsAddr(); 22 | 23 | port = AdsCallDllFunction.adsPortOpen(); 24 | err = AdsCallDllFunction.getLocalAddress(addr); 25 | addr.setPort(AllTests.DEVICE_PORT); 26 | } 27 | 28 | @Override 29 | protected void tearDown() { 30 | AdsCallDllFunction.adsPortClose(); 31 | } 32 | 33 | public void testAddDeleteRouterNotification() { 34 | if ((port >= AllTests.ADS_PORTNUMBER_MIN) & 35 | (port <= AllTests.ADS_PORTNUMBER_MAX)) { 36 | err = AdsCallDllFunction.adsAmsRegisterRouterNotification(); 37 | 38 | assertEquals("Test AddRouterNotification error value", 39 | AdsCallDllFunction.ADSERR_NO_ERR, err); 40 | 41 | err = AdsCallDllFunction.adsAmsUnRegisterRouterNotification(); 42 | 43 | assertEquals("Test DeleteRouterNotification error value (short)", 44 | AdsCallDllFunction.ADSERR_NO_ERR, err); 45 | } else { 46 | fail("ADS port out of range: " + Long.toString(port)); 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/tcads/adscalldllfunction/test/WriteControlRequestTest.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.tcads.adscalldllfunction.test; 2 | 3 | import de.beckhoff.jni.AllTests; 4 | import de.beckhoff.jni.JNIByteBuffer; 5 | import de.beckhoff.jni.tcads.AdsCallDllFunction; 6 | import de.beckhoff.jni.tcads.AdsState; 7 | import de.beckhoff.jni.tcads.AmsAddr; 8 | import junit.framework.TestCase; 9 | 10 | /** 11 | * 12 | * @author Beckhoff Automation 13 | */ 14 | public class WriteControlRequestTest extends TestCase { 15 | static final short RUN_STATE = AdsState.ADSSTATE_RUN; 16 | static final short STOP_STATE = AdsState.ADSSTATE_STOP; 17 | static final int ZERO_VAL = 0; 18 | 19 | AmsAddr addr; 20 | JNIByteBuffer buffer; 21 | long port, err; 22 | 23 | public WriteControlRequestTest(String name) { super(name); } 24 | 25 | @Override 26 | protected void setUp() { 27 | err = 0; 28 | buffer = new JNIByteBuffer(); 29 | addr = new AmsAddr(); 30 | 31 | port = AdsCallDllFunction.adsPortOpen(); 32 | addr.setNetIdStringEx(AllTests.DEVICE_AMSADDR); 33 | addr.setPort(AllTests.DEVICE_PORT); 34 | } 35 | 36 | @Override 37 | protected void tearDown() { 38 | // Restore initial device state and ads state 39 | err = AdsCallDllFunction.adsSyncWriteControlReq(addr, RUN_STATE, 40 | ZERO_VAL, port, buffer); 41 | 42 | AdsCallDllFunction.adsPortClose(); 43 | } 44 | 45 | public void testWriteControlRequest() { 46 | if ((port >= AllTests.ADS_PORTNUMBER_MIN) & 47 | (port <= AllTests.ADS_PORTNUMBER_MAX)) { 48 | err = AdsCallDllFunction.adsSyncWriteControlReq( 49 | addr, STOP_STATE, ZERO_VAL, buffer.getUsedBytesCount(), buffer); 50 | 51 | assertEquals("Test WriteControlRequest error value", 52 | AdsCallDllFunction.ADSERR_NO_ERR, err); 53 | 54 | AdsState adsState = new AdsState(); 55 | AdsState deviceState = new AdsState(); 56 | err = AdsCallDllFunction.adsSyncReadStateReq(addr, adsState, 57 | deviceState); 58 | 59 | assertEquals("Test WriteControlRequest check ads-state", STOP_STATE, 60 | adsState.getState()); 61 | } else { 62 | fail("ADS port out of range: " + Long.toString(port)); 63 | } 64 | } 65 | 66 | public void testWriteControlRequestInvalidState() { 67 | if ((port >= AllTests.ADS_PORTNUMBER_MIN) & 68 | (port <= AllTests.ADS_PORTNUMBER_MAX)) { 69 | // Setting the same state twice results in a invalid server state 70 | // error. 71 | err = AdsCallDllFunction.adsSyncWriteControlReq( 72 | addr, RUN_STATE, ZERO_VAL, buffer.getUsedBytesCount(), buffer); 73 | 74 | assertEquals("Fail WriteControlRequest error value", 75 | AdsCallDllFunction.ADSERR_INV_SERVER_STATE, err); 76 | } else { 77 | fail("ADS port out of range: " + Long.toString(port)); 78 | } 79 | } 80 | 81 | public void testWriteControlRequestAddrNull() { 82 | if ((port >= AllTests.ADS_PORTNUMBER_MIN) & 83 | (port <= AllTests.ADS_PORTNUMBER_MAX)) { 84 | addr = null; 85 | err = AdsCallDllFunction.adsSyncWriteControlReq( 86 | addr, AdsState.ADSSTATE_STOP, ZERO_VAL, 87 | buffer.getUsedBytesCount(), buffer); 88 | 89 | assertEquals("Fail WriteControlRequest error value (Address null)", 90 | AdsCallDllFunction.ADSERR_INV_AMS_NETID, err); 91 | } else { 92 | fail("ADS port out of range: " + Long.toString(port)); 93 | } 94 | } 95 | 96 | public void testWriteControlRequestBuffNull() { 97 | if ((port >= AllTests.ADS_PORTNUMBER_MIN) & 98 | (port <= AllTests.ADS_PORTNUMBER_MAX)) { 99 | buffer = null; 100 | err = AdsCallDllFunction.adsSyncWriteControlReq( 101 | addr, AdsState.ADSSTATE_STOP, ZERO_VAL, ZERO_VAL, buffer); 102 | 103 | assertEquals("Fail WriteControlRequest error value (Buffer null)", 104 | AdsCallDllFunction.ADSERR_INV_PARAM_VALS2, err); 105 | } else { 106 | fail("ADS port out of range: " + Long.toString(port)); 107 | } 108 | } 109 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/tcads/adscalldllfunctionex/test/AdsAmsPortEnabledExTest.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.tcads.adscalldllfunctionex.test; 2 | 3 | import de.beckhoff.jni.AllTests; 4 | import de.beckhoff.jni.JNIBool; 5 | import de.beckhoff.jni.tcads.AdsCallDllFunction; 6 | import de.beckhoff.jni.tcads.AmsAddr; 7 | import junit.framework.TestCase; 8 | 9 | /** 10 | * 11 | * @author Beckhoff Automation 12 | */ 13 | public class AdsAmsPortEnabledExTest extends TestCase { 14 | private final static boolean PORT_OPEN = true; 15 | 16 | long port; 17 | long err; 18 | AmsAddr addr; 19 | JNIBool bool; 20 | 21 | public AdsAmsPortEnabledExTest(String name) { super(name); } 22 | 23 | @Override 24 | protected void setUp() { 25 | err = 0; 26 | addr = new AmsAddr(); 27 | 28 | port = AdsCallDllFunction.adsPortOpenEx(); 29 | addr.setNetIdStringEx(AllTests.DEVICE_AMSADDR); 30 | addr.setPort(AllTests.DEVICE_PORT); 31 | } 32 | 33 | @Override 34 | protected void tearDown() { 35 | AdsCallDllFunction.adsPortCloseEx(port); 36 | } 37 | 38 | public void testPortEnabledEx1() { 39 | if ((port >= AllTests.ADS_PORTNUMBER_MIN) & 40 | (port <= AllTests.ADS_PORTNUMBER_MAX) & (err == 0)) { 41 | if (AdsCallDllFunction.jniWrapperDllVersionNot1()) { 42 | bool = new JNIBool(); 43 | err = AdsCallDllFunction.adsAmsPortEnabledEx(port, bool); 44 | 45 | assertEquals("PortEnabledEx1 check error", 46 | AdsCallDllFunction.ADSERR_NO_ERR, err); 47 | 48 | assertEquals("PortEnabledEx1 check value", PORT_OPEN, 49 | bool.getBool()); 50 | } else { 51 | bool = new JNIBool(); 52 | err = AdsCallDllFunction.adsAmsPortEnabledEx(port, bool); 53 | 54 | assertEquals( 55 | "PortEnabledEx1 check error (service not supported)", 56 | AdsCallDllFunction.ADSERR_SRVICE_NOT_SUPP, err); 57 | } 58 | } else { 59 | fail(); 60 | } 61 | } 62 | 63 | public void testPortEnabledEx2() { 64 | if ((port >= AllTests.ADS_PORTNUMBER_MIN) & 65 | (port <= AllTests.ADS_PORTNUMBER_MAX) & (err == 0)) { 66 | if (AdsCallDllFunction.jniWrapperDllVersionNot1()) { 67 | // Close the port 68 | err = AdsCallDllFunction.adsPortCloseEx(port); 69 | 70 | bool = new JNIBool(); 71 | err = AdsCallDllFunction.adsAmsPortEnabledEx(port, bool); 72 | 73 | assertEquals("PortEnabledEx2 check error", 74 | AdsCallDllFunction.ADSERR_ADSPORT_CLOSED, err); 75 | 76 | assertEquals("PortEnabledEx2 check value", !PORT_OPEN, 77 | bool.getBool()); 78 | } else { 79 | // Do no test since it's already covered above 80 | } 81 | } else { 82 | fail(); 83 | } 84 | } 85 | 86 | public void testPortEnabledExLongNull() { 87 | if ((port >= AllTests.ADS_PORTNUMBER_MIN) & 88 | (port <= AllTests.ADS_PORTNUMBER_MAX) & (err == 0)) { 89 | bool = null; 90 | err = AdsCallDllFunction.adsAmsPortEnabledEx(port, bool); 91 | 92 | assertEquals("PortEnabledEx check error", 93 | AdsCallDllFunction.ADSERR_INV_PARAM_VALS2, err); 94 | } else { 95 | fail(); 96 | } 97 | } 98 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/tcads/adscalldllfunctionex/test/AllTests.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.tcads.adscalldllfunctionex.test; 2 | 3 | import de.beckhoff.jni.tcads.AdsCallDllFunction; 4 | import junit.framework.Test; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * 9 | * @author Beckhoff Automation 10 | */ 11 | public class AllTests { 12 | public static void main(String[] args) { 13 | junit.textui.TestRunner.run(de.beckhoff.jni.AllTests.class); 14 | } 15 | 16 | public static Test suite() { 17 | TestSuite suite = new TestSuite(); 18 | 19 | if (AdsCallDllFunction.jniWrapperDllVersionNot1()) { 20 | suite.addTestSuite(AdsAmsPortEnabledExTest.class); 21 | suite.addTestSuite(DeviceNotificationRequestExTest.class); 22 | suite.addTestSuite(GetLocalAmsAddressExTest.class); 23 | suite.addTestSuite(GetSetTimeoutExTest.class); 24 | suite.addTestSuite(PortOpenCloseExTest.class); 25 | suite.addTestSuite(ReadDeviceInfoRequestExTest.class); 26 | suite.addTestSuite(ReadRequestEx2Test.class); 27 | suite.addTestSuite(ReadRequestExTest.class); 28 | suite.addTestSuite(ReadStateRequestExTest.class); 29 | suite.addTestSuite(ReadWriteRequestExTest.class); 30 | suite.addTestSuite(ReadWriteRequestEx2Test.class); 31 | suite.addTestSuite(WriteControlRequestExTest.class); 32 | suite.addTestSuite(WriteRequestExArrayTest.class); 33 | suite.addTestSuite(WriteRequestExTest.class); 34 | } 35 | 36 | return suite; 37 | } 38 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/tcads/adscalldllfunctionex/test/GetLocalAmsAddressExTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package de.beckhoff.jni.tcads.adscalldllfunctionex.test; 7 | 8 | import de.beckhoff.jni.AllTests; 9 | import de.beckhoff.jni.tcads.AdsCallDllFunction; 10 | import de.beckhoff.jni.tcads.AmsAddr; 11 | import java.util.Arrays; 12 | import junit.framework.TestCase; 13 | 14 | /** 15 | * 16 | * @author Beckhoff Automation 17 | */ 18 | public class GetLocalAmsAddressExTest extends TestCase { 19 | AmsAddr addr; 20 | long port, err; 21 | 22 | public GetLocalAmsAddressExTest(String name) { super(name); } 23 | 24 | @Override 25 | protected void setUp() { 26 | addr = new AmsAddr(); 27 | err = 0; 28 | port = AdsCallDllFunction.adsPortOpenEx(); 29 | } 30 | 31 | @Override 32 | protected void tearDown() { 33 | AdsCallDllFunction.adsPortCloseEx(port); 34 | } 35 | 36 | public void testGetLocalAddressEx() { 37 | if ((port >= AllTests.ADS_PORTNUMBER_MIN) & 38 | (port <= AllTests.ADS_PORTNUMBER_MAX)) { 39 | err = AdsCallDllFunction.getLocalAddressEx(port, addr); 40 | 41 | assertEquals("Test GetLocalAmsAddrEx error value", 42 | AdsCallDllFunction.ADSERR_NO_ERR, err); 43 | 44 | String netId = addr.getNetIdString(); 45 | String[] parts = netId.split("\\."); 46 | assertEquals("Test number of parts of the AMS Net ID", 6, 47 | parts.length); 48 | assertFalse("127.0.0.1.1.1" == netId); 49 | assertFalse("0.0.0.0.1.1" == netId); 50 | assertFalse("0.0.0.0.0.0" == netId); 51 | } else { 52 | fail("ADS port out of range: " + Long.toString(port)); 53 | } 54 | } 55 | 56 | public void testGetLocalAddressExPortClosed() { 57 | AdsCallDllFunction.adsPortCloseEx(port); 58 | 59 | err = AdsCallDllFunction.getLocalAddressEx(port, addr); 60 | assertEquals("Fail GetLocalAmsAddrEx (port is closed)", 61 | AdsCallDllFunction.ADSERR_ADSPORT_CLOSED, err); 62 | } 63 | 64 | public void testGetLocalAddressExAddrNull() { 65 | if ((port >= AllTests.ADS_PORTNUMBER_MIN) & 66 | (port <= AllTests.ADS_PORTNUMBER_MAX)) { 67 | addr = null; 68 | 69 | err = AdsCallDllFunction.getLocalAddressEx(port, addr); 70 | assertEquals("Fail GetLocalAmsAddrEx (addr is null)", 71 | AdsCallDllFunction.ADSERR_INV_AMS_NETID, err); 72 | } else { 73 | fail("ADS port out of range: " + Long.toString(port)); 74 | } 75 | } 76 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/tcads/adscalldllfunctionex/test/GetSetTimeoutExTest.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.tcads.adscalldllfunctionex.test; 2 | 3 | import de.beckhoff.jni.AllTests; 4 | import de.beckhoff.jni.JNIByteBuffer; 5 | import de.beckhoff.jni.JNILong; 6 | import de.beckhoff.jni.tcads.AdsCallDllFunction; 7 | import de.beckhoff.jni.tcads.AmsAddr; 8 | import junit.framework.TestCase; 9 | 10 | /** 11 | * 12 | * @author Beckhoff Automation 13 | */ 14 | public class GetSetTimeoutExTest extends TestCase { 15 | static final int ADS_TIMEOUT_DEFAULT = 5000; 16 | static final int ADS_TIMEOUT_CHANGED = 2500; 17 | static final int ZERO_VAL = 0; 18 | 19 | AmsAddr addr; 20 | JNIByteBuffer buffer; 21 | JNILong timeout; 22 | long port; 23 | long err; 24 | 25 | public GetSetTimeoutExTest(String name) { super(name); } 26 | 27 | @Override 28 | protected void setUp() { 29 | err = 0; 30 | addr = new AmsAddr(); 31 | 32 | port = AdsCallDllFunction.adsPortOpenEx(); 33 | addr.setNetIdStringEx(AllTests.DEVICE_AMSADDR); 34 | addr.setPort(AllTests.DEVICE_PORT); 35 | } 36 | 37 | @Override 38 | protected void tearDown() { 39 | AdsCallDllFunction.adsSyncSetTimeoutEx(port, ADS_TIMEOUT_CHANGED); 40 | 41 | AdsCallDllFunction.adsPortCloseEx(port); 42 | } 43 | 44 | public void testGetTimeoutEx() { 45 | if ((port >= AllTests.ADS_PORTNUMBER_MIN) & 46 | (port <= AllTests.ADS_PORTNUMBER_MAX) & (err == 0)) { 47 | timeout = new JNILong(); 48 | err = AdsCallDllFunction.adsSyncGetTimeoutEx(port, timeout); 49 | 50 | assertEquals("Test SetTimeoutEx error value", 51 | AdsCallDllFunction.ADSERR_NO_ERR, err); 52 | 53 | assertEquals("Test GetTimeoutEx timeout-value", ADS_TIMEOUT_DEFAULT, 54 | timeout.getLong()); 55 | } 56 | } 57 | 58 | public void testSetTimeoutEx() { 59 | if ((port >= AllTests.ADS_PORTNUMBER_MIN) & 60 | (port <= AllTests.ADS_PORTNUMBER_MAX) & (err == 0)) { 61 | err = AdsCallDllFunction.adsSyncSetTimeoutEx(port, 62 | ADS_TIMEOUT_CHANGED); 63 | 64 | assertEquals("Test SetTimeoutEx error value", 65 | AdsCallDllFunction.ADSERR_NO_ERR, err); 66 | 67 | timeout = new JNILong(); 68 | err = AdsCallDllFunction.adsSyncGetTimeoutEx(port, timeout); 69 | 70 | assertEquals("Test GetTimeoutEx timeout-value", ADS_TIMEOUT_CHANGED, 71 | timeout.getLong()); 72 | } else { 73 | fail(); 74 | } 75 | } 76 | 77 | public void testSetTimeoutExBuffNull() { 78 | if ((port >= AllTests.ADS_PORTNUMBER_MIN) & 79 | (port <= AllTests.ADS_PORTNUMBER_MAX) & (err == 0)) { 80 | timeout = null; 81 | err = AdsCallDllFunction.adsSyncGetTimeoutEx(port, timeout); 82 | 83 | assertEquals("SetTimeoutEx buffer null error value", 84 | AdsCallDllFunction.ADSERR_INV_PARAM_VALS2, err); 85 | } else { 86 | fail(); 87 | } 88 | } 89 | 90 | public void testSetTimeoutExInvTimeout() { 91 | if ((port >= AllTests.ADS_PORTNUMBER_MIN) & 92 | (port <= AllTests.ADS_PORTNUMBER_MAX) & (err == 0)) { 93 | err = AdsCallDllFunction.adsSyncSetTimeoutEx(port, 0); 94 | 95 | assertEquals("Fail SetTimeoutEx error value", 96 | AdsCallDllFunction.ADSERR_INV_CLIENT_TIMEOUT, err); 97 | } else { 98 | fail(); 99 | } 100 | } 101 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/tcads/adscalldllfunctionex/test/PortOpenCloseExTest.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.tcads.adscalldllfunctionex.test; 2 | 3 | import de.beckhoff.jni.AllTests; 4 | import de.beckhoff.jni.tcads.AdsCallDllFunction; 5 | import junit.framework.TestCase; 6 | 7 | /** 8 | * 9 | * @author Beckhoff Automation 10 | */ 11 | public class PortOpenCloseExTest extends TestCase { 12 | long port, err; 13 | 14 | public PortOpenCloseExTest(String name) { super(name); } 15 | 16 | @Override 17 | protected void setUp() { 18 | port = 0; 19 | err = 0; 20 | } 21 | 22 | @Override 23 | protected void tearDown() {} 24 | 25 | public void testPortOpenCloseEx() { 26 | port = AdsCallDllFunction.adsPortOpenEx(); 27 | assertTrue("Test Ads PortOpenEx", 28 | ((port >= AllTests.ADS_PORTNUMBER_MIN) & 29 | (port <= AllTests.ADS_PORTNUMBER_MAX))); 30 | 31 | err = AdsCallDllFunction.adsPortCloseEx(port); 32 | assertEquals("Test Ads PortCloseEx", AdsCallDllFunction.ADSERR_NO_ERR, 33 | err); 34 | } 35 | 36 | public void testPortCloseExInvalidPort() { 37 | err = 38 | AdsCallDllFunction.adsPortCloseEx(AllTests.ADS_PORTNUMBER_MAX + 1); 39 | 40 | assertEquals("Test Ads PortCloseEx invalid port err", 41 | AdsCallDllFunction.ADSERR_ADSPORT_CLOSED, err); 42 | } 43 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/tcads/adscalldllfunctionex/test/ReadDeviceInfoRequestExTest.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.tcads.adscalldllfunctionex.test; 2 | 3 | import de.beckhoff.jni.AllTests; 4 | import de.beckhoff.jni.JNIByteBuffer; 5 | import de.beckhoff.jni.tcads.AdsCallDllFunction; 6 | import de.beckhoff.jni.tcads.AdsDevName; 7 | import de.beckhoff.jni.tcads.AdsVersion; 8 | import de.beckhoff.jni.tcads.AmsAddr; 9 | import junit.framework.TestCase; 10 | 11 | /** 12 | * 13 | * @author Beckhoff Automation 14 | */ 15 | public class ReadDeviceInfoRequestExTest extends TestCase { 16 | AmsAddr addr; 17 | JNIByteBuffer buffer; 18 | long port, err; 19 | 20 | AdsDevName deviceName; 21 | AdsVersion version; 22 | 23 | public ReadDeviceInfoRequestExTest(String name) { super(name); } 24 | 25 | @Override 26 | protected void setUp() { 27 | err = 0; 28 | addr = new AmsAddr(); 29 | deviceName = new AdsDevName(); 30 | version = new AdsVersion(); 31 | 32 | port = AdsCallDllFunction.adsPortOpenEx(); 33 | addr.setNetIdStringEx(AllTests.DEVICE_AMSADDR); 34 | addr.setPort(AllTests.DEVICE_PORT); 35 | } 36 | 37 | @Override 38 | protected void tearDown() { 39 | AdsCallDllFunction.adsPortCloseEx(port); 40 | } 41 | 42 | public void testReadDeviceInfoRequestEx() { 43 | err = AdsCallDllFunction.adsSyncReadDeviceInfoReqEx( 44 | port, addr, deviceName, version); 45 | 46 | assertEquals("ReadDeviceInfoRequestEx test", 47 | AdsCallDllFunction.ADSERR_NO_ERR, err); 48 | 49 | assertEquals("ReadDeviceInfoRequestEx (DeviceName)", 50 | AllTests.DEVICE_NAME, deviceName.getDevName()); 51 | } 52 | 53 | public void tetsReadStateRequestExAddrNull() { 54 | addr = null; 55 | err = AdsCallDllFunction.adsSyncReadDeviceInfoReqEx( 56 | port, addr, deviceName, version); 57 | 58 | assertEquals("ReadDeviceInfoRequestEx address null test", 59 | AdsCallDllFunction.ADSERR_INV_AMS_NETID, err); 60 | } 61 | 62 | public void testReadStateRequestExAdsStateNull() { 63 | deviceName = null; 64 | err = AdsCallDllFunction.adsSyncReadDeviceInfoReqEx( 65 | port, addr, deviceName, version); 66 | 67 | assertEquals("ReadDeviceInfoRequestEx ads device name null", 68 | AdsCallDllFunction.ADSERR_INV_PARAM_VALS2, err); 69 | } 70 | 71 | public void testReadStateRequestExDeviceStateNull() { 72 | version = null; 73 | err = AdsCallDllFunction.adsSyncReadDeviceInfoReqEx( 74 | port, addr, deviceName, version); 75 | 76 | assertEquals("ReadDeviceInfoRequestEx ads version null", 77 | AdsCallDllFunction.ADSERR_INV_PARAM_VALS2, err); 78 | } 79 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/tcads/adscalldllfunctionex/test/ReadStateRequestExTest.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.tcads.adscalldllfunctionex.test; 2 | 3 | import de.beckhoff.jni.AllTests; 4 | import de.beckhoff.jni.JNIByteBuffer; 5 | import de.beckhoff.jni.tcads.AdsCallDllFunction; 6 | import de.beckhoff.jni.tcads.AdsState; 7 | import de.beckhoff.jni.tcads.AmsAddr; 8 | import junit.framework.TestCase; 9 | 10 | /** 11 | * 12 | * @author Beckhoff Automation 13 | */ 14 | public class ReadStateRequestExTest extends TestCase { 15 | AmsAddr addr; 16 | JNIByteBuffer buffer; 17 | long port, err; 18 | 19 | private final int ZERO_VAL = 0; 20 | AdsState ads_state, device_state; 21 | 22 | public ReadStateRequestExTest(String name) { super(name); } 23 | 24 | @Override 25 | protected void setUp() { 26 | err = 0; 27 | addr = new AmsAddr(); 28 | ads_state = new AdsState(); 29 | device_state = new AdsState(); 30 | 31 | port = AdsCallDllFunction.adsPortOpenEx(); 32 | addr.setNetIdStringEx(AllTests.DEVICE_AMSADDR); 33 | addr.setPort(AllTests.DEVICE_PORT); 34 | } 35 | 36 | @Override 37 | protected void tearDown() { 38 | AdsCallDllFunction.adsPortCloseEx(port); 39 | } 40 | 41 | public void testReadStateRequestEx() { 42 | err = AdsCallDllFunction.adsSyncReadStateReqEx(port, addr, ads_state, 43 | device_state); 44 | 45 | assertEquals("ReadStateRequestEx test", 46 | AdsCallDllFunction.ADSERR_NO_ERR, err); 47 | 48 | assertEquals("ReadStateRequestEx ads-state", AdsState.ADSSTATE_RUN, 49 | ads_state.getState()); 50 | 51 | assertEquals("ReadStateRequestEx ads-state", ZERO_VAL, 52 | device_state.getState()); 53 | } 54 | 55 | public void tetsReadStateRequestExAddrNull() { 56 | addr = null; 57 | err = AdsCallDllFunction.adsSyncReadStateReqEx(port, addr, ads_state, 58 | device_state); 59 | 60 | assertEquals("ReadStateRequestEx address null test", 61 | AdsCallDllFunction.ADSERR_INV_AMS_NETID, err); 62 | } 63 | 64 | public void testReadStateRequestExAdsStateNull() { 65 | ads_state = null; 66 | err = AdsCallDllFunction.adsSyncReadStateReqEx(port, addr, ads_state, 67 | device_state); 68 | 69 | assertEquals("ReadStateRequestEx ads state null", 70 | AdsCallDllFunction.ADSERR_INV_PARAM_VALS2, err); 71 | } 72 | 73 | public void testReadStateRequestExDeviceStateNull() { 74 | ads_state = null; 75 | err = AdsCallDllFunction.adsSyncReadStateReqEx(port, addr, ads_state, 76 | device_state); 77 | 78 | assertEquals("ReadStateRequestEx device state null", 79 | AdsCallDllFunction.ADSERR_INV_PARAM_VALS2, err); 80 | } 81 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/tcads/adscalldllfunctionex/test/WriteControlRequestExTest.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.tcads.adscalldllfunctionex.test; 2 | 3 | import de.beckhoff.jni.AllTests; 4 | import de.beckhoff.jni.JNIByteBuffer; 5 | import de.beckhoff.jni.tcads.AdsCallDllFunction; 6 | import de.beckhoff.jni.tcads.AdsState; 7 | import de.beckhoff.jni.tcads.AmsAddr; 8 | import junit.framework.TestCase; 9 | 10 | /** 11 | * 12 | * @author Beckhoff Automation 13 | */ 14 | public class WriteControlRequestExTest extends TestCase { 15 | static final short RUN_STATE = AdsState.ADSSTATE_RUN; 16 | static final short STOP_STATE = AdsState.ADSSTATE_STOP; 17 | static final int ZERO_VAL = 0; 18 | 19 | AmsAddr addr; 20 | JNIByteBuffer buffer; 21 | long port, err; 22 | 23 | public WriteControlRequestExTest(String name) { super(name); } 24 | 25 | @Override 26 | protected void setUp() { 27 | err = 0; 28 | buffer = new JNIByteBuffer(); 29 | addr = new AmsAddr(); 30 | 31 | port = AdsCallDllFunction.adsPortOpenEx(); 32 | addr.setNetIdStringEx(AllTests.DEVICE_AMSADDR); 33 | addr.setPort(AllTests.DEVICE_PORT); 34 | } 35 | 36 | @Override 37 | protected void tearDown() { 38 | // Restore initial device state and ads state 39 | err = AdsCallDllFunction.adsSyncWriteControlReqEx( 40 | port, addr, RUN_STATE, ZERO_VAL, port, buffer); 41 | 42 | AdsCallDllFunction.adsPortCloseEx(port); 43 | } 44 | 45 | public void testWriteControlRequestEx() { 46 | if ((port >= AllTests.ADS_PORTNUMBER_MIN) & 47 | (port <= AllTests.ADS_PORTNUMBER_MAX) & (err == 0)) { 48 | err = AdsCallDllFunction.adsSyncWriteControlReqEx( 49 | port, addr, STOP_STATE, ZERO_VAL, buffer.getUsedBytesCount(), 50 | buffer); 51 | 52 | assertEquals("Test WriteControlRequestEx error value", 53 | AdsCallDllFunction.ADSERR_NO_ERR, err); 54 | 55 | AdsState adsState = new AdsState(); 56 | AdsState deviceState = new AdsState(); 57 | err = AdsCallDllFunction.adsSyncReadStateReqEx(port, addr, adsState, 58 | deviceState); 59 | 60 | assertEquals("Test WriteControlRequestEx check ads-state", 61 | STOP_STATE, adsState.getState()); 62 | } else { 63 | fail(); 64 | } 65 | } 66 | 67 | public void testWriteControlRequestExInvalidState() { 68 | if ((port >= AllTests.ADS_PORTNUMBER_MIN) & 69 | (port <= AllTests.ADS_PORTNUMBER_MAX) & (err == 0)) { 70 | // Setting the same state twice results in a invalid server state 71 | // error. 72 | err = AdsCallDllFunction.adsSyncWriteControlReqEx( 73 | port, addr, RUN_STATE, ZERO_VAL, buffer.getUsedBytesCount(), 74 | buffer); 75 | 76 | assertEquals("Fail WriteControlRequestEx error value", 77 | AdsCallDllFunction.ADSERR_INV_SERVER_STATE, err); 78 | } else { 79 | fail(); 80 | } 81 | } 82 | 83 | public void testWriteControlRequestExAddrNull() { 84 | if ((port >= AllTests.ADS_PORTNUMBER_MIN) & 85 | (port <= AllTests.ADS_PORTNUMBER_MAX) & (err == 0)) { 86 | addr = null; 87 | err = AdsCallDllFunction.adsSyncWriteControlReqEx( 88 | port, addr, AdsState.ADSSTATE_STOP, ZERO_VAL, 89 | buffer.getUsedBytesCount(), buffer); 90 | 91 | assertEquals( 92 | "Fail WriteControlRequestEx error value (Address null)", 93 | AdsCallDllFunction.ADSERR_INV_AMS_NETID, err); 94 | } else { 95 | fail(); 96 | } 97 | } 98 | 99 | public void testWriteControlRequestExBuffNull() { 100 | if ((port >= AllTests.ADS_PORTNUMBER_MIN) & 101 | (port <= AllTests.ADS_PORTNUMBER_MAX) & (err == 0)) { 102 | buffer = null; 103 | err = AdsCallDllFunction.adsSyncWriteControlReqEx( 104 | port, addr, AdsState.ADSSTATE_STOP, ZERO_VAL, ZERO_VAL, buffer); 105 | 106 | assertEquals("Fail WriteControlRequestEx error value (Buffer null)", 107 | AdsCallDllFunction.ADSERR_INV_PARAM_VALS2, err); 108 | } else { 109 | fail(); 110 | } 111 | } 112 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/tcads/adsdevicename/test/AdsDevNameTest.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.tcads.adsdevicename.test; 2 | 3 | import de.beckhoff.jni.AllTests; 4 | import de.beckhoff.jni.tcads.AdsDevName; 5 | import junit.framework.TestCase; 6 | 7 | /** 8 | * 9 | * @author Beckhoff Automation 10 | */ 11 | public class AdsDevNameTest extends TestCase { 12 | private AdsDevName deviceName1; 13 | private AdsDevName deviceName2; 14 | 15 | public AdsDevNameTest(String name) { super(name); } 16 | 17 | @Override 18 | protected void setUp() { 19 | deviceName1 = new AdsDevName(); 20 | deviceName2 = new AdsDevName(AllTests.DEVICE_NAME); 21 | } 22 | 23 | @Override 24 | protected void tearDown() {} 25 | 26 | public void testInitialization() { 27 | assertEquals("Test initial device name (constructor /wo parameter)", 28 | AllTests.EMPTY_DEVICE_NAME, deviceName1.getDevName()); 29 | 30 | assertEquals("Test initial device name (constructor /w parameter)", 31 | AllTests.DEVICE_NAME, deviceName2.getDevName()); 32 | } 33 | 34 | public void testSetDeviceName() { 35 | deviceName1.setDevName(AllTests.DEVICE_NAME); 36 | assertEquals("Test new device name", deviceName2.getDevName(), 37 | deviceName1.getDevName()); 38 | } 39 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/tcads/adsdevicename/test/AllTests.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.tcads.adsdevicename.test; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * 9 | * @author Beckhoff Automation 10 | */ 11 | public class AllTests extends TestCase { 12 | public static void main(String[] args) { 13 | junit.textui.TestRunner.run(AllTests.class); 14 | } 15 | 16 | public static Test suite() { 17 | TestSuite suite = new TestSuite(); 18 | suite.addTestSuite(AdsDevNameTest.class); 19 | 20 | return suite; 21 | } 22 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/tcads/adsnotificationattrib/test/AdsNotificationAttribTest.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.tcads.adsnotificationattrib.test; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import de.beckhoff.jni.tcads.AdsNotificationAttrib; 6 | import junit.framework.TestCase; 7 | 8 | /** 9 | * 10 | * @author Beckhoff Automation 11 | */ 12 | public class AdsNotificationAttribTest extends TestCase { 13 | static final long INIT_ADS_NOTIFICATION_ATTRIBUTE_LEN = 0L; 14 | static final int INIT_ADS_NOTIFICATION_ATTRIBUTE_TRANS_MODE = 0; 15 | static final long INIT_ADS_NOTIFICATION_ATTRIBUTE_DELAY = 0L; 16 | static final long INIT_ADS_NOTIFICATION_ATTRIBUTE_CYCLE_TIME = 0L; 17 | static final long INIT_ADS_NOTIFICATION_ATTRIBUTE_CHANGE_FILTER = 0L; 18 | 19 | static final long NEW_ADS_NOTIFICATION_ATTRIBUTE_LEN = 3L; 20 | static final int NEW_ADS_NOTIFICATION_ATTRIBUTE_TRANS_MODE = 5; 21 | static final long NEW_ADS_NOTIFICATION_ATTRIBUTE_DELAY = 7L; 22 | static final long NEW_ADS_NOTIFICATION_ATTRIBUTE_CYCLE_TIME = 9L; 23 | static final long NEW_ADS_NOTIFICATION_ATTRIBUTE_CHANGE_FILTER = 11L; 24 | 25 | private AdsNotificationAttrib notificationAttrib; 26 | 27 | public AdsNotificationAttribTest(String name) { super(name); } 28 | 29 | @Override 30 | protected void setUp() { 31 | notificationAttrib = new AdsNotificationAttrib(); 32 | } 33 | 34 | @Override 35 | protected void tearDown() {} 36 | 37 | public void testInitialization() { 38 | assertEquals("Test initially carried amount of bytes", 39 | INIT_ADS_NOTIFICATION_ATTRIBUTE_LEN, 40 | notificationAttrib.getCbLength()); 41 | 42 | assertEquals("Test initial transfer mode", 43 | INIT_ADS_NOTIFICATION_ATTRIBUTE_TRANS_MODE, 44 | notificationAttrib.getNTransMode()); 45 | 46 | assertEquals("Test initial maximal delay", 47 | INIT_ADS_NOTIFICATION_ATTRIBUTE_DELAY, 48 | notificationAttrib.getNMaxDelay()); 49 | 50 | assertEquals("Test initial cycle time", 51 | INIT_ADS_NOTIFICATION_ATTRIBUTE_CYCLE_TIME, 52 | notificationAttrib.getNCycleTime()); 53 | 54 | assertEquals("Test initial change filter", 55 | INIT_ADS_NOTIFICATION_ATTRIBUTE_CHANGE_FILTER, 56 | notificationAttrib.getDwChangeFilter()); 57 | } 58 | 59 | public void testSetCBLength() { 60 | notificationAttrib.setCbLength(NEW_ADS_NOTIFICATION_ATTRIBUTE_LEN); 61 | assertEquals("Test newly carried amount of bytes", 62 | NEW_ADS_NOTIFICATION_ATTRIBUTE_LEN, 63 | notificationAttrib.getCbLength()); 64 | } 65 | 66 | public void testSetCycleTime() { 67 | notificationAttrib.setNCycleTime( 68 | NEW_ADS_NOTIFICATION_ATTRIBUTE_CYCLE_TIME); 69 | assertEquals("Test new cycle time", 70 | NEW_ADS_NOTIFICATION_ATTRIBUTE_CYCLE_TIME, 71 | notificationAttrib.getNCycleTime()); 72 | } 73 | 74 | public void testSetMaxDelay() { 75 | notificationAttrib.setNMaxDelay(NEW_ADS_NOTIFICATION_ATTRIBUTE_DELAY); 76 | assertEquals("Test new delay", NEW_ADS_NOTIFICATION_ATTRIBUTE_DELAY, 77 | notificationAttrib.getNMaxDelay()); 78 | } 79 | 80 | public void testSetTransMode() { 81 | notificationAttrib.setNTransMode( 82 | NEW_ADS_NOTIFICATION_ATTRIBUTE_TRANS_MODE); 83 | assertEquals("Test new transfer mode", 84 | NEW_ADS_NOTIFICATION_ATTRIBUTE_TRANS_MODE, 85 | notificationAttrib.getNTransMode()); 86 | } 87 | 88 | public void testSetChangeFilter() { 89 | notificationAttrib.setDwChangeFilter( 90 | NEW_ADS_NOTIFICATION_ATTRIBUTE_CHANGE_FILTER); 91 | assertEquals("Test new change filter", 92 | NEW_ADS_NOTIFICATION_ATTRIBUTE_CHANGE_FILTER, 93 | notificationAttrib.getDwChangeFilter()); 94 | } 95 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/tcads/adsnotificationattrib/test/AllTests.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.tcads.adsnotificationattrib.test; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * 9 | * @author Beckhoff Automation 10 | */ 11 | public class AllTests extends TestCase { 12 | public static void main(String[] args) { 13 | junit.textui.TestRunner.run(AllTests.class); 14 | } 15 | 16 | public static Test suite() { 17 | TestSuite suite = new TestSuite(); 18 | suite.addTestSuite(AdsNotificationAttribTest.class); 19 | 20 | return suite; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/tcads/adsnotificationheader/test/AdsNotificationHeaderTest.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.tcads.adsnotificationheader.test; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import de.beckhoff.jni.tcads.AdsNotificationHeader; 6 | import junit.framework.TestCase; 7 | 8 | /** 9 | * 10 | * @author Beckhoff Automation 11 | */ 12 | public class AdsNotificationHeaderTest extends TestCase { 13 | static final int INIT_ADS_NOTIFICATION_HEADER_DATA_LEN = 10; 14 | static final long INIT_ADS_NOTIFICATION_HEADER_HANDLE = 0L; 15 | static final long INIT_ADS_NOTIFICATION_HEADER_TIME_STAMP = 0L; 16 | static final byte[] INIT_ADS_NOTIFICATION_HEADER_DATA = 17 | new byte[INIT_ADS_NOTIFICATION_HEADER_DATA_LEN]; 18 | 19 | private AdsNotificationHeader notificationHeader; 20 | 21 | public AdsNotificationHeaderTest(String name) { super(name); } 22 | 23 | @Override 24 | protected void setUp() { 25 | notificationHeader = 26 | new AdsNotificationHeader(INIT_ADS_NOTIFICATION_HEADER_DATA_LEN); 27 | } 28 | 29 | @Override 30 | protected void tearDown() {} 31 | 32 | public void testInitialization() { 33 | assertEquals("Test initial notification handle", 34 | INIT_ADS_NOTIFICATION_HEADER_HANDLE, 35 | notificationHeader.getHNotification()); 36 | 37 | assertEquals("Test initial time stamp", 38 | INIT_ADS_NOTIFICATION_HEADER_TIME_STAMP, 39 | notificationHeader.getNTimeStamp()); 40 | 41 | assertArrayEquals("Test initial data", 42 | INIT_ADS_NOTIFICATION_HEADER_DATA, 43 | notificationHeader.getData()); 44 | } 45 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/tcads/adsnotificationheader/test/AllTests.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.tcads.adsnotificationheader.test; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * 9 | * @author Beckhoff Automation 10 | */ 11 | public class AllTests extends TestCase { 12 | public static void main(String[] args) { 13 | junit.textui.TestRunner.run(AllTests.class); 14 | } 15 | 16 | public static Test suite() { 17 | TestSuite suite = new TestSuite(); 18 | suite.addTestSuite(AdsNotificationHeaderTest.class); 19 | 20 | return suite; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/tcads/adsstate/test/AdsStateTest.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.tcads.adsstate.test; 2 | 3 | import de.beckhoff.jni.tcads.AdsState; 4 | import junit.framework.TestCase; 5 | 6 | /** 7 | * 8 | * @author Beckhoff Automation 9 | */ 10 | public class AdsStateTest extends TestCase { 11 | static final short INIT_ADSSTATE_STATE = 0; 12 | static final short NEW_ADSSTATE_STATE = 1; 13 | 14 | private AdsState state; 15 | 16 | public AdsStateTest(String name) { super(name); } 17 | 18 | @Override 19 | protected void setUp() { 20 | state = new AdsState(); 21 | } 22 | 23 | @Override 24 | protected void tearDown() {} 25 | 26 | public void testInitialization() { 27 | assertEquals("Test initial state", INIT_ADSSTATE_STATE, 28 | state.getState()); 29 | } 30 | 31 | public void testSetState() { 32 | state.setState(NEW_ADSSTATE_STATE); 33 | assertEquals("Test new state", NEW_ADSSTATE_STATE, state.getState()); 34 | } 35 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/tcads/adsstate/test/AllTests.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.tcads.adsstate.test; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * 9 | * @author Beckhoff Automation 10 | */ 11 | public class AllTests extends TestCase { 12 | public static void main(String[] args) { 13 | junit.textui.TestRunner.run(AllTests.class); 14 | } 15 | 16 | public static Test suite() { 17 | TestSuite suite = new TestSuite(); 18 | suite.addTestSuite(AdsStateTest.class); 19 | 20 | return suite; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/tcads/adssymbolentry/test/AdsSymbolEntryExceptionTest.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.tcads.adssymbolentry.test; 2 | 3 | import de.beckhoff.jni.tcads.AdsSymbolEntry; 4 | import junit.framework.TestCase; 5 | 6 | /** 7 | * 8 | * @author Beckhoff Automation 9 | */ 10 | public class AdsSymbolEntryExceptionTest extends TestCase { 11 | static final byte[] INIT_ADSSYM_BUFF_EX1 = new byte[] { 12 | 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 13 | 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 14 | 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x42, 0x65, 0x63, 0x00, 15 | 0x6B, 0x68, 0x6F, 0x00, 0x66, 0x66, 0x21, 0x00}; 16 | 17 | static final byte[] INIT_ADSSYM_BUFF_EX2 = new byte[] { 18 | 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 19 | 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 20 | 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x42, 0x65, 0x63, 21 | 0x6B, 0x68, 0x6F, 0x00, 0x66, 0x66, 0x21, 0x00}; 22 | 23 | private AdsSymbolEntry symbol; 24 | 25 | public AdsSymbolEntryExceptionTest(String name) { super(name); } 26 | 27 | public void testInitializationEx1() { 28 | try { 29 | symbol = new AdsSymbolEntry(INIT_ADSSYM_BUFF_EX1); 30 | fail("IllegalArgumentException"); 31 | } catch (IllegalArgumentException ex) { 32 | } 33 | } 34 | 35 | public void testInitializationEx2() { 36 | try { 37 | symbol = new AdsSymbolEntry(INIT_ADSSYM_BUFF_EX2); 38 | fail("IllegalArgumentException"); 39 | } catch (IllegalArgumentException ex) { 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/tcads/adssymbolentry/test/AdsSymbolEntryTest.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.tcads.adssymbolentry.test; 2 | 3 | import de.beckhoff.jni.tcads.AdsSymbolEntry; 4 | import junit.framework.TestCase; 5 | 6 | /** 7 | * 8 | * @author Beckhoff Automation 9 | */ 10 | public class AdsSymbolEntryTest extends TestCase { 11 | static final byte[] INIT_ADSSYM_BUFF = new byte[] { 12 | 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 13 | 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 14 | 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x42, 0x65, 0x63, 15 | 0x00, 0x6B, 0x68, 0x6F, 0x00, 0x66, 0x66, 0x21, 0x00}; 16 | 17 | static final int INIT_ADSSYM_ENTRY_LEN = 0; 18 | static final int INIT_ADSSYM_IGROUP = 1; 19 | static final int INIT_ADSSYM_IOFF = 2; 20 | static final int INIT_ADSSYM_SIZE = 3; 21 | static final int INIT_ADSSYM_DATATYPE = 4; 22 | static final int INIT_ADSSYM_FLAGS = 5; 23 | static final int INIT_ADSSYM_NAME_LEN = 3; 24 | static final int INIT_ADSSYM_TYPE_LEN = 3; 25 | static final int INIT_ADSSYM_COMMENT_LEN = 3; 26 | static final String INIT_ADSSYM_NAME = "Bec"; 27 | static final String INIT_ADSSYM_TYPE = "kho"; 28 | static final String INIT_ADSSYM_COMMENT = "ff!"; 29 | 30 | private AdsSymbolEntry symbol; 31 | 32 | public AdsSymbolEntryTest(String name) { super(name); } 33 | 34 | @Override 35 | protected void setUp() { 36 | symbol = new AdsSymbolEntry(INIT_ADSSYM_BUFF); 37 | } 38 | 39 | @Override 40 | protected void tearDown() {} 41 | 42 | public void testInitialization() { 43 | assertEquals("Test initial entry length", INIT_ADSSYM_ENTRY_LEN, 44 | symbol.getEntryLen()); 45 | 46 | assertEquals("Test initial index group", INIT_ADSSYM_IGROUP, 47 | symbol.getiGroup()); 48 | 49 | assertEquals("Test initial index offset", INIT_ADSSYM_IOFF, 50 | symbol.getiOffs()); 51 | 52 | assertEquals("Test initial size", INIT_ADSSYM_SIZE, symbol.getSize()); 53 | 54 | assertEquals("Test initial datatype", INIT_ADSSYM_DATATYPE, 55 | symbol.getDataType()); 56 | 57 | assertEquals("Test initial flags", INIT_ADSSYM_FLAGS, 58 | symbol.getFlags()); 59 | 60 | assertEquals("Test initial name length", INIT_ADSSYM_NAME_LEN, 61 | symbol.getNameLength()); 62 | 63 | assertEquals("Test initial type length", INIT_ADSSYM_TYPE_LEN, 64 | symbol.getTypeLength()); 65 | 66 | assertEquals("Test initial comment length", INIT_ADSSYM_COMMENT_LEN, 67 | symbol.getCommentLength()); 68 | 69 | assertEquals("Test initial name", INIT_ADSSYM_NAME, symbol.getName()); 70 | 71 | assertEquals("Test initial type", INIT_ADSSYM_TYPE, symbol.getType()); 72 | 73 | assertEquals("Test initial comment", INIT_ADSSYM_COMMENT, 74 | symbol.getComment()); 75 | } 76 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/tcads/adssymbolentry/test/AllTests.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.tcads.adssymbolentry.test; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * 9 | * @author Beckhoff Automation 10 | */ 11 | public class AllTests extends TestCase { 12 | public static void main(String[] args) { 13 | junit.textui.TestRunner.run(AllTests.class); 14 | } 15 | 16 | public static Test suite() { 17 | TestSuite suite = new TestSuite(); 18 | suite.addTestSuite(AdsSymbolEntryTest.class); 19 | suite.addTestSuite(AdsSymbolEntryExceptionTest.class); 20 | 21 | return suite; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/tcads/adsversion/test/AdsVersionTest.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.tcads.adsversion.test; 2 | 3 | import de.beckhoff.jni.tcads.AdsVersion; 4 | import junit.framework.TestCase; 5 | 6 | /** 7 | * 8 | * @author Beckhoff Automation 9 | */ 10 | public class AdsVersionTest extends TestCase { 11 | static final short INIT_ADSVERSION_VERSION = 0; 12 | static final char INIT_ADSVERSION_BUILD = 0; 13 | static final char INIT_ADSVERSION_REVISION = 0; 14 | 15 | public AdsVersionTest(String name) { super(name); } 16 | 17 | public void testInitialization() { 18 | AdsVersion version = new AdsVersion(); 19 | 20 | assertEquals("Test ADS-version", INIT_ADSVERSION_VERSION, 21 | version.getVersion()); 22 | 23 | assertEquals("Test ADS-build", INIT_ADSVERSION_BUILD, 24 | version.getBuild()); 25 | 26 | assertEquals("Test ADS-revision", INIT_ADSVERSION_REVISION, 27 | version.getRevision()); 28 | } 29 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/tcads/adsversion/test/AllTests.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.tcads.adsversion.test; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * 9 | * @author Beckhoff Automation 10 | */ 11 | public class AllTests extends TestCase { 12 | public static void main(String[] args) { 13 | junit.textui.TestRunner.run(AllTests.class); 14 | } 15 | 16 | public static Test suite() { 17 | TestSuite suite = new TestSuite(); 18 | suite.addTestSuite(AdsVersionTest.class); 19 | 20 | return suite; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/tcads/amsaddr/test/AllTests.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.tcads.amsaddr.test; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * 9 | * @author Beckhoff Automation 10 | */ 11 | public class AllTests extends TestCase { 12 | public static void main(String[] args) { 13 | junit.textui.TestRunner.run(AllTests.class); 14 | } 15 | 16 | public static Test suite() { 17 | TestSuite suite = new TestSuite(); 18 | suite.addTestSuite(AmsAddrTest.class); 19 | suite.addTestSuite(AmsAddrStringTest.class); 20 | 21 | return suite; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/tcads/amsaddr/test/AmsAddrStringTest.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.tcads.amsaddr.test; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import de.beckhoff.jni.tcads.AdsCallDllFunction; 6 | import de.beckhoff.jni.tcads.AmsAddr; 7 | import de.beckhoff.jni.tcads.AmsNetId; 8 | import junit.framework.TestCase; 9 | 10 | /** 11 | * 12 | * @author Beckhoff Automation 13 | */ 14 | public class AmsAddrStringTest extends TestCase { 15 | static final AmsNetId NEW_AMSADDR_NET_ID = 16 | new AmsNetId(new char[] {172, 16, 4, 220, 1, 1}); 17 | static final String NEW_AMSADDR_NET_ID_STRING = "172.16.4.220.1.1"; 18 | 19 | private AmsAddr addr; 20 | 21 | public AmsAddrStringTest(String name) { super(name); } 22 | 23 | @Override 24 | protected void setUp() { 25 | addr = new AmsAddr(); 26 | } 27 | 28 | @Override 29 | protected void tearDown() {} 30 | 31 | public void testSetNetIdString0() { 32 | boolean exceptionThrown = false; 33 | try { 34 | addr.setNetIdStringEx("X"); 35 | } catch (IllegalArgumentException ex) { 36 | exceptionThrown = true; 37 | } 38 | assertTrue( 39 | "Expect the exception to be thrown when the format is invalid", 40 | exceptionThrown); 41 | } 42 | 43 | public void testSetNetIdString1() { 44 | addr.setNetIdString(NEW_AMSADDR_NET_ID_STRING); 45 | 46 | if (AdsCallDllFunction.jniWrapperDllVersionNot1()) { 47 | assertArrayEquals("Test new AmsNetId value (set via string).", 48 | NEW_AMSADDR_NET_ID.getCharArr(), 49 | addr.getNetId().getCharArr()); 50 | } else { 51 | assertEquals("Test new AmsNetId value (set via string).", 52 | NEW_AMSADDR_NET_ID_STRING, addr.getNetIdString()); 53 | } 54 | } 55 | 56 | public void testSetNetIdString2() { 57 | addr.setNetIdStringEx(NEW_AMSADDR_NET_ID_STRING); 58 | 59 | if (AdsCallDllFunction.jniWrapperDllVersionNot1()) { 60 | assertArrayEquals("Test new AmsNetId value (set via string).", 61 | NEW_AMSADDR_NET_ID.getCharArr(), 62 | addr.getNetId().getCharArr()); 63 | } else { 64 | assertEquals("Test new AmsNetId value (set via string).", 65 | NEW_AMSADDR_NET_ID_STRING, addr.getNetIdString()); 66 | } 67 | } 68 | 69 | public void testGetNetIdString() { 70 | if (AdsCallDllFunction.jniWrapperDllVersionNot1()) { 71 | addr.setNetId(NEW_AMSADDR_NET_ID); 72 | 73 | assertEquals("Test AmsNetId string conversion", 74 | NEW_AMSADDR_NET_ID_STRING, addr.getNetIdString()); 75 | } else { 76 | // Nothing to test here 77 | } 78 | } 79 | } -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/tcads/amsnetid/test/AllTests.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.tcads.amsnetid.test; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * 9 | * @author Beckhoff Automation 10 | */ 11 | public class AllTests extends TestCase { 12 | public static void main(String[] args) { 13 | junit.textui.TestRunner.run(AllTests.class); 14 | } 15 | 16 | public static Test suite() { 17 | TestSuite suite = new TestSuite(); 18 | suite.addTestSuite(AmsNetIdTest.class); 19 | 20 | return suite; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/de/beckhoff/jni/tcads/amsnetid/test/AmsNetIdTest.java: -------------------------------------------------------------------------------- 1 | package de.beckhoff.jni.tcads.amsnetid.test; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import de.beckhoff.jni.tcads.AmsNetId; 6 | import junit.framework.TestCase; 7 | 8 | /** 9 | * 10 | * @author Beckhoff Automation 11 | */ 12 | public class AmsNetIdTest extends TestCase { 13 | static final char[] INIT_AMS_PARTS_EMPTY = new char[6]; 14 | static final char[] INIT_AMS_PARTS = new char[] {172, 16, 4, 220, 1, 1}; 15 | static final char[] NEW_AMS_PARTS = new char[] {172, 16, 4, 42, 1, 1}; 16 | 17 | public AmsNetIdTest(String name) { super(name); } 18 | 19 | @Override 20 | protected void setUp() {} 21 | 22 | @Override 23 | protected void tearDown() {} 24 | 25 | public void testInitialization1() { 26 | AmsNetId amsNetId = new AmsNetId(); 27 | assertArrayEquals("Test initial empty amsNetId parts", 28 | INIT_AMS_PARTS_EMPTY, amsNetId.getCharArr()); 29 | } 30 | 31 | public void testInitialization2() { 32 | AmsNetId amsNetId = new AmsNetId(INIT_AMS_PARTS); 33 | assertArrayEquals("Test initial amsNetID parts", INIT_AMS_PARTS, 34 | amsNetId.getCharArr()); 35 | } 36 | 37 | public void testSetAmsNetId() { 38 | AmsNetId amsNetId = new AmsNetId(INIT_AMS_PARTS); 39 | amsNetId.setCharArr(NEW_AMS_PARTS); 40 | assertArrayEquals("Test new amsNetID parts", NEW_AMS_PARTS, 41 | amsNetId.getCharArr()); 42 | } 43 | } 44 | --------------------------------------------------------------------------------