20:02, EEST
August 7, 2018
Hi,
I am having a problem in order to pass parameters to a method in the client, this is my code:
public Object GetSerialNumbers(UUID messageID, UUID correlationID, String initiatorID, String partnerID, //————————–Here I receive all parameters fine
String[][] extensionParametersStr, String requestedQuantityStr, String outputFormatStr, String poolID,
String gTIN, String sSCCGCP, String sSCCExtension, String germanyIFA, String franceCIP,
String spainNationalCode, String aNVISARegistryNumber, String location, String subLocation,
String lotNumber) {
KeyValuePairDataType[] extensionParameters = new KeyValuePairDataType[extensionParametersStr.length];
for (int i = 0; i < extensionParametersStr.length; i++) {
String[] parameter = extensionParametersStr[i];
Object var = new Object();
var = parameter[1];
extensionParameters[i] = new KeyValuePairDataType(parameter[0], var); //———————–Here I convert the data into KeyValuePairDataType
}
System.out.println("Extension Parameters en el cliente 1= " + extensionParameters[0].getKey() + ": " // ——————————— Print the data OK
+ extensionParameters[0].getValue());
System.out.println("Extension Parameters en el cliente 2= " + extensionParameters[1].getKey() + ": "
+ extensionParameters[1].getValue());
System.out.println("Extension Parameters en el cliente 1= " + extensionParameters[2].getKey() + ": "
+ extensionParameters[2].getValue());
System.out.println("Extension Parameters en el cliente 2= " + extensionParameters[3].getKey() + ": "
+ extensionParameters[3].getValue());
UnsignedInteger requestedQuantity = new UnsignedInteger(requestedQuantityStr);
SIDFormatEnum outputFormat = (outputFormatStr.compareToIgnoreCase("serialonly") == 0) ? SIDFormatEnum.SERIALONLY
: SIDFormatEnum.SERIALONLY;
HeaderDataType headerInput = new HeaderDataType(messageID, correlationID, initiatorID, partnerID,
extensionParameters);
PoolSelectorDataType poolSelector = new PoolSelectorDataType(poolID, gTIN, sSCCGCP, sSCCExtension, germanyIFA,
franceCIP, spainNationalCode, aNVISARegistryNumber, location, subLocation, lotNumber,
extensionParameters);
GetSerialNumbersInputDataType bodyInput = new GetSerialNumbersInputDataType(requestedQuantity, poolSelector,
outputFormat);
return GetSerialNumbers(headerInput, bodyInput);
}
//——————————- GetSerialNumbers——————————————————-
public Object GetSerialNumbers(HeaderDataType headerInput, GetSerialNumbersInputDataType bodyInput) {
client.registerModel(ClientInformationModel.MODEL);
SerialNumbersManagerTypeImpl serialNumbersManager = new SerialNumbersManagerTypeImpl(new AddressSpace(client),
new NodeId(2, 44), new QualifiedName(2, "SerialNumbersManager"),
new LocalizedText("SerialNumbersManager"));
GetSerialNumbersMethodOutputs outputs;
try {
outputs = serialNumbersManager.getSerialNumbers(headerInput, bodyInput); //————Here call the method getSerialNumbers with the parameters OK
Hashtable resultTable = new Hashtable();
resultTable.put(“MessageID”, outputs.getHeaderOutput().getMessageID());
resultTable.put(“CorrelationID”, outputs.getHeaderOutput().getCorrelationID());
resultTable.put(“PoolID”, outputs.getBodyOutput().getPoolID());
resultTable.put(“OutputFormat”, outputs.getBodyOutput().getOutputFormat().toString());
resultTable.put(“RequestToken”, outputs.getBodyOutput().getRequestToken().toString());
resultTable.put(“ReturnedQuantity”, outputs.getBodyOutput().getReturnedQuantity().toString());
resultTable.put(“SerialNumbers”, outputs.getBodyOutput().getSerialNumbers());
resultTable.put(“FirstSerial”, outputs.getBodyOutput().getFirstSerial());
resultTable.put(“LastSerial”, outputs.getBodyOutput().getLastSerial());
resultTable.put(“MessageID”, outputs.getFunctionalResult().toString());
System.out.println(Arrays.toString(outputs.getBodyOutput().getSerialNumbers()));
return resultTable;
} catch (MethodCallStatusException | ServiceException e) {
e.printStackTrace();
}
return null;
}
//——————————————getSerialNumbers——————————————
@Override
public SerialNumbersManagerType.GetSerialNumbersMethodOutputs getSerialNumbers(HeaderDataType headerInput,
GetSerialNumbersInputDataType bodyInput) throws MethodCallStatusException, ServiceException {
KeyValuePairDataType[] extensionParameters = headerInput.getExtensionParameters(); // ———————– Here I receive the parameters OK
System.out.println(“Extensions= ” + extensionParameters[0].getKey() + “: ” + extensionParameters[0].getValue()); // ——————- Print the parameters OK
System.out.println(“Extensions= ” + extensionParameters[1].getKey() + “: ” + extensionParameters[1].getValue());
System.out.println(“Extensions= ” + extensionParameters[2].getKey() + “: ” + extensionParameters[2].getValue());
System.out.println(“Extensions= ” + extensionParameters[3].getKey() + “: ” + extensionParameters[3].getValue());
NodeId methodId = new NodeId(2, 45);
return call(methodId, new MethodArgumentTransformer() { // —- In this line is the error!!!
@Override
public SerialNumbersManagerType.GetSerialNumbersMethodOutputs fromVariantArray(Variant[] values) {
return new SerialNumbersManagerType.GetSerialNumbersMethodOutputs((HeaderDataType) values[0].getValue(),
(GetSerialNumbersOutputDataType) values[1].getValue(),
(FunctionalResultEnum) values[2].asEnum(FunctionalResultEnum.class));
}
}, (Object) headerInput, (Object) bodyInput);
}
And this is the error: ServiceResult=Bad_EncodingError (0x80060000) “Encoding halted because of invalid data in the objects being serialized.”
I do not know how do I have to send the values in the headerInput, to catch all the extensionParameters on my OPCUA Server.
Thank you!
10:57, EEST
April 3, 2012
Hi,
Well first of all, does it compile?
Is this your own model or a “well known model”?
Assuming the KeyValuePair is not your own type (but the standard information model one), it wont compile/work until the SDK has UA 1.04 information model support, as that type is added in UA 1.04. That will happen at some point during this year with SDK 4.x, hopefully we will start some kind of public beta for it soon.
20:44, EEST
August 7, 2018
10:33, EEST
April 17, 2013
Hi,
I assume you have used the code generator of Prosys OPC UA Java SDK to create Java classes corresponding to the information model in UaNodeSet2 XML format.
Have you also called UaClient.registerModel method to register the classes to the client application? Basically not calling the registerModel might lead to this encoding issue. See Client SDK Tutorial document, chapter 18.4. Using Instances of Generated Types.
Furthermore, do you think you could send the XML model to us by email? This way we can check the file and reproduce this issue ourself. Correct address would be uajava-support@prosysopc.com
23:54, EEST
August 7, 2018
Hi,
Yes, I used code generator of Prosys OPC UA Java SDK to create Java Classes.
No, I don’t call UaClient.registerModel method.
I sent you the XML model, from carlos.gonzalez@beeond.net email.
Thank you!
16:18, EEST
April 17, 2013
0:56, EEST
August 7, 2018
Hi,
In fact, yes, I am calling UaClient.registerModel method, but still get the same error. Actually the call is in the first topic on this ticket where I put all the code.. On the //——————————- GetSerialNumbers——————————————————-
public Object GetSerialNumbers(HeaderDataType headerInput, GetSerialNumbersInputDataType bodyInput) {
client.registerModel(ClientInformationModel.MODEL);
I am calling the method, but still get the same error.
Also, I resolved the “references issues” of the NodeSet file, I generated the Java Class again, and I am getting the same error..
Most Users Ever Online: 1919
Currently Online:
18 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Heikki Tahvanainen: 402
hbrackel: 144
rocket science: 88
pramanj: 86
Francesco Zambon: 83
Ibrahim: 78
Sabari: 62
kapsl: 57
gjevremovic: 49
Xavier: 43
Member Stats:
Guest Posters: 0
Members: 730
Moderators: 7
Admins: 1
Forum Stats:
Groups: 3
Forums: 15
Topics: 1529
Posts: 6471
Newest Members:
rondawolinski7, Marypof5711, roycedelargie91, kourtneyquisenbe, ellis87832073466, zkxwilliemae, gabriellabachus, Deakin, KTP25Zof, Wojciech KubalaModerators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1032, Jimmy Ni: 26, Matti Siponen: 349, Lusetti: 0
Administrators: admin: 1