diff --git a/OPC_Client_Jeasyopc/.classpath b/OPC_Client_Jeasyopc/.classpath index f7805d0..9379821 100644 --- a/OPC_Client_Jeasyopc/.classpath +++ b/OPC_Client_Jeasyopc/.classpath @@ -1,15 +1,10 @@ - - - - - - - - + + + diff --git a/OPC_Client_Jeasyopc/lib/JCustomOpc.dll b/OPC_Client_Jeasyopc/lib/JCustomOpc.dll new file mode 100644 index 0000000..8feab4c Binary files /dev/null and b/OPC_Client_Jeasyopc/lib/JCustomOpc.dll differ diff --git a/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest01.java b/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest01.java new file mode 100644 index 0000000..425945a --- /dev/null +++ b/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest01.java @@ -0,0 +1,31 @@ +package com.freud.opc.jeasyopc; + +import javafish.clients.opc.JOpc; + +/** + * Á¬½Óµ½OPC Server, ÿ¸ô200ºÁÃë²é¿´Ò»´Î״̬£¬1ÃëÖÓÖ®ºó¹Ø±ÕÁ¬½Ó + * + * @author Freud + * + */ +public class JeasyopcTest01 { + public static int iter = 0; + + public static void main(String[] args) throws Exception { + + JOpc.coInitialize(); + JOpc jopc = new JOpc("localhost", "Matrikon.OPC.Simulation", + "JCustomOPC"); + + jopc.connect(); + while (true) { + Thread.sleep(200); + System.out.println("Client is connected: " + jopc.ping()); + iter++; + if (iter == 5) { + break; + } + } + JOpc.coUninitialize(); + } +} diff --git a/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest02.java b/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest02.java new file mode 100644 index 0000000..34d4128 --- /dev/null +++ b/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest02.java @@ -0,0 +1,39 @@ +package com.freud.opc.jeasyopc; + +import javafish.clients.opc.JOpc; +import javafish.clients.opc.component.OpcGroup; +import javafish.clients.opc.component.OpcItem; +import javafish.clients.opc.exception.CoInitializeException; + +/** + * Á¬½Óµ½OPC Server, ²¢Ìí¼ÓÒ»¸öGroup£¬ÔÚGroupÏÂÌí¼ÓÒ»¸öItem + * + * @author Freud + * + */ +public class JeasyopcTest02 { + + public static void main(String[] args) throws Exception { + + try { + JOpc.coInitialize(); + } catch (CoInitializeException e1) { + e1.printStackTrace(); + } + + JOpc jopc = new JOpc("localhost", "Matrikon.OPC.Simulation", "JOPC1"); + + OpcItem item1 = new OpcItem("Random.Real8", true, ""); + OpcGroup group = new OpcGroup("group1", false, 500, 0.0f); + + group.addItem(item1); + + jopc.addGroup(group); + + jopc.connect(); + System.out.println("Connected..."); + + JOpc.coUninitialize(); + System.out.println("Test terminated..."); + } +} diff --git a/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest03.java b/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest03.java new file mode 100644 index 0000000..62f0138 --- /dev/null +++ b/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest03.java @@ -0,0 +1,26 @@ +package com.freud.opc.jeasyopc; + +import javafish.clients.opc.browser.JOpcBrowser; + +/** + * ²éÕÒijServerϵÄËùÓÐOPC serverÁ¬½Ó + * + * @author Freud + * + */ +public class JeasyopcTest03 { + + public static void main(String[] args) throws Exception { + + JOpcBrowser.coInitialize(); + + String[] opcServers = JOpcBrowser.getOpcServers("localhost"); + System.out.println("------------List All Servers------------"); + for (String server : opcServers) { + System.out.println("[server]:" + server); + } + + // uninitialize COM components + JOpcBrowser.coUninitialize(); + } +} diff --git a/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest04.java b/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest04.java new file mode 100644 index 0000000..4e4a112 --- /dev/null +++ b/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest04.java @@ -0,0 +1,28 @@ +package com.freud.opc.jeasyopc; + +import javafish.clients.opc.browser.JOpcBrowser; + +/** + * ͨ¹ýOPCÃû×Ö²éÕÒËùÓÐBranch + * + * @author Freud + * + */ +public class JeasyopcTest04 { + + public static void main(String[] args) throws Exception { + + JOpcBrowser jbrowser = new JOpcBrowser("localhost", + "Matrikon.OPC.Simulation.1", "JOPCBrowser1"); + + jbrowser.connect(); + String[] branches = jbrowser.getOpcBranch(""); + System.out.println("------------List All Branches------------"); + for (String branch : branches) { + System.out.println("[branch]:" + branch); + } + + // uninitialize COM components + JOpcBrowser.coUninitialize(); + } +} diff --git a/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest05.java b/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest05.java new file mode 100644 index 0000000..fa3cdd6 --- /dev/null +++ b/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest05.java @@ -0,0 +1,31 @@ +package com.freud.opc.jeasyopc; + +import javafish.clients.opc.browser.JOpcBrowser; + +/** + * ͨ¹ýBranchÃû×Ö²éÕÒËùÓÐItem + * + * @author Freud + * + */ +public class JeasyopcTest05 { + + public static void main(String[] args) throws Exception { + + JOpcBrowser jbrowser = new JOpcBrowser("localhost", + "Matrikon.OPC.Simulation.1", "JOPCBrowser1"); + String[] items = jbrowser.getOpcItems("Simulation Items.Random", true); + + if (items != null) { + System.out + .println("------------List All Leafs under[Simulation Items.Random]------------"); + for (int i = 0; i < items.length; i++) { + String item = items[i]; + System.out.println(item); + } + } + + // uninitialize COM components + JOpcBrowser.coUninitialize(); + } +} diff --git a/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest06.java b/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest06.java new file mode 100644 index 0000000..c8a7d90 --- /dev/null +++ b/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest06.java @@ -0,0 +1,64 @@ +package com.freud.opc.jeasyopc; + +import javafish.clients.opc.JOpc; +import javafish.clients.opc.component.OpcGroup; +import javafish.clients.opc.component.OpcItem; + +/** + * ͬ²½¶ÁÈ¡Group + * + * @author Freud + * + */ +public class JeasyopcTest06 { + + public static void main(String[] args) throws Exception { + + JOpc.coInitialize(); + + JOpc jopc = new JOpc("localhost", "Matrikon.OPC.Simulation.1", "JOPC1"); + + OpcItem item1 = new OpcItem("Random.Real8", true, ""); + OpcItem item2 = new OpcItem("Random.Real8", true, ""); + OpcItem item3 = new OpcItem("Random.Real8", true, ""); + + OpcGroup group = new OpcGroup("group1", true, 10, 0.0f); + + group.addItem(item1); + group.addItem(item2); + group.addItem(item3); + + jopc.addGroup(group); + + jopc.connect(); + System.out.println("JOPC client is connected..."); + + jopc.registerGroups(); + System.out.println("OPCGroup are registered..."); + + synchronized (JeasyopcTest06.class) { + JeasyopcTest06.class.wait(2000); + } + + // Synchronous reading of group + int cycles = 30; + int acycle = 0; + /** + * ÉèÖöÁÈ¡30´Î + */ + while (acycle++ < cycles) { + /** + * ÉèÖÃÿ2ÃëÖÓ¶ÁÈ¡Ò»´Î + */ + synchronized (JeasyopcTest06.class) { + JeasyopcTest06.class.wait(2000); + } + + OpcGroup responseGroup = jopc.synchReadGroup(group); + System.out.println(responseGroup); + + } + + JOpc.coUninitialize(); + } +} diff --git a/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest07.java b/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest07.java new file mode 100644 index 0000000..09cebf3 --- /dev/null +++ b/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest07.java @@ -0,0 +1,58 @@ +package com.freud.opc.jeasyopc; + +import javafish.clients.opc.JOpc; +import javafish.clients.opc.SynchReadItemExample; +import javafish.clients.opc.component.OpcGroup; +import javafish.clients.opc.component.OpcItem; +import javafish.clients.opc.variant.Variant; + +/** + * ͬ²½¶ÁÈ¡ItemÖµ + * + * @author Freud + * + */ +public class JeasyopcTest07 { + + public static void main(String[] args) throws Exception { + + SynchReadItemExample test = new SynchReadItemExample(); + + JOpc.coInitialize(); + + JOpc jopc = new JOpc("localhost", "Matrikon.OPC.Simulation", "JOPC1"); + + OpcItem item1 = new OpcItem("Random.int1", true, ""); + + OpcGroup group = new OpcGroup("group1", true, 500, 0.0f); + + group.addItem(item1); + jopc.addGroup(group); + + jopc.connect(); + System.out.println("JOPC client is connected..."); + + jopc.registerGroups(); + System.out.println("OPCGroup are registered..."); + + synchronized (test) { + test.wait(50); + } + + // Synchronous reading of item + int cycles = 7; + int acycle = 0; + while (acycle++ < cycles) { + synchronized (test) { + test.wait(1000); + } + OpcItem responseItem = jopc.synchReadItem(group, item1); + System.out.println(responseItem); + System.out.println(Variant.getVariantName(responseItem + .getDataType()) + ": " + responseItem.getValue()); + + } + + JOpc.coUninitialize(); + } +} diff --git a/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest08.java b/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest08.java new file mode 100644 index 0000000..d4a98cd --- /dev/null +++ b/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest08.java @@ -0,0 +1,81 @@ +package com.freud.opc.jeasyopc; + +import javafish.clients.opc.JOpc; +import javafish.clients.opc.component.OpcGroup; +import javafish.clients.opc.component.OpcItem; +import javafish.clients.opc.variant.Variant; +import javafish.clients.opc.variant.VariantList; + +/** + * ͬ²½¶ÁдItemÖµ + * + * @author Freud + * + */ +public class JeasyopcTest08 { + + public static void main(String[] args) throws Exception { + + JOpc jopc = new JOpc("localhost", "Matrikon.OPC.Simulation.1", "JOPC1"); + + JOpc.coInitialize(); + + OpcItem item1 = new OpcItem("Bucket Brigade.ArrayOfReal8", true, ""); + + OpcGroup group = new OpcGroup("Random", true, 500, 0.0f); + + group.addItem(item1); + + jopc.connect(); + System.out.println("OPC is connected..."); + jopc.addGroup(group); + + jopc.registerGroup(group); + System.out.println("Group was registred..."); + jopc.registerItem(group, item1); + System.out.println("Item was registred..."); + + // synchronous reading + OpcItem itemRead = null; + for (int i = 0; i < 2; i++) { + Thread.sleep(2000); + + itemRead = jopc.synchReadItem(group, item1); + System.out.println(itemRead); + } + + // synchronous writing (example with array writing ;-) + // prepare array + VariantList list = new VariantList(Variant.VT_R8); + list.add(new Variant(2.0)); + list.add(new Variant(2.0)); + list.add(new Variant(3.0)); + Variant varin = new Variant(list); + System.out + .println("Original Variant type: " + + Variant.getVariantName(varin.getVariantType()) + ", " + + varin); + item1.setValue(varin); + + // write to opc-server + jopc.synchWriteItem(group, item1); + + Thread.sleep(2000); + + // read item from opc-server + itemRead = jopc.synchReadItem(group, item1); + + // show item and its variant type + System.out.println("WRITE ITEM IS: " + itemRead); + System.out.println("VALUE TYPE: " + + Variant.getVariantName(itemRead.getDataType())); + + jopc.unregisterItem(group, item1); + System.out.println("Item was unregistred..."); + jopc.unregisterGroup(group); + System.out.println("Group was unregistred..."); + JOpc.coUninitialize(); + System.out.println("OPC is disconnected..."); + + } +} diff --git a/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest09.java b/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest09.java new file mode 100644 index 0000000..9fd0c8b --- /dev/null +++ b/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest09.java @@ -0,0 +1,86 @@ +package com.freud.opc.jeasyopc; + +import javafish.clients.opc.JOpc; +import javafish.clients.opc.component.OpcGroup; +import javafish.clients.opc.component.OpcItem; + +/** + * Òì²½¶ÁдItemÖµ + * + * @author Freud + * + */ +public class JeasyopcTest09 { + + public static void main(String[] args) throws Exception { + + JOpc.coInitialize(); + + JOpc jopc = new JOpc("localhost", "Matrikon.OPC.Simulation", "JOPC1"); + + OpcItem item1 = new OpcItem("Random.Real8", true, ""); + OpcItem item2 = new OpcItem("Random.Real8", true, ""); + OpcGroup group = new OpcGroup("group1", true, 2000, 0.0f); + + group.addItem(item1); + group.addItem(item2); + + jopc.addGroup(group); + + jopc.connect(); + System.out.println("OPC client is connected..."); + + jopc.registerGroups(); + System.out.println("OPC groups are registered..."); + + jopc.asynch10Read(group); + System.out.println("OPC asynchronous reading is applied..."); + + OpcGroup downGroup; + + long start = System.currentTimeMillis(); + while ((System.currentTimeMillis() - start) < 10000) { + jopc.ping(); + downGroup = jopc.getDownloadGroup(); + if (downGroup != null) { + System.out.println(downGroup); + } + + if ((System.currentTimeMillis() - start) >= 6000) { + jopc.setGroupActivity(group, false); + } + + synchronized (JeasyopcTest09.class) { + JeasyopcTest09.class.wait(1000); + } + } + + // change activity + jopc.setGroupActivity(group, true); + + // change updateTime + jopc.setGroupUpdateTime(group, 100); + + start = System.currentTimeMillis(); + while ((System.currentTimeMillis() - start) < 5000) { + jopc.ping(); + downGroup = jopc.getDownloadGroup(); + if (downGroup != null) { + System.out.println(downGroup); + } + + synchronized (JeasyopcTest09.class) { + JeasyopcTest09.class.wait(50); + } + } + + jopc.asynch10Unadvise(group); + System.out.println("OPC asynchronous reading is unadvise..."); + + JOpc.coUninitialize(); + System.out.println("Program terminated..."); + + System.out.println(""); + + } +} diff --git a/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest10.java b/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest10.java new file mode 100644 index 0000000..e2fdad1 --- /dev/null +++ b/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest10.java @@ -0,0 +1,85 @@ +package com.freud.opc.jeasyopc; + +import javafish.clients.opc.JEasyOpc; +import javafish.clients.opc.JOpc; +import javafish.clients.opc.component.OpcGroup; +import javafish.clients.opc.component.OpcItem; + +/** + * Òì²½10ºÍÒì²½20¶ÁÈ¡ + * + * @author Freud + * + */ +public class JeasyopcTest10 { + + public static void main(String[] args) throws Exception { + + JOpc.coInitialize(); + + JOpc jopc = new JOpc("localhost", "Matrikon.OPC.Simulation", "JOPC1"); + JEasyOpc jopc2 = new JEasyOpc("localhost", "Matrikon.OPC.Simulation", + "JOPC2"); + + OpcItem item1 = new OpcItem("Random.Real8", true, ""); + OpcItem item2 = new OpcItem("Random.Real8", true, ""); + OpcGroup group = new OpcGroup("group1", true, 1000, 0.0f); + + OpcItem item3 = new OpcItem("Random.Real8", true, ""); + OpcItem item4 = new OpcItem("Random.Real8", true, ""); + + OpcGroup group2 = new OpcGroup("group2", true, 2500, 0.0f); + + group.addItem(item1); + group.addItem(item2); + + group2.addItem(item3); + group2.addItem(item4); + + jopc.addGroup(group); + jopc2.addGroup(group2); + + jopc.connect(); + jopc2.connect(); + System.out.println("OPC client is connected..."); + + jopc.registerGroups(); + jopc2.registerGroups(); + System.out.println("OPC groups are registered..."); + + jopc.asynch10Read(group); + jopc2.asynch20Read(group2); + System.out.println("OPC asynchronous reading is applied..."); + + OpcGroup downGroup; + OpcGroup downGroup2; + + long start = System.currentTimeMillis(); + while ((System.currentTimeMillis() - start) < 30000) { + jopc.ping(); + jopc2.ping(); + + downGroup = jopc.getDownloadGroup(); + if (downGroup != null) { + System.out.println("[Group1]" + downGroup); + } + + downGroup2 = jopc2.getDownloadGroup(); + if (downGroup2 != null) { + System.out.println("[Group2]" + downGroup2); + } + + synchronized (JeasyopcTest10.class) { + JeasyopcTest10.class.wait(50); + } + } + + jopc.asynch10Unadvise(group); + jopc2.asynch20Unadvise(group2); + System.out.println("OPC asynchronous reading is unadvise..."); + + JOpc.coUninitialize(); + System.out.println("Program terminated..."); + + } +} diff --git a/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest11.java b/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest11.java new file mode 100644 index 0000000..cbae8d6 --- /dev/null +++ b/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest11.java @@ -0,0 +1,86 @@ +package com.freud.opc.jeasyopc; + +import com.freud.opc.jeasyopc.listener.OpcAsynchListener; + +import javafish.clients.opc.JEasyOpc; +import javafish.clients.opc.JOpc; +import javafish.clients.opc.component.OpcGroup; +import javafish.clients.opc.component.OpcItem; + +/** + * Òì²½¶©ÔÄʽ¶ÁÈ¡ + * + * @author Freud + * + */ +public class JeasyopcTest11 { + + public static void main(String[] args) throws Exception { + OpcAsynchListener listener = new OpcAsynchListener(); + + JOpc.coInitialize(); + + JEasyOpc jopc = new JEasyOpc("localhost", "Matrikon.OPC.Simulation", + "JOPC"); + + OpcItem item1 = new OpcItem("Random.Real8", true, ""); + OpcItem item2 = new OpcItem("Random.Real8", true, ""); + OpcItem item3 = new OpcItem("Random.Real8", true, ""); + OpcItem item4 = new OpcItem("Random.Real8", true, ""); + + OpcGroup group1 = new OpcGroup("group1", true, 2000, 0.0f); + + group1.addItem(item1); + group1.addItem(item2); + group1.addItem(item3); + group1.addItem(item4); + + group1.addAsynchListener(listener); + + jopc.addGroup(group1); + + jopc.start(); + + System.out + .println("--------------------------JOPC started--------------------------"); + + synchronized (listener) { + listener.wait(3000); + } + + System.out.println("--------------------------JOPC active:[" + + jopc.ping() + "]--------------------------"); + + synchronized (listener) { + listener.wait(8000); + } + + jopc.setGroupActivity(group1, false); + System.out.println("--------------------------Set JOPC status:[" + + group1.isActive() + "]--------------------------"); + + synchronized (listener) { + listener.wait(4000); + } + + jopc.setGroupActivity(group1, true); + System.out.println("--------------------------Set JOPC status:[" + + group1.isActive() + "]--------------------------"); + + synchronized (listener) { + listener.wait(4000); + } + + jopc.setGroupUpdateTime(group1, 100); + System.out.println("--------------------------Set JOPC update rate : [" + + group1.getUpdateRate() + "]--------------------------"); + + synchronized (listener) { + listener.wait(2000); + } + + jopc.terminate(); + + JOpc.coUninitialize(); + } +} diff --git a/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest12.java b/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest12.java new file mode 100644 index 0000000..4b21575 --- /dev/null +++ b/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest12.java @@ -0,0 +1,24 @@ +package com.freud.opc.jeasyopc; + +import javafish.clients.opc.component.OpcGroup; +import javafish.clients.opc.component.OpcItem; + +/** + * Group¿Ë¡ + * + * @author Freud + * + */ +public class JeasyopcTest12 { + + public static void main(String[] args) throws Exception { + OpcGroup group1 = new OpcGroup("group-1", true, 500, 0.0f); + OpcItem item1 = new OpcItem("item-1", true, "path1"); + OpcItem item2 = new OpcItem("item-2", true, "path2"); + group1.addItem(item1); + group1.addItem(item2); + OpcGroup groupClone1 = (OpcGroup) group1.clone(); + + System.out.println(groupClone1); + } +} diff --git a/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest13.java b/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest13.java new file mode 100644 index 0000000..6973dcf --- /dev/null +++ b/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/JeasyopcTest13.java @@ -0,0 +1,67 @@ +package com.freud.opc.jeasyopc; + +import javafish.clients.opc.EmptyValueExample; +import javafish.clients.opc.JOpc; +import javafish.clients.opc.component.OpcGroup; +import javafish.clients.opc.component.OpcItem; +import javafish.clients.opc.exception.ComponentNotFoundException; +import javafish.clients.opc.exception.SynchReadException; +import javafish.clients.opc.variant.Variant; + +/** + * ¿ÕֵʾÀý + * + * @author Freud + * + */ +public class JeasyopcTest13 { + + public static void main(String[] args) throws Exception { + EmptyValueExample test = new EmptyValueExample(); + + JOpc.coInitialize(); + + JOpc jopc = new JOpc("localhost", "Matrikon.OPC.Simulation", "JOPC1"); + + OpcItem item = new OpcItem("Random.ArrayOfReal8", true, ""); + + OpcGroup group = new OpcGroup("group1", true, 10, 0.0f); + + group.addItem(item); + jopc.addGroup(group); + + jopc.connect(); + System.out.println("JOPC client is connected..."); + + jopc.registerGroups(); + System.out.println("OPCGroup are registered..."); + + // not waiting for registration + synchReadItem(jopc, group, item); + synchronized (test) { + test.wait(2000); + } + synchReadItem(jopc, group, item); + + JOpc.coUninitialize(); + + } + + private static void synchReadItem(JOpc jopc, OpcGroup group, OpcItem item) + throws ComponentNotFoundException, SynchReadException { + // read again + OpcItem responseItem = jopc.synchReadItem(group, item); + System.out.println(responseItem); + System.out.println(!responseItem.isQuality() ? "Quality: BAD!!!" + : "Quality: GOOD"); + // processing + if (!responseItem.isQuality()) { + System.out + .println("This next processing is WRONG!!! You haven't quality!!!"); + } + System.out.println("Processing: Data type: " + + Variant.getVariantName(responseItem.getDataType()) + + " Value: " + responseItem.getValue()); + + } +} diff --git a/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/listener/OpcAsynchListener.java b/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/listener/OpcAsynchListener.java new file mode 100644 index 0000000..49bc5d0 --- /dev/null +++ b/OPC_Client_Jeasyopc/src/main/java/com/freud/opc/jeasyopc/listener/OpcAsynchListener.java @@ -0,0 +1,25 @@ +package com.freud.opc.jeasyopc.listener; + +import javafish.clients.opc.JCustomOpc; +import javafish.clients.opc.asynch.AsynchEvent; +import javafish.clients.opc.asynch.OpcAsynchGroupListener; + +public class OpcAsynchListener implements OpcAsynchGroupListener { + + @Override + public void getAsynchEvent(AsynchEvent event) { + System.out.println(((JCustomOpc) event.getSource()) + .getFullOpcServerName() + "=>"); + System.out.println("Package: " + event.getID()); + System.out.println(event.getOPCGroup()); + + // System.out.println(((JCustomOpc) event.getSource()) + // .getFullOpcServerName() + "=>"); + // System.out.println("Package: " + event.getID()); + // System.out.println("Group name: " + + // event.getOPCGroup().getGroupName()); + // System.out + // .println("Items count: " + event.getOPCGroup().getItemCount()); + } + +} diff --git a/OPC_Client_Jeasyopc/src/main/resources/javafish/clients/opc/JCustomOpc.properties b/OPC_Client_Jeasyopc/src/main/resources/javafish/clients/opc/JCustomOpc.properties new file mode 100644 index 0000000..5ad2dde --- /dev/null +++ b/OPC_Client_Jeasyopc/src/main/resources/javafish/clients/opc/JCustomOpc.properties @@ -0,0 +1,7 @@ +# JCustomOpc properties +#---------------------- +# library path +library.path = ./lib/JCustomOpc + +# translation, see: +# javafish.clients.opc.Translate \ No newline at end of file diff --git a/OPC_Client_Jeasyopc/src/main/resources/javafish/clients/opc/lang/Translate.properties b/OPC_Client_Jeasyopc/src/main/resources/javafish/clients/opc/lang/Translate.properties new file mode 100644 index 0000000..151dbe1 --- /dev/null +++ b/OPC_Client_Jeasyopc/src/main/resources/javafish/clients/opc/lang/Translate.properties @@ -0,0 +1,3 @@ +# Translate properties +resource = javafish.clients.opc.lang.resource +locale = en \ No newline at end of file diff --git a/OPC_Client_Jeasyopc/src/main/resources/javafish/clients/opc/lang/resource_cs.properties b/OPC_Client_Jeasyopc/src/main/resources/javafish/clients/opc/lang/resource_cs.properties new file mode 100644 index 0000000..f424d4d --- /dev/null +++ b/OPC_Client_Jeasyopc/src/main/resources/javafish/clients/opc/lang/resource_cs.properties @@ -0,0 +1 @@ +# czech localization diff --git a/OPC_Client_Jeasyopc/src/main/resources/javafish/clients/opc/lang/resource_de.properties b/OPC_Client_Jeasyopc/src/main/resources/javafish/clients/opc/lang/resource_de.properties new file mode 100644 index 0000000..e69de29 diff --git a/OPC_Client_Jeasyopc/src/main/resources/javafish/clients/opc/lang/resource_en.properties b/OPC_Client_Jeasyopc/src/main/resources/javafish/clients/opc/lang/resource_en.properties new file mode 100644 index 0000000..34cfeec --- /dev/null +++ b/OPC_Client_Jeasyopc/src/main/resources/javafish/clients/opc/lang/resource_en.properties @@ -0,0 +1,41 @@ +# english localization + +# exception localization +GROUP_EXISTS_EXCEPTION = The group exists on OPC Server: +GROUP_NO_EXISTS_EXCEPTION = The group doesn't exist: +ITEM_EXISTS_EXCEPTION = The item exists on OPC Group: +ITEM_NO_EXISTS_EXCEPTION = The item doesn't exist: +CONNECTIVITY_EXCEPTION = The connection to the OPC Server has failed: +COINITIALIZE_EXCECPTION = CoInitialize COM object exception. +COUNINITIALIZE_EXCECPTION = CoUninitialize COM object exception. +HOST_EXCEPTION = Host not found: +UNABLE_BROWSE_BRANCH_EXCEPTION = Unable to browse a branch. +UNABLE_BROWSE_LEAF_EXCEPTION = Unable to browse a leaf (item). +UNABLE_IBROWSE_EXCEPTION = Unable to initialize IBrowse. +NOT_FOUND_SERVERS_EXCEPTION = OPC servers not found on +UNABLE_ADD_GROUP_EXCEPTION = Unable to register group to server: +UNABLE_ADD_GROUP_EXCEPTION_UNKNOWN = Unable to register some group to server. +UNABLE_ADD_ITEM_EXCEPTION = Unable to register item to group: +UNABLE_ADD_ITEM_EXCEPTION_UNKNOWN = Unable to register some item to group. +COMPONENT_NOT_FOUND_EXCEPTION = The component (group/item) wasn't found: +UNABLE_REMOVE_GROUP_EXCEPTION = Unable to remove group: +UNABLE_REMOVE_GROUP_EXCEPTION_UNKNOWN = Unable to remove some group. +UNABLE_REMOVE_ITEM_EXCEPTION = Unable to remove item: +SYNCH_READ_EXCEPTION = Synchronous reading error. +SYNCH_WRITE_EXCEPTION = Synchronous writing error. +ASYNCH_10_READ_EXCEPTION = Asynchronous read error (register AdviseSink). +ASYNCH_20_READ_EXCEPTION = Asynchronous read error (register CallBack). +ASYNCH_10_UNADVISE_EXCEPTION = Asynchronous unadvise 1.0 error. +ASYNCH_20_UNADVISE_EXCEPTION = Asynchronous unadvise 2.0 error. +GROUP_UPDATETIME_EXCEPTION = Update time of group cannot be changed: +GROUP_ACTIVITY_EXCEPTION = Activity of group cannot be changed: +ITEM_ACTIVITY_EXCEPTION = Activity of item cannot be changed: +VARIANT_TYPE_EXCEPTION = Variant typecast exception. +VARIANT_TYPE_COMPARE_EXCEPTION = Variant compare exception (not Comparable types). + +# jeasyopc translation +JEASYOPC_CONNECTED = The OPC Client is connected. +JEASYOPC_DISCONNECTED = The OPC Client is disconnected. +JEASYOPC_GRP_REG = OPC Groups are registered. +JEASYOPC_GRP_UNREG = OPC Groups are unregistered successfully. +JEASYOPC_ASYNCH20_START = Asynchronous mode 2.0 is started. \ No newline at end of file diff --git a/OPC_Client_Jeasyopc/src/main/resources/javafish/clients/opc/lang/resource_pt.properties b/OPC_Client_Jeasyopc/src/main/resources/javafish/clients/opc/lang/resource_pt.properties new file mode 100644 index 0000000..61844cc --- /dev/null +++ b/OPC_Client_Jeasyopc/src/main/resources/javafish/clients/opc/lang/resource_pt.properties @@ -0,0 +1,41 @@ +# Portuguese localization + +# exception localization +GROUP_EXISTS_EXCEPTION = O grupo existe no servidor OPC: +GROUP_NO_EXISTS_EXCEPTION = O grupo não existe: +ITEM_EXISTS_EXCEPTION = O item existe no grupo OPC: +ITEM_NO_EXISTS_EXCEPTION = O item não existe: +CONNECTIVITY_EXCEPTION = A ligação ao servidor OPC falhou: +COINITIALIZE_EXCECPTION = Excepção CoInitialize no objecto COM. +COUNINITIALIZE_EXCECPTION = Excepção CoUninitialize no objecto COM. +HOST_EXCEPTION = Servidor não encontrado: +UNABLE_BROWSE_BRANCH_EXCEPTION = Impossível fazer browse ao branch. +UNABLE_BROWSE_LEAF_EXCEPTION = Impossível fazer browse ao item. +UNABLE_IBROWSE_EXCEPTION = Impossível inicializar IBrowse. +NOT_FOUND_SERVERS_EXCEPTION = Servidor OPC não encontrado em +UNABLE_ADD_GROUP_EXCEPTION = Impossível registar grupo no servidor: +UNABLE_ADD_GROUP_EXCEPTION_UNKNOWN = Impossível registar algum grupo no servidor. +UNABLE_ADD_ITEM_EXCEPTION = Impossível registar item no grupo: +UNABLE_ADD_ITEM_EXCEPTION_UNKNOWN = Impossível registar algum item no grupo. +COMPONENT_NOT_FOUND_EXCEPTION = O componente (grupo/item) não foi encontrado: +UNABLE_REMOVE_GROUP_EXCEPTION = Impossível remover grupo: +UNABLE_REMOVE_GROUP_EXCEPTION_UNKNOWN = Impossível remover algum grupo. +UNABLE_REMOVE_ITEM_EXCEPTION = Impossível remover item: +SYNCH_READ_EXCEPTION = Erro de leitura síncrono. +SYNCH_WRITE_EXCEPTION = Erro de escrita síncrono. +ASYNCH_10_READ_EXCEPTION = Erro de leitura assíncrono (register AdviseSink). +ASYNCH_20_READ_EXCEPTION = Erro de leitura assíncrono (register CallBack). +ASYNCH_10_UNADVISE_EXCEPTION = Asynchronous unadvise 1.0 error. +ASYNCH_20_UNADVISE_EXCEPTION = Asynchronous unadvise 2.0 error. +GROUP_UPDATETIME_EXCEPTION = Tempo de actualização do grupo não pode ser mudado: +GROUP_ACTIVITY_EXCEPTION = Actividade do grupo não pode ser mudada: +ITEM_ACTIVITY_EXCEPTION = Actividade do item não pode ser mudada: +VARIANT_TYPE_EXCEPTION = Variant typecast exception. +VARIANT_TYPE_COMPARE_EXCEPTION = Variant compare exception (tipos não implementam Comparable). + +# jeasyopc translation +JEASYOPC_CONNECTED = O cliente OPC está ligado. +JEASYOPC_DISCONNECTED = O cliente OPC está desligado. +JEASYOPC_GRP_REG = Grupos OPC registados. +JEASYOPC_GRP_UNREG = Grupos OPC desregistados. +JEASYOPC_ASYNCH20_START = Modo Asynchronous 2.0 iniciado. \ No newline at end of file diff --git a/OPC_Client_Jeasyopc/src/main/resources/jeasyopc-2.3.2.zip b/OPC_Client_Jeasyopc/src/main/resources/jeasyopc-2.3.2.zip new file mode 100644 index 0000000..ea8b4d0 Binary files /dev/null and b/OPC_Client_Jeasyopc/src/main/resources/jeasyopc-2.3.2.zip differ