error
This commit is contained in:
parent
8c9b73c2d3
commit
26b2939a5c
270
myClient.c
270
myClient.c
@ -22,48 +22,244 @@
|
|||||||
// return flag;
|
// return flag;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
u32 UA_NodeGetHandleList(long ConnectionHdl,u16 NodeIDCount,UANodeID *NodeIDs,long *NodeHdls,u32 ErrorIDs[]){
|
u32 UA_NodeGetInformation(long ConnectionHdl,UANodeID NodeID,UANodeInformation *NodeInfo,u32 ErrorIDs[]){
|
||||||
int i;
|
UA_Client *c = (UA_Client*)ConnectionHdl;
|
||||||
u32 retval=0;
|
if (c == NULL) {
|
||||||
UA_NodeId *NodeID=malloc(sizeof(UA_NodeId)*NodeIDCount);
|
fprintf(stderr, "Invalid UA_Client pointer\n");
|
||||||
if(NodeIDCount>MAX_ELEMENTS_NODELIST){
|
return UA_STATUSCODE_BADUNEXPECTEDERROR; // 返回错误码
|
||||||
retval=0xA0000002;
|
}
|
||||||
return retval;
|
u32 retval,ret=0;
|
||||||
|
|
||||||
|
printf("\n\n %s \n\n",NodeID.Identifier.data);
|
||||||
|
|
||||||
|
// UA_NodeId NODEID=UA_NODEID_STRING(NodeID.NamespaceIndex,NodeID.Identifier.data);
|
||||||
|
UA_NodeId NODEID=UA_NODEID_NUMERIC(NodeID.NamespaceIndex,NodeID.Identifier);
|
||||||
|
|
||||||
|
// NODEID.namespaceIndex = NodeID.NamespaceIndex;
|
||||||
|
// if(NodeID.IdentifierType>=0&&NodeID.IdentifierType<4){
|
||||||
|
// switch(NodeID.IdentifierType){
|
||||||
|
// case 0:NODEID.identifierType=0;
|
||||||
|
// case 1:NODEID.identifierType=3;
|
||||||
|
// case 2:NODEID.identifierType=4;
|
||||||
|
// case 3:NODEID.identifierType=5;
|
||||||
|
// }
|
||||||
|
// ret=0;
|
||||||
|
// }else{
|
||||||
|
// ret=0xA0000301;
|
||||||
|
// }
|
||||||
|
// NODEID.identifier.string = UA_STRING(NodeID.Identifier.data);
|
||||||
|
UA_NodeClass outNodeClass;
|
||||||
|
UA_NodeClass_init(&outNodeClass);
|
||||||
|
retval=UA_Client_readNodeClassAttribute(c,NODEID,&outNodeClass);
|
||||||
|
if(retval!=0){
|
||||||
|
ErrorIDs[0]=retval;
|
||||||
|
ret=retval;
|
||||||
|
}
|
||||||
|
u32 temp =outNodeClass;
|
||||||
|
NodeInfo->NodeClass=temp;
|
||||||
|
UA_NodeClass_clear(&outNodeClass);
|
||||||
|
|
||||||
|
UA_QualifiedName outBrowseName;
|
||||||
|
UA_QualifiedName_init(&outBrowseName);
|
||||||
|
retval=UA_Client_readBrowseNameAttribute(c,NODEID,&outBrowseName);
|
||||||
|
if(retval!=0){
|
||||||
|
fprintf(stderr, "Failed to read BrowseName: %s\n", UA_StatusCode_name(retval));
|
||||||
|
ErrorIDs[1]=retval;
|
||||||
|
ret=retval;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
NodeInfo->BrowseName.NamespaceIndex=outBrowseName.namespaceIndex;
|
||||||
|
NodeInfo->BrowseName.Name.length=outBrowseName.name.length;
|
||||||
|
NodeInfo->BrowseName.Name.data=outBrowseName.name.data;
|
||||||
|
printf("\n\n %s \n\n",outBrowseName.name.data);
|
||||||
|
UA_QualifiedName_clear(&outBrowseName);
|
||||||
|
|
||||||
|
UA_LocalizedText outDisplayName;
|
||||||
|
UA_LocalizedText_init(&outDisplayName);
|
||||||
|
retval=UA_Client_readDisplayNameAttribute(c,NODEID,&outDisplayName);
|
||||||
|
if(retval!=0){
|
||||||
|
ErrorIDs[2]=retval;
|
||||||
|
ret=retval;
|
||||||
|
}
|
||||||
|
NodeInfo->DisplayName.Locale=outDisplayName.locale.data;
|
||||||
|
NodeInfo->DisplayName.Text.length=outDisplayName.text.length;
|
||||||
|
NodeInfo->DisplayName.Text.data=outDisplayName.text.data;
|
||||||
|
UA_LocalizedText_clear(&outDisplayName);
|
||||||
|
|
||||||
|
UA_LocalizedText outDescription;
|
||||||
|
UA_LocalizedText_init(&outDescription);
|
||||||
|
retval=UA_Client_readDescriptionAttribute(c,NODEID,&outDescription);
|
||||||
|
if(retval!=0){
|
||||||
|
ErrorIDs[3]=retval;
|
||||||
|
ret=retval;
|
||||||
|
}
|
||||||
|
NodeInfo->Description.Locale=outDescription.locale.data;
|
||||||
|
NodeInfo->Description.Text.length=outDescription.text.length;
|
||||||
|
NodeInfo->Description.Text.data=outDescription.text.data;
|
||||||
|
UA_LocalizedText_clear(&outDescription);
|
||||||
|
|
||||||
|
UA_UInt32 outWriteMask;
|
||||||
|
UA_UInt32_init(&outWriteMask);
|
||||||
|
retval=UA_Client_readWriteMaskAttribute(c,NODEID,&outWriteMask);
|
||||||
|
if(retval!=0){
|
||||||
|
ErrorIDs[4]=retval;
|
||||||
|
ret=retval;
|
||||||
|
}
|
||||||
|
NodeInfo->WriteMask=outWriteMask;
|
||||||
|
UA_UInt32_clear(&outWriteMask);
|
||||||
|
|
||||||
|
UA_UInt32 outUserWriteMask;
|
||||||
|
UA_UInt32_init(&outUserWriteMask);
|
||||||
|
retval=UA_Client_readUserWriteMaskAttribute(c,NODEID,&outUserWriteMask);
|
||||||
|
if(retval!=0){
|
||||||
|
ErrorIDs[5]=retval;
|
||||||
|
ret=retval;
|
||||||
|
}
|
||||||
|
NodeInfo->UserWriteMask=outUserWriteMask;
|
||||||
|
UA_UInt32_clear(&outUserWriteMask);
|
||||||
|
|
||||||
|
UA_Boolean outIsAbstract;
|
||||||
|
UA_Boolean_init(&outIsAbstract);
|
||||||
|
retval=UA_Client_readIsAbstractAttribute(c,NODEID,&outIsAbstract);
|
||||||
|
if(retval!=0){
|
||||||
|
ErrorIDs[6]=retval;
|
||||||
|
//ret=retval;
|
||||||
|
}
|
||||||
|
NodeInfo->IsAbstract=outIsAbstract;
|
||||||
|
UA_Boolean_clear(&outIsAbstract);
|
||||||
|
|
||||||
|
UA_Boolean outSymmetric;
|
||||||
|
UA_Boolean_init(&outSymmetric);
|
||||||
|
retval=UA_Client_readSymmetricAttribute(c,NODEID,&outSymmetric);
|
||||||
|
if(retval!=0){
|
||||||
|
ErrorIDs[7]=retval;
|
||||||
|
//ret=retval;
|
||||||
|
}
|
||||||
|
NodeInfo->Symmetric=outSymmetric;
|
||||||
|
UA_Boolean_clear(&outSymmetric);
|
||||||
|
|
||||||
|
UA_LocalizedText outInverseName;
|
||||||
|
UA_LocalizedText_init(&outInverseName);
|
||||||
|
retval=UA_Client_readInverseNameAttribute(c,NODEID,&outInverseName);
|
||||||
|
if(retval!=0){
|
||||||
|
ErrorIDs[8]=retval;
|
||||||
|
//ret=retval;
|
||||||
|
}
|
||||||
|
NodeInfo->InverseName.length=outInverseName.text.length;
|
||||||
|
NodeInfo->InverseName.data=outInverseName.text.data;
|
||||||
|
UA_LocalizedText_clear(&outInverseName);
|
||||||
|
|
||||||
|
UA_Boolean outContainsNoLoops;
|
||||||
|
UA_Boolean_init(&outContainsNoLoops);
|
||||||
|
retval=UA_Client_readContainsNoLoopsAttribute(c,NODEID,&outContainsNoLoops);
|
||||||
|
if(retval!=0){
|
||||||
|
ErrorIDs[9]=retval;
|
||||||
|
//ret=retval;
|
||||||
|
}
|
||||||
|
NodeInfo->ContainsNoLoops=outContainsNoLoops;
|
||||||
|
UA_Boolean_clear(&outContainsNoLoops);
|
||||||
|
|
||||||
|
UA_Byte outEventNotifier;
|
||||||
|
UA_Byte_init(&outEventNotifier);
|
||||||
|
retval=UA_Client_readEventNotifierAttribute(c,NODEID,&outEventNotifier);
|
||||||
|
if(retval!=0){
|
||||||
|
ErrorIDs[10]=retval;
|
||||||
|
//ret=retval;
|
||||||
|
}
|
||||||
|
NodeInfo->EventNotifier=outEventNotifier;
|
||||||
|
UA_Byte_clear(&outEventNotifier);
|
||||||
|
|
||||||
|
UA_NodeId outDataType;
|
||||||
|
UA_NodeId_init(&outDataType);
|
||||||
|
retval=UA_Client_readDataTypeAttribute(c,NODEID,&outDataType);
|
||||||
|
if(retval!=0){
|
||||||
|
ErrorIDs[11]=retval;
|
||||||
|
ret=retval;
|
||||||
|
}
|
||||||
|
NodeInfo->DataType.NamespaceIndex=outDataType.namespaceIndex;
|
||||||
|
NodeInfo->DataType.IdentifierType=outDataType.identifierType;
|
||||||
|
NodeInfo->DataType.Identifier.length=outDataType.identifier.string.length;
|
||||||
|
NodeInfo->DataType.Identifier.data=outDataType.identifier.string.data;
|
||||||
|
UA_NodeId_clear(&outDataType);
|
||||||
|
|
||||||
|
UA_Int32 outValueRank;
|
||||||
|
UA_Int32_init(&outValueRank);
|
||||||
|
retval=UA_Client_readValueRankAttribute(c,NODEID,&outValueRank);
|
||||||
|
if(retval!=0){
|
||||||
|
ErrorIDs[12]=retval;
|
||||||
|
ret=retval;
|
||||||
|
}
|
||||||
|
NodeInfo->ValueRank=outValueRank;
|
||||||
|
UA_Int32_clear(&outValueRank);
|
||||||
|
|
||||||
|
UA_UInt32 outArrayDimensions[MAX_ELEMENTS_ARRAYDIMENSION];
|
||||||
|
//UA_UInt32_init(*outArrayDimensions);
|
||||||
|
int size;
|
||||||
|
retval=UA_Client_readArrayDimensionsAttribute(c,NODEID,&size,outArrayDimensions);
|
||||||
|
if(retval!=0){
|
||||||
|
ErrorIDs[13]=retval;
|
||||||
|
ret=retval;
|
||||||
|
}
|
||||||
|
for(int i=0;i<MAX_ELEMENTS_ARRAYDIMENSION;i++){
|
||||||
|
NodeInfo->ArrayDimension[i]=outArrayDimensions[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i=0;i<NodeIDCount;i++){
|
|
||||||
printf("\nNdeIDs[i].IdentifierType=%d,NodeIDs[i].NamespaceIndex=%d,NodeIDs[i].Identifier.length=%d, NodeIDs[i].Identifier.data=%s\n",
|
|
||||||
NodeIDs[i].IdentifierType, NodeIDs[i].NamespaceIndex, NodeIDs[i].Identifier.length ,NodeIDs[i].Identifier.data );
|
|
||||||
|
|
||||||
if(NodeIDs[i].IdentifierType>=0&&NodeIDs[i].IdentifierType<4){
|
UA_Byte outAccessLevel;
|
||||||
switch(NodeIDs[i].IdentifierType){
|
UA_Byte_init(&outAccessLevel);
|
||||||
case 0:NodeID[i]=UA_NODEID_NUMERIC(NodeIDs[i].NamespaceIndex,NodeIDs[i].Identifier.data);break;
|
retval=UA_Client_readAccessLevelAttribute(c,NODEID,&outAccessLevel);
|
||||||
case 1:NodeID[i]=UA_NODEID_STRING(NodeIDs[i].NamespaceIndex,NodeIDs[i].Identifier.data);break;
|
if(retval!=0){
|
||||||
case 2:NodeID[i].identifierType=4;
|
ErrorIDs[14]=retval;
|
||||||
NodeID[i].identifier.string.data=NodeIDs[i].Identifier.data;
|
ret=retval;
|
||||||
NodeID[i].identifier.string.length=NodeIDs[i].Identifier.length;
|
|
||||||
NodeID[i].namespaceIndex=NodeIDs[i].NamespaceIndex;break;
|
|
||||||
case 3:NodeID[i]=UA_NODEID_BYTESTRING(NodeIDs[i].NamespaceIndex,NodeIDs[i].Identifier.data);break;
|
|
||||||
}
|
|
||||||
ErrorIDs[i]=0;
|
|
||||||
}else{
|
|
||||||
ErrorIDs[i]=0xA0000301;
|
|
||||||
retval=ErrorIDs[i];
|
|
||||||
}
|
|
||||||
// NodeID[i].identifier.string.data=NodeIDs[i].Identifier.data;
|
|
||||||
// NodeID[i].identifier.string.length=NodeIDs[i].Identifier.length;
|
|
||||||
// NodeID[i].namespaceIndex=NodeIDs[i].NamespaceIndex;
|
|
||||||
NodeHdls[i]=&NodeID[i];
|
|
||||||
//UA_NodeId *NodeID1=malloc(sizeof(UA_NodeId)*NodeIDCount);
|
|
||||||
//UA_NodeId_delete(&NodeID[i]);
|
|
||||||
}
|
}
|
||||||
|
NodeInfo->AccessLevel=outAccessLevel;
|
||||||
|
|
||||||
return retval;
|
UA_Byte outUserAccessLevel;
|
||||||
|
UA_Byte_init(&outUserAccessLevel);
|
||||||
|
retval=UA_Client_readUserAccessLevelAttribute(c,NODEID,&outUserAccessLevel);
|
||||||
|
if(retval!=0){
|
||||||
|
ErrorIDs[15]=retval;
|
||||||
|
ret=retval;
|
||||||
|
}
|
||||||
|
NodeInfo->UserAccessLevel=outUserAccessLevel;
|
||||||
|
|
||||||
}
|
UA_Double outMinSamplingInterval;
|
||||||
|
UA_Double_init(&outMinSamplingInterval);
|
||||||
|
retval=UA_Client_readMinimumSamplingIntervalAttribute(c,NODEID,&outMinSamplingInterval);
|
||||||
|
if(retval!=0){
|
||||||
|
ErrorIDs[16]=retval;
|
||||||
|
ret=retval;
|
||||||
|
}
|
||||||
|
NodeInfo->MinimumSamplingInterval=outMinSamplingInterval;
|
||||||
|
|
||||||
void Browser(){
|
UA_Boolean outHistorizing;
|
||||||
|
UA_Boolean_init(&outHistorizing);
|
||||||
|
retval=UA_Client_readHistorizingAttribute(c,NODEID,&outHistorizing);
|
||||||
|
if(retval!=0){
|
||||||
|
ErrorIDs[17]=retval;
|
||||||
|
ret=retval;
|
||||||
|
}
|
||||||
|
NodeInfo->Historizing=outHistorizing;
|
||||||
|
|
||||||
|
UA_Boolean outExecutable;
|
||||||
|
UA_Boolean_init(&outExecutable);
|
||||||
|
retval=UA_Client_readExecutableAttribute(c,NODEID,&outExecutable);
|
||||||
|
if(retval!=0){
|
||||||
|
ErrorIDs[18]=retval;
|
||||||
|
//ret=retval;
|
||||||
|
}
|
||||||
|
NodeInfo->Executable=outExecutable;
|
||||||
|
|
||||||
|
UA_Boolean outUserExecutable;
|
||||||
|
UA_Boolean_init(&outUserExecutable);
|
||||||
|
retval=UA_Client_readUserExecutableAttribute(c,NODEID,&outUserExecutable);
|
||||||
|
if(retval!=0){
|
||||||
|
ErrorIDs[19]=retval;
|
||||||
|
//ret=retval;
|
||||||
|
}
|
||||||
|
NodeInfo->UserExecutable=outUserExecutable;
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
@ -77,7 +273,7 @@ int main(int argc, char *argv[]) {
|
|||||||
UA_Client_delete(client);
|
UA_Client_delete(client);
|
||||||
return (int)retval;
|
return (int)retval;
|
||||||
}
|
}
|
||||||
long *connecthdl = (long*)client;
|
long hdl = (long)client;
|
||||||
UANodeID nodes[4];
|
UANodeID nodes[4];
|
||||||
long nodeHdls[4] = {0};
|
long nodeHdls[4] = {0};
|
||||||
u32 errors[4];
|
u32 errors[4];
|
||||||
@ -124,9 +320,9 @@ int main(int argc, char *argv[]) {
|
|||||||
UA_BrowseRequest_clear(&bReq);
|
UA_BrowseRequest_clear(&bReq);
|
||||||
UA_BrowseResponse_clear(&bResp);
|
UA_BrowseResponse_clear(&bResp);
|
||||||
|
|
||||||
UA_NodeGetHandleList(*connecthdl,4,nodes,nodeHdls,errors);
|
UANodeInformation *nodeinfo = (UANodeInformation*)malloc(sizeof(UANodeInformation));
|
||||||
|
UA_NodeGetInformation(hdl,nodes[1],nodeinfo,errors);
|
||||||
|
|
||||||
printf("%d\n",nodeHdls[0]);
|
|
||||||
/* Clean up */
|
/* Clean up */
|
||||||
UA_Client_disconnect(client);
|
UA_Client_disconnect(client);
|
||||||
UA_Client_delete(client);
|
UA_Client_delete(client);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user