Compare commits
	
		
			4 Commits
		
	
	
		
			NodeGetInf
			...
			WriteAndRe
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 3a4c6ae05e | |||
| 92dc482f10 | |||
| f014791721 | |||
| d2290d43a7 | 
							
								
								
									
										509
									
								
								myClient.c
									
									
									
									
									
								
							
							
						
						
									
										509
									
								
								myClient.c
									
									
									
									
									
								
							| @@ -22,244 +22,305 @@ | ||||
| // 	return flag; | ||||
| // } | ||||
|  | ||||
| u32 UA_NodeGetInformation(long ConnectionHdl,UANodeID NodeID,UANodeInformation *NodeInfo,u32 ErrorIDs[]){ | ||||
| u32 UA_NodeGetHandleList(long ConnectionHdl,u16 NodeIDCount,UANodeID *NodeIDs,long *NodeHdls,u32 ErrorIDs[]){ | ||||
| 	int i; | ||||
| 	u32 retval=0; | ||||
| 	UA_NodeId *NodeID=malloc(sizeof(UA_NodeId)*NodeIDCount); | ||||
| 	if(NodeIDCount>MAX_ELEMENTS_NODELIST){ | ||||
| 		retval=0xA0000002; | ||||
| 		return retval; | ||||
| 	} | ||||
|  | ||||
| 	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){ | ||||
| 			switch(NodeIDs[i].IdentifierType){ | ||||
| 				case 0:NodeID[i]=UA_NODEID_NUMERIC(NodeIDs[i].NamespaceIndex,NodeIDs[i].Identifier.data);break; | ||||
| 				case 1:NodeID[i]=UA_NODEID_STRING(NodeIDs[i].NamespaceIndex,NodeIDs[i].Identifier.data);break; | ||||
| 				case 2:NodeID[i].identifierType=4; | ||||
| 						NodeID[i].identifier.string.data=NodeIDs[i].Identifier.data; | ||||
| 						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]); | ||||
| 	} | ||||
|  | ||||
| 	return retval; | ||||
|  | ||||
| } | ||||
|  | ||||
| u32 UA_ReadList(long ConnectionHdl,u16 NodeHdlCount,long *NodeHdls,UANodeAdditionalInfo *NodeAddInfos,UA_Value *variables,u32 ErrorIDs[]){ | ||||
| 	UA_Client *c = (UA_Client*)ConnectionHdl; | ||||
| 	if (c == NULL) { | ||||
|     	fprintf(stderr, "Invalid UA_Client pointer\n"); | ||||
|     	return UA_STATUSCODE_BADUNEXPECTEDERROR; // 返回错误码 | ||||
| 	int i; | ||||
| 	u32 retval; | ||||
|  	UA_ReadValueId item[NodeHdlCount]; | ||||
| 	if(NodeHdlCount>MAX_ELEMENTS_NODELIST){ | ||||
| 		retval=0xA0000002; | ||||
| 	} | ||||
| 	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,atoll(NodeID.Identifier.data)); | ||||
| 	 | ||||
| 	// 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; | ||||
| 	else | ||||
|     { | ||||
|         for(i=0;i<NodeHdlCount;i++){ | ||||
|             UA_ReadValueId_init(&item[i]); | ||||
|             item[i].nodeId = *(UA_NodeId*)NodeHdls[i]; | ||||
|             //item[i].nodeId.identifier.numeric = NodeHdls[i];//zjy 20240910 | ||||
|             item[i].attributeId = NodeAddInfos[i].AttributeID; | ||||
|             //item[i].nodeId.namespaceIndex = 1; | ||||
|             printf("------------#2------NodeHdls[i] = %ld ,item[i].nodeId = %d,item[i].attributeId=%d,item[i].nodeId.namespaceIndex=%d-\n", | ||||
|                NodeHdls[i],item[i].nodeId.identifier.string.length,item[i].attributeId,item[i].nodeId.namespaceIndex); | ||||
|         } | ||||
| 	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; | ||||
|         UA_ReadRequest request; | ||||
|         UA_ReadRequest_init(&request); | ||||
|         request.nodesToRead = &item[0]; | ||||
|         request.nodesToReadSize = 1; | ||||
|         UA_ReadResponse response = UA_Client_Service_read(c, request); | ||||
|         retval = response.responseHeader.serviceResult; | ||||
|         if(retval == UA_STATUSCODE_GOOD) | ||||
|         { | ||||
|             printf("------------#3---------------\n"); | ||||
|             if(response.resultsSize==NodeHdlCount) | ||||
|             { | ||||
|                 printf("------------#4---------------\n"); | ||||
|                 for (i = 0; i < NodeHdlCount; i++) | ||||
|                 { | ||||
|                     ErrorIDs[i]=response.results[i].status; | ||||
|                 } | ||||
| 	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; | ||||
|                 retval = 0 ; | ||||
|                 for(i=0;i<NodeHdlCount;i++) | ||||
|                 { | ||||
|                     if(ErrorIDs[i]==UA_STATUSCODE_GOOD) | ||||
|                     { | ||||
|                         printf("------------#5---------------\n"); | ||||
|                         UA_DataValue res = response.results[i]; | ||||
|                         if(!res.hasValue) | ||||
|                         { | ||||
|                             printf("------------#6---------------\n"); | ||||
|                             UA_ReadResponse_clear(&response); | ||||
|                             retval =  UA_STATUSCODE_BADUNEXPECTEDERROR; | ||||
|                         } | ||||
| 	NodeInfo->DisplayName.Locale=outDisplayName.locale.data; | ||||
| 	NodeInfo->DisplayName.Text.length=outDisplayName.text.length; | ||||
| 	NodeInfo->DisplayName.Text.data=outDisplayName.text.data; | ||||
| 	UA_LocalizedText_clear(&outDisplayName); | ||||
| 						else | ||||
| 						{ | ||||
|   							if(NodeAddInfos[i].AttributeID == UA_ATTRIBUTEID_VALUE) | ||||
| 							{ | ||||
|   								//UA_Variant *out=malloc(sizeof(UA_Variant)); | ||||
| 								UA_Variant out; | ||||
| 								//memcpy(&out, &res.value, sizeof(UA_Variant)); | ||||
| 								//UA_Variant_init(&res.value); | ||||
| 								//variables[i].data =res.value.data; | ||||
| 								long temp ; | ||||
| 								memcpy(&temp,res.value.data,8); | ||||
| 								variables[i].data = (void *)temp; | ||||
|  | ||||
| 	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); | ||||
| 								variables[i].type=res.value.type->typeId.identifier.numeric; | ||||
|  | ||||
| 	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; | ||||
| 							else if(NodeAddInfos[i].AttributeID == UA_ATTRIBUTEID_NODECLASS) | ||||
| 							{ | ||||
| 								//UA_NodeClass *out1; | ||||
| 								//memcpy(out1, (UA_NodeClass*)res.value.data, sizeof(UA_NodeClass)); | ||||
| 								memcpy(variables[i].data,res.value.data,8); | ||||
| 								variables[i].type=UA_TYPES_NODECLASS; | ||||
| 							} | ||||
| 	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; | ||||
| 							else if(UA_Variant_isScalar(&res.value)) | ||||
| 							{ | ||||
| 								//memcpy(&variables[i].data, &res.value.data, res.value.type->memSize); | ||||
| 								//UA_free(res.value.data); | ||||
| 								//res.value.data = 0; | ||||
| 								variables[i].type=res.value.type->typeId.identifier.numeric; | ||||
| 							} | ||||
| 	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]; | ||||
| 							else | ||||
| 							{ | ||||
| 								retval = UA_STATUSCODE_BADUNEXPECTEDERROR; | ||||
| 							} | ||||
|  | ||||
|  | ||||
| 	UA_Byte outAccessLevel; | ||||
| 	UA_Byte_init(&outAccessLevel); | ||||
| 	retval=UA_Client_readAccessLevelAttribute(c,NODEID,&outAccessLevel); | ||||
| 	if(retval!=0){ | ||||
| 		ErrorIDs[14]=retval; | ||||
| 		ret=retval; | ||||
| 						} | ||||
| 	NodeInfo->AccessLevel=outAccessLevel; | ||||
|  | ||||
| 	UA_Byte outUserAccessLevel; | ||||
| 	UA_Byte_init(&outUserAccessLevel); | ||||
| 	retval=UA_Client_readUserAccessLevelAttribute(c,NODEID,&outUserAccessLevel); | ||||
| 	if(retval!=0){ | ||||
| 		ErrorIDs[15]=retval; | ||||
| 		ret=retval; | ||||
| 						UA_free(res.value.data);   //?????   need or not | ||||
| 					} | ||||
| 	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; | ||||
|                 }  //end for | ||||
|             } | ||||
| 	NodeInfo->MinimumSamplingInterval=outMinSamplingInterval; | ||||
|             else | ||||
|             { | ||||
|  | ||||
| 	UA_Boolean outHistorizing; | ||||
| 	UA_Boolean_init(&outHistorizing); | ||||
| 	retval=UA_Client_readHistorizingAttribute(c,NODEID,&outHistorizing); | ||||
| 	if(retval!=0){ | ||||
| 		ErrorIDs[17]=retval; | ||||
| 		ret=retval; | ||||
|                 retval = UA_STATUSCODE_BADUNEXPECTEDERROR; | ||||
|             } | ||||
| 	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; | ||||
|         }//end if(retval == UA_STATUSCODE_GOOD) | ||||
|       //  printf("------------#f8 --------------\n"); | ||||
|         // UA_ReadResponse_clear(&response); | ||||
|     } | ||||
| 	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; | ||||
|     return retval; | ||||
| } | ||||
|  | ||||
| u32 UA_WriteList(long ConnectionHdl,u16 NodeHdlCount,long *NodeHdls,UANodeAdditionalInfo *NodeAddInfos,UA_Value *variables,u32 ErrorIDs[]){ | ||||
| 	UA_Client *c = (UA_Client*)ConnectionHdl; | ||||
| 	int i; | ||||
| 	UA_StatusCode retval=0; | ||||
| 	if(NodeHdlCount>MAX_ELEMENTS_NODELIST){ | ||||
| 		retval=0xA0000002; | ||||
| 		return retval; | ||||
| 	} | ||||
| 	NodeInfo->UserExecutable=outUserExecutable; | ||||
| 	//UA_NodeId NODEid= UA_NODEID_STRING(1, "A1.the anwser2"); | ||||
| 	//UA_Client_writeValueAttribute(c,NODEid,&in); | ||||
| 	UA_WriteValue wValue[NodeHdlCount]; | ||||
| 	for(i=0;i<NodeHdlCount;i++){ | ||||
| 		UA_WriteValue_init(&wValue[i]); | ||||
| 	 	wValue[i].nodeId = *(UA_NodeId*)NodeHdls[i]; | ||||
| 	 	//wValue[i].nodeId = NODEid; | ||||
| 	 	wValue[i].attributeId = NodeAddInfos[i].AttributeID; | ||||
| 	 	if(NodeAddInfos[i].AttributeID == UA_ATTRIBUTEID_VALUE){ | ||||
| 	 		UA_Variant in; | ||||
| 			UA_Variant_init(&in); | ||||
| 			UA_Variant_setScalar(&in,variables[i].data,&UA_TYPES[variables[i].type-1]); | ||||
|          	wValue[i].value.value = in; | ||||
| 			wValue[i].value.hasValue = true; | ||||
| 	 	} | ||||
| 	 	else{ | ||||
| 	 		UA_Variant_setScalar(&wValue[i].value.value, (void*)(uintptr_t)variables[i].data, &UA_TYPES[variables[i].type-1]); | ||||
| 		} | ||||
| 	} | ||||
| 	UA_WriteRequest wReq; | ||||
| 	UA_WriteRequest_init(&wReq); | ||||
| 	wReq.nodesToWrite = &wValue[0]; | ||||
| 	wReq.nodesToWriteSize = NodeHdlCount; | ||||
|  | ||||
| 	return ret; | ||||
| 	UA_WriteResponse wResp = UA_Client_Service_write(c, wReq); | ||||
|  | ||||
| 	retval = wResp.responseHeader.serviceResult; | ||||
| 	if(retval==UA_STATUSCODE_GOOD){ | ||||
| 		if(wResp.resultsSize==NodeHdlCount){ | ||||
| 			for(i=0;i<NodeHdlCount;i++){ | ||||
| 				ErrorIDs[i]=wResp.results[i]; | ||||
| 			} | ||||
| 		}else{ | ||||
| 			retval=UA_STATUSCODE_BADUNEXPECTEDERROR; | ||||
| 		} | ||||
| 	} | ||||
| 	UA_WriteRequest_clear(&wResp); | ||||
| 	return retval; | ||||
| } | ||||
|  | ||||
| void readTest(long ConnectionHdl,u16 NodeHdlCount,long *NodeHdls,UA_Value *variables,u32 ErrorIDs[]) | ||||
| { | ||||
|     UA_Client *c = (UA_Client*)ConnectionHdl; | ||||
| 	int i; | ||||
| 	u32 retval; | ||||
|  	UA_ReadValueId item[NodeHdlCount]; | ||||
| 	if(NodeHdlCount>MAX_ELEMENTS_NODELIST){ | ||||
| 		retval=0xA0000002; | ||||
| 	} | ||||
| 	else | ||||
|     { | ||||
|         for(i=0;i<NodeHdlCount;i++){ | ||||
|             UA_ReadValueId_init(&item[i]); | ||||
|             item[i].nodeId = *(UA_NodeId*)NodeHdls[i]; | ||||
|             //item[i].nodeId.identifier.numeric = NodeHdls[i];//zjy 20240910 | ||||
|             item[i].attributeId = 1; | ||||
|             //item[i].nodeId.namespaceIndex = 1; | ||||
|             printf("------------#2------NodeHdls[i] = %ld ,item[i].nodeId = %d,item[i].attributeId=%d,item[i].nodeId.namespaceIndex=%d-\n", | ||||
|                NodeHdls[i],item[i].nodeId.identifier.string.length,item[i].attributeId,item[i].nodeId.namespaceIndex); | ||||
|         } | ||||
|         UA_ReadRequest request; | ||||
|         UA_ReadRequest_init(&request); | ||||
|         request.nodesToRead = &item[0]; | ||||
|         request.nodesToReadSize = NodeHdlCount; | ||||
|         UA_ReadResponse response = UA_Client_Service_read(c, request); | ||||
|         retval = response.responseHeader.serviceResult; | ||||
|         if(retval == UA_STATUSCODE_GOOD) | ||||
|         { | ||||
|             printf("------------#3---------------\n"); | ||||
|             if(response.resultsSize==NodeHdlCount) | ||||
|             { | ||||
|                 printf("------------#4---------------\n"); | ||||
|                 for (i = 0; i < NodeHdlCount; i++) | ||||
|                 { | ||||
|                     ErrorIDs[i]=response.results[i].status; | ||||
|                 } | ||||
|                 for (int i = 0; i < NodeHdlCount; i++) | ||||
|                 { | ||||
|                     printf("%d",ErrorIDs[i]); | ||||
|                     printf("\n"); | ||||
|                 } | ||||
|                  | ||||
|                 retval = 0 ; | ||||
|                 for(i=0;i<NodeHdlCount;i++) | ||||
|                 { | ||||
|                     if(ErrorIDs[i]==UA_STATUSCODE_GOOD) | ||||
|                     { | ||||
|                         printf("------------#5---------------\n"); | ||||
|                         UA_DataValue res = response.results[i]; | ||||
|                         if(!res.hasValue) | ||||
|                         { | ||||
|                             printf("------------#6---------------\n"); | ||||
|                             UA_ReadResponse_clear(&response); | ||||
|                             retval =  UA_STATUSCODE_BADUNEXPECTEDERROR; | ||||
|                         } | ||||
| 						else | ||||
| 						{ | ||||
|   							memcpy(variables[i].data,res.value.data,8); | ||||
| 							variables[i].type=UA_TYPES_NODECLASS; | ||||
| 						} | ||||
| 						UA_free(res.value.data);   //?????   need or not | ||||
| 					} | ||||
|                 }  //end for | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|  | ||||
|                 retval = UA_STATUSCODE_BADUNEXPECTEDERROR; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| void writeTest(long ConnectionHdl,u16 NodeHdlCount,long *NodeHdls,UA_Value *variables,u32 ErrorIDs[]){ | ||||
|     UA_Client *c = (UA_Client*)ConnectionHdl; | ||||
| 	int i; | ||||
| 	UA_StatusCode retval=0; | ||||
| 	if(NodeHdlCount>MAX_ELEMENTS_NODELIST){ | ||||
| 		retval=0xA0000002; | ||||
| 		return retval; | ||||
| 	} | ||||
| 	//UA_NodeId NODEid= UA_NODEID_STRING(1, "A1.the anwser2"); | ||||
| 	//UA_Client_writeValueAttribute(c,NODEid,&in); | ||||
| 	UA_WriteValue wValue[NodeHdlCount]; | ||||
| 	for(i=0;i<NodeHdlCount;i++){ | ||||
| 		UA_WriteValue_init(&wValue[i]); | ||||
| 	 	wValue[i].nodeId = *(UA_NodeId*)NodeHdls[i]; | ||||
| 	 	//wValue[i].nodeId = NODEid; | ||||
| 	 	wValue[i].attributeId = 1; | ||||
| 	 	UA_Variant_setScalar(&wValue[i].value.value, (void*)(uintptr_t)variables[i].data, &UA_TYPES[variables[i].type-1]); | ||||
| 	} | ||||
| 	UA_WriteRequest wReq; | ||||
| 	UA_WriteRequest_init(&wReq); | ||||
| 	wReq.nodesToWrite = &wValue[0]; | ||||
| 	wReq.nodesToWriteSize = NodeHdlCount; | ||||
|  | ||||
| 	UA_WriteResponse wResp = UA_Client_Service_write(c, wReq); | ||||
|  | ||||
| 	retval = wResp.responseHeader.serviceResult; | ||||
| 	if(retval==UA_STATUSCODE_GOOD){ | ||||
| 		if(wResp.resultsSize==NodeHdlCount){ | ||||
| 			for(i=0;i<NodeHdlCount;i++){ | ||||
| 				ErrorIDs[i]=wResp.results[i]; | ||||
| 			} | ||||
| 		}else{ | ||||
| 			retval=UA_STATUSCODE_BADUNEXPECTEDERROR; | ||||
| 		} | ||||
| 	} | ||||
| 	UA_WriteRequest_clear(&wResp); | ||||
| 	return retval; | ||||
| } | ||||
|  | ||||
| int main(int argc, char *argv[]) { | ||||
| @@ -304,12 +365,12 @@ int main(int argc, char *argv[]) { | ||||
|                        (int)ref->displayName.text.length, ref->displayName.text.data); | ||||
|             } | ||||
|  | ||||
| 			printf("%lld",ref->nodeId.nodeId.identifier.numeric); | ||||
| 			printf("\n%lld\n\n",ref->nodeId.nodeId.identifier.numeric); | ||||
|  | ||||
| 			nodes[j].Identifier.length = ref->nodeId.nodeId.identifier.string.length; | ||||
| 			if(nodes[j].Identifier.length > 0) { | ||||
|     			nodes[j].Identifier.data = (u8*)malloc(nodes[j].Identifier.length); | ||||
| 				snprintf(nodes[j].Identifier.data, nodes[j].Identifier.length, "%lld", (long long)ref->nodeId.nodeId.identifier.numeric); | ||||
| 				snprintf(nodes[j].Identifier.data, 64, "%lld", (long long)ref->nodeId.nodeId.identifier.numeric); | ||||
|     			 | ||||
| 			} | ||||
| 			nodes[j].IdentifierType = ref->nodeId.nodeId.identifierType; | ||||
| @@ -320,8 +381,14 @@ int main(int argc, char *argv[]) { | ||||
|     UA_BrowseRequest_clear(&bReq); | ||||
|     UA_BrowseResponse_clear(&bResp); | ||||
|  | ||||
| 	UANodeInformation *nodeinfo = (UANodeInformation*)malloc(sizeof(UANodeInformation)); | ||||
| 	UA_NodeGetInformation(hdl,nodes[1],nodeinfo,errors); | ||||
| 	UA_NodeGetHandleList(hdl,4,nodes,nodeHdls,errors); | ||||
|     UA_Value *variables = (UA_Value*)malloc(4 * sizeof(UA_Value)); | ||||
| 	readTest(hdl,4,nodeHdls,variables,errors); | ||||
|     for (int i = 0; i < 4; i++) | ||||
|     { | ||||
|         printf("%d\n",variables[i].type); | ||||
|     } | ||||
|      | ||||
|  | ||||
|     /* Clean up */ | ||||
|     UA_Client_disconnect(client); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user