I'm using the example code provided with the jeasyopc, and I'm getting no problems with reading and writing tags only when the tags arrays.
I created a tag with 3 integers on the TOP OPC server that point to an array on my PLC and it is working fine with Matrikon.
The code is this:
try {
// Reading *
OpcItem responseItem = jopc.synchReadItem(group, item1);
System.out.println(responseItem);
System.out.println(Variant.getVariantName(responseItem.getDataType()) + ": " + responseItem.getValue());
/**/
/* Writing Word *
Variant varin = new Variant(1);
item1.setValue(varin);
/**/
/* Writing Array */
VariantList list = new VariantList(Variant.VT_UI2);
list.add(new Variant(1));
list.add(new Variant(2));
list.add(new Variant(3));
Variant varin = new Variant(list);
System.out.println("Original Variant type: " +
Variant.getVariantName(varin.getVariantType()) + ", " + varin);
item1.setValue(varin);
/**/
try {
jopc.synchWriteItem(group, item1);
} catch (SynchWriteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
I'm using VT_UI2 type because that's what I'm getting when I read the array and get the type:
Variant.getVariantName(varin.getVariantType()) + ", " + varin);
item1.setValue(varin);
but when I ran the example the result on the console is this:
Original Variant type: VT_ARRAY(VT_UI2), [1, 2, 3]
javafish.clients.opc.exception.SynchWriteException: Synchronous writing error.
at javafish.clients.opc.JOpc.synchWriteItem(JOpc.java:416)
at Main.main(Main.java:103)
I have tried different types li VT_UI1, VT_UI2 but the result is always the same excemption.
Thanks in advance
Ernesto Wiebe
Hello,
I am facing the similar problem of Synchronous reading or writing error. Did you get to resolve this issue?
Any help is appreciated.
Thank you,
Ameya Chandrayan