Compare commits
	
		
			1 Commits
		
	
	
		
			MonitoredI
			...
			NodeGetInf
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| a340e3fb02 | 
							
								
								
									
										529
									
								
								myClient.c
									
									
									
									
									
								
							
							
						
						
									
										529
									
								
								myClient.c
									
									
									
									
									
								
							| @@ -22,325 +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; |  | ||||||
| 	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; | 	UA_Client *c = (UA_Client*)ConnectionHdl; | ||||||
| 	int i; | 	if (c == NULL) { | ||||||
| 	u32 retval; |     	fprintf(stderr, "Invalid UA_Client pointer\n"); | ||||||
|  	UA_ReadValueId item[NodeHdlCount]; |     	return UA_STATUSCODE_BADUNEXPECTEDERROR; // 返回错误码 | ||||||
| 	if(NodeHdlCount>MAX_ELEMENTS_NODELIST){ |  | ||||||
| 		retval=0xA0000002; |  | ||||||
| 	} | 	} | ||||||
| 	else | 	u32 retval,ret=0; | ||||||
|     { |  | ||||||
|         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); |  | ||||||
|         } |  | ||||||
|         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; |  | ||||||
|                 } |  | ||||||
|                 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 |  | ||||||
| 						{ |  | ||||||
|   							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; |  | ||||||
|  |  | ||||||
| 								variables[i].type=res.value.type->typeId.identifier.numeric; | 	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 if(NodeAddInfos[i].AttributeID == UA_ATTRIBUTEID_NODECLASS) | 	u32 temp =outNodeClass; | ||||||
| 							{ | 	NodeInfo->NodeClass=temp; | ||||||
| 								//UA_NodeClass *out1; | 	UA_NodeClass_clear(&outNodeClass); | ||||||
| 								//memcpy(out1, (UA_NodeClass*)res.value.data, sizeof(UA_NodeClass)); |  | ||||||
| 								memcpy(variables[i].data,res.value.data,8); | 	UA_QualifiedName outBrowseName; | ||||||
| 								variables[i].type=UA_TYPES_NODECLASS; | 	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; | ||||||
| 	} | 	} | ||||||
| 							else if(UA_Variant_isScalar(&res.value)) | 	NodeInfo->BrowseName.NamespaceIndex=outBrowseName.namespaceIndex; | ||||||
| 							{ | 	NodeInfo->BrowseName.Name.length=outBrowseName.name.length; | ||||||
| 								//memcpy(&variables[i].data, &res.value.data, res.value.type->memSize); | 	NodeInfo->BrowseName.Name.data=outBrowseName.name.data; | ||||||
| 								//UA_free(res.value.data); | 	printf("\n\n %s \n\n",outBrowseName.name.data); | ||||||
| 								//res.value.data = 0; | 	UA_QualifiedName_clear(&outBrowseName); | ||||||
| 								variables[i].type=res.value.type->typeId.identifier.numeric; |  | ||||||
|  | 	UA_LocalizedText outDisplayName; | ||||||
|  | 	UA_LocalizedText_init(&outDisplayName); | ||||||
|  | 	retval=UA_Client_readDisplayNameAttribute(c,NODEID,&outDisplayName); | ||||||
|  | 	if(retval!=0){ | ||||||
|  | 		ErrorIDs[2]=retval; | ||||||
|  | 		ret=retval; | ||||||
| 	} | 	} | ||||||
| 							else | 	NodeInfo->DisplayName.Locale=outDisplayName.locale.data; | ||||||
| 							{ | 	NodeInfo->DisplayName.Text.length=outDisplayName.text.length; | ||||||
| 								retval = UA_STATUSCODE_BADUNEXPECTEDERROR; | 	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]; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 						} |  | ||||||
| 						UA_free(res.value.data);   //?????   need or not |  | ||||||
| 					} |  | ||||||
|                 }  //end for |  | ||||||
|             } |  | ||||||
|             else |  | ||||||
|             { |  | ||||||
|  |  | ||||||
|                 retval = UA_STATUSCODE_BADUNEXPECTEDERROR; | 	UA_Byte outAccessLevel; | ||||||
|             } | 	UA_Byte_init(&outAccessLevel); | ||||||
|         }//end if(retval == UA_STATUSCODE_GOOD) | 	retval=UA_Client_readAccessLevelAttribute(c,NODEID,&outAccessLevel); | ||||||
|       //  printf("------------#f8 --------------\n"); | 	if(retval!=0){ | ||||||
|         // UA_ReadResponse_clear(&response); | 		ErrorIDs[14]=retval; | ||||||
|  | 		ret=retval; | ||||||
| 	} | 	} | ||||||
|  | 	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; | ||||||
|  |  | ||||||
| u32 UA_WriteList(long ConnectionHdl,u16 NodeHdlCount,long *NodeHdls,UANodeAdditionalInfo *NodeAddInfos,UA_Value *variables,u32 ErrorIDs[]){ | 	UA_Double outMinSamplingInterval; | ||||||
| 	UA_Client *c = (UA_Client*)ConnectionHdl; | 	UA_Double_init(&outMinSamplingInterval); | ||||||
| 	int i; | 	retval=UA_Client_readMinimumSamplingIntervalAttribute(c,NODEID,&outMinSamplingInterval); | ||||||
| 	UA_StatusCode retval=0; | 	if(retval!=0){ | ||||||
| 	if(NodeHdlCount>MAX_ELEMENTS_NODELIST){ | 		ErrorIDs[16]=retval; | ||||||
| 		retval=0xA0000002; | 		ret=retval; | ||||||
| 		return retval; |  | ||||||
| 	} | 	} | ||||||
| 	//UA_NodeId NODEid= UA_NODEID_STRING(1, "A1.the anwser2"); | 	NodeInfo->MinimumSamplingInterval=outMinSamplingInterval; | ||||||
| 	//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; |  | ||||||
|  |  | ||||||
| 	UA_WriteResponse wResp = UA_Client_Service_write(c, wReq); | 	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; | ||||||
|  |  | ||||||
| 	retval = wResp.responseHeader.serviceResult; | 	UA_Boolean outExecutable; | ||||||
| 	if(retval==UA_STATUSCODE_GOOD){ | 	UA_Boolean_init(&outExecutable); | ||||||
| 		if(wResp.resultsSize==NodeHdlCount){ | 	retval=UA_Client_readExecutableAttribute(c,NODEID,&outExecutable); | ||||||
| 			for(i=0;i<NodeHdlCount;i++){ | 	if(retval!=0){ | ||||||
| 				ErrorIDs[i]=wResp.results[i]; | 		ErrorIDs[18]=retval; | ||||||
| 			} | 		//ret=retval; | ||||||
| 		}else{ |  | ||||||
| 			retval=UA_STATUSCODE_BADUNEXPECTEDERROR; |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 	UA_WriteRequest_clear(&wResp); |  | ||||||
| 	return retval; |  | ||||||
| 	} | 	} | ||||||
|  | 	NodeInfo->Executable=outExecutable; | ||||||
|  |  | ||||||
| void readTest(long ConnectionHdl,u16 NodeHdlCount,long *NodeHdls,UA_Value *variables,u32 ErrorIDs[]) | 	UA_Boolean outUserExecutable; | ||||||
| { | 	UA_Boolean_init(&outUserExecutable); | ||||||
|     UA_Client *c = (UA_Client*)ConnectionHdl; | 	retval=UA_Client_readUserExecutableAttribute(c,NODEID,&outUserExecutable); | ||||||
| 	int i; | 	if(retval!=0){ | ||||||
| 	u32 retval; | 		ErrorIDs[19]=retval; | ||||||
|  	UA_ReadValueId item[NodeHdlCount]; | 		//ret=retval; | ||||||
| 	if(NodeHdlCount>MAX_ELEMENTS_NODELIST){ |  | ||||||
| 		retval=0xA0000002; |  | ||||||
| 	} | 	} | ||||||
| 	else | 	NodeInfo->UserExecutable=outUserExecutable; | ||||||
|     { |  | ||||||
|         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 = 1; |  | ||||||
|         UA_ReadResponse response = UA_Client_Service_read(c, request); |  | ||||||
|         retval = response.responseHeader.serviceResult; |  | ||||||
|         if(retval == UA_STATUSCODE_GOOD) |  | ||||||
|         { |  | ||||||
|             printf("------------#3---------------\n"); |  | ||||||
|             printf("%d\n",response.resultsSize); |  | ||||||
|             if(response.resultsSize==NodeHdlCount) |  | ||||||
|             { |  | ||||||
|                 printf("------------#4---------------\n"); |  | ||||||
|                 for (i = 0; i < NodeHdlCount; i++) |  | ||||||
|                 { |  | ||||||
|                     ErrorIDs[i]=response.results[i].status; |  | ||||||
|                 } |  | ||||||
|                 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; | 	return ret; | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  |  | ||||||
| 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; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| u32 SubscriptionCreate(long ConnectionHdl,bool PublishingEnable,u16 Priority,long *SubscriptionHdl,TIME *PublishingInterval){ |  | ||||||
| 	UA_Client *c = (UA_Client*)ConnectionHdl; |  | ||||||
| 	UA_CreateSubscriptionRequest request = UA_CreateSubscriptionRequest_default(); |  | ||||||
| 	request.requestedPublishingInterval=*PublishingInterval; |  | ||||||
| 	request.publishingEnabled=PublishingEnable; |  | ||||||
| 	request.priority=Priority; |  | ||||||
| 	UA_CreateSubscriptionResponse *response=malloc(sizeof(UA_CreateSubscriptionResponse)); |  | ||||||
| 	*response = UA_Client_Subscriptions_create(c,request,NULL,NULL,NULL); |  | ||||||
| 	u32 retval=response[0].responseHeader.serviceResult; |  | ||||||
| 	if(retval!=UA_STATUSCODE_GOOD){ |  | ||||||
| 		UA_CreateSubscriptionResponse_clear(&response[0]); |  | ||||||
| 		return retval; |  | ||||||
| 	} |  | ||||||
| 	printf("response[0].subscripstionId is %x\n",response[0].subscriptionId); |  | ||||||
| 	*SubscriptionHdl=(long *)response[0].subscriptionId; |  | ||||||
| 	UA_CreateSubscriptionResponse_clear(&response[0]); |  | ||||||
| 	return retval; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| u32 UA_SubscriptionDelete(long ConnectionHdl,long SubscriptionHdl){ |  | ||||||
| 	UA_Client *c = (UA_Client*)ConnectionHdl; |  | ||||||
| 	u32 retval=UA_Client_Subscriptions_deleteSingle(c,SubscriptionHdl); |  | ||||||
| 	return retval; |  | ||||||
| } | } | ||||||
|  |  | ||||||
| int main(int argc, char *argv[]) { | int main(int argc, char *argv[]) { | ||||||
| @@ -385,12 +304,12 @@ int main(int argc, char *argv[]) { | |||||||
|                        (int)ref->displayName.text.length, ref->displayName.text.data); |                        (int)ref->displayName.text.length, ref->displayName.text.data); | ||||||
|             } |             } | ||||||
|  |  | ||||||
| 			printf("\n%lld\n\n",ref->nodeId.nodeId.identifier.numeric); | 			printf("%lld",ref->nodeId.nodeId.identifier.numeric); | ||||||
|  |  | ||||||
| 			nodes[j].Identifier.length = ref->nodeId.nodeId.identifier.string.length; | 			nodes[j].Identifier.length = ref->nodeId.nodeId.identifier.string.length; | ||||||
| 			if(nodes[j].Identifier.length > 0) { | 			if(nodes[j].Identifier.length > 0) { | ||||||
|     			nodes[j].Identifier.data = (u8*)malloc(nodes[j].Identifier.length); |     			nodes[j].Identifier.data = (u8*)malloc(nodes[j].Identifier.length); | ||||||
| 				snprintf(nodes[j].Identifier.data, 64, "%lld", (long long)ref->nodeId.nodeId.identifier.numeric); | 				snprintf(nodes[j].Identifier.data, nodes[j].Identifier.length, "%lld", (long long)ref->nodeId.nodeId.identifier.numeric); | ||||||
|     			 |     			 | ||||||
| 			} | 			} | ||||||
| 			nodes[j].IdentifierType = ref->nodeId.nodeId.identifierType; | 			nodes[j].IdentifierType = ref->nodeId.nodeId.identifierType; | ||||||
| @@ -401,14 +320,8 @@ int main(int argc, char *argv[]) { | |||||||
|     UA_BrowseRequest_clear(&bReq); |     UA_BrowseRequest_clear(&bReq); | ||||||
|     UA_BrowseResponse_clear(&bResp); |     UA_BrowseResponse_clear(&bResp); | ||||||
|  |  | ||||||
| 	UA_NodeGetHandleList(hdl,4,nodes,nodeHdls,errors); | 	UANodeInformation *nodeinfo = (UANodeInformation*)malloc(sizeof(UANodeInformation)); | ||||||
|     UA_Value *variables = (UA_Value*)malloc(4 * sizeof(UA_Value)); | 	UA_NodeGetInformation(hdl,nodes[1],nodeinfo,errors); | ||||||
| 	readTest(hdl,4,nodeHdls,variables,errors); |  | ||||||
|     for (int i = 0; i < 4; i++) |  | ||||||
|     { |  | ||||||
|         printf("%d\n",variables[i].type); |  | ||||||
|     } |  | ||||||
|      |  | ||||||
|  |  | ||||||
|     /* Clean up */ |     /* Clean up */ | ||||||
|     UA_Client_disconnect(client); |     UA_Client_disconnect(client); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user