Compare commits
	
		
			5 Commits
		
	
	
		
			NodeGetInf
			...
			MonitoredI
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| c9370e53db | |||
| 2692cbfa14 | |||
| 92dc482f10 | |||
| f014791721 | |||
| d2290d43a7 | 
							
								
								
									
										529
									
								
								myClient.c
									
									
									
									
									
								
							
							
						
						
									
										529
									
								
								myClient.c
									
									
									
									
									
								
							| @@ -22,244 +22,325 @@ | |||||||
| // 	return flag; | // 	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; | 	UA_Client *c = (UA_Client*)ConnectionHdl; | ||||||
| 	if (c == NULL) { | 	int i; | ||||||
|     	fprintf(stderr, "Invalid UA_Client pointer\n"); | 	u32 retval; | ||||||
|     	return UA_STATUSCODE_BADUNEXPECTEDERROR; // 返回错误码 |  	UA_ReadValueId item[NodeHdlCount]; | ||||||
|  | 	if(NodeHdlCount>MAX_ELEMENTS_NODELIST){ | ||||||
|  | 		retval=0xA0000002; | ||||||
| 	} | 	} | ||||||
| 	u32 retval,ret=0; | 	else | ||||||
|  |     { | ||||||
| 	printf("\n\n %s \n\n",NodeID.Identifier.data); |         for(i=0;i<NodeHdlCount;i++){ | ||||||
|  |             UA_ReadValueId_init(&item[i]); | ||||||
| 	// UA_NodeId NODEID=UA_NODEID_STRING(NodeID.NamespaceIndex,NodeID.Identifier.data); |             item[i].nodeId = *(UA_NodeId*)NodeHdls[i]; | ||||||
| 	UA_NodeId NODEID=UA_NODEID_NUMERIC(NodeID.NamespaceIndex,NodeID.Identifier); |             //item[i].nodeId.identifier.numeric = NodeHdls[i];//zjy 20240910 | ||||||
| 	 |             item[i].attributeId = NodeAddInfos[i].AttributeID; | ||||||
| 	// NODEID.namespaceIndex = NodeID.NamespaceIndex; |             //item[i].nodeId.namespaceIndex = 1; | ||||||
| 	// if(NodeID.IdentifierType>=0&&NodeID.IdentifierType<4){ |             printf("------------#2------NodeHdls[i] = %ld ,item[i].nodeId = %d,item[i].attributeId=%d,item[i].nodeId.namespaceIndex=%d-\n", | ||||||
| 	// 		switch(NodeID.IdentifierType){ |                NodeHdls[i],item[i].nodeId.identifier.string.length,item[i].attributeId,item[i].nodeId.namespaceIndex); | ||||||
| 	// 			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; |         UA_ReadRequest request; | ||||||
| 	NodeInfo->NodeClass=temp; |         UA_ReadRequest_init(&request); | ||||||
| 	UA_NodeClass_clear(&outNodeClass); |         request.nodesToRead = &item[0]; | ||||||
|  |         request.nodesToReadSize = 1; | ||||||
| 	UA_QualifiedName outBrowseName; |         UA_ReadResponse response = UA_Client_Service_read(c, request); | ||||||
| 	UA_QualifiedName_init(&outBrowseName); |         retval = response.responseHeader.serviceResult; | ||||||
| 	retval=UA_Client_readBrowseNameAttribute(c,NODEID,&outBrowseName); |         if(retval == UA_STATUSCODE_GOOD) | ||||||
| 	if(retval!=0){ |         { | ||||||
| 		fprintf(stderr, "Failed to read BrowseName: %s\n", UA_StatusCode_name(retval)); |             printf("------------#3---------------\n"); | ||||||
| 		ErrorIDs[1]=retval; |             if(response.resultsSize==NodeHdlCount) | ||||||
| 		ret=retval; |             { | ||||||
| 		return ret; |                 printf("------------#4---------------\n"); | ||||||
|  |                 for (i = 0; i < NodeHdlCount; i++) | ||||||
|  |                 { | ||||||
|  |                     ErrorIDs[i]=response.results[i].status; | ||||||
|                 } |                 } | ||||||
| 	NodeInfo->BrowseName.NamespaceIndex=outBrowseName.namespaceIndex; |                 retval = 0 ; | ||||||
| 	NodeInfo->BrowseName.Name.length=outBrowseName.name.length; |                 for(i=0;i<NodeHdlCount;i++) | ||||||
| 	NodeInfo->BrowseName.Name.data=outBrowseName.name.data; |                 { | ||||||
| 	printf("\n\n %s \n\n",outBrowseName.name.data); |                     if(ErrorIDs[i]==UA_STATUSCODE_GOOD) | ||||||
| 	UA_QualifiedName_clear(&outBrowseName); |                     { | ||||||
|  |                         printf("------------#5---------------\n"); | ||||||
| 	UA_LocalizedText outDisplayName; |                         UA_DataValue res = response.results[i]; | ||||||
| 	UA_LocalizedText_init(&outDisplayName); |                         if(!res.hasValue) | ||||||
| 	retval=UA_Client_readDisplayNameAttribute(c,NODEID,&outDisplayName); |                         { | ||||||
| 	if(retval!=0){ |                             printf("------------#6---------------\n"); | ||||||
| 		ErrorIDs[2]=retval; |                             UA_ReadResponse_clear(&response); | ||||||
| 		ret=retval; |                             retval =  UA_STATUSCODE_BADUNEXPECTEDERROR; | ||||||
|                         } |                         } | ||||||
| 	NodeInfo->DisplayName.Locale=outDisplayName.locale.data; | 						else | ||||||
| 	NodeInfo->DisplayName.Text.length=outDisplayName.text.length; | 						{ | ||||||
| 	NodeInfo->DisplayName.Text.data=outDisplayName.text.data; |   							if(NodeAddInfos[i].AttributeID == UA_ATTRIBUTEID_VALUE) | ||||||
| 	UA_LocalizedText_clear(&outDisplayName); | 							{ | ||||||
|  |   								//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; | 								variables[i].type=res.value.type->typeId.identifier.numeric; | ||||||
| 	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; | 							else if(NodeAddInfos[i].AttributeID == UA_ATTRIBUTEID_NODECLASS) | ||||||
| 	UA_UInt32_clear(&outWriteMask); | 							{ | ||||||
|  | 								//UA_NodeClass *out1; | ||||||
| 	UA_UInt32 outUserWriteMask; | 								//memcpy(out1, (UA_NodeClass*)res.value.data, sizeof(UA_NodeClass)); | ||||||
| 	UA_UInt32_init(&outUserWriteMask); | 								memcpy(variables[i].data,res.value.data,8); | ||||||
| 	retval=UA_Client_readUserWriteMaskAttribute(c,NODEID,&outUserWriteMask); | 								variables[i].type=UA_TYPES_NODECLASS; | ||||||
| 	if(retval!=0){ |  | ||||||
| 		ErrorIDs[5]=retval; |  | ||||||
| 		ret=retval; |  | ||||||
| 							} | 							} | ||||||
| 	NodeInfo->UserWriteMask=outUserWriteMask; | 							else if(UA_Variant_isScalar(&res.value)) | ||||||
| 	UA_UInt32_clear(&outUserWriteMask); | 							{ | ||||||
|  | 								//memcpy(&variables[i].data, &res.value.data, res.value.type->memSize); | ||||||
| 	UA_Boolean outIsAbstract; | 								//UA_free(res.value.data); | ||||||
| 	UA_Boolean_init(&outIsAbstract); | 								//res.value.data = 0; | ||||||
| 	retval=UA_Client_readIsAbstractAttribute(c,NODEID,&outIsAbstract); | 								variables[i].type=res.value.type->typeId.identifier.numeric; | ||||||
| 	if(retval!=0){ |  | ||||||
| 		ErrorIDs[6]=retval; |  | ||||||
| 		//ret=retval; |  | ||||||
| 							} | 							} | ||||||
| 	NodeInfo->IsAbstract=outIsAbstract; | 							else | ||||||
| 	UA_Boolean_clear(&outIsAbstract); | 							{ | ||||||
|  | 								retval = UA_STATUSCODE_BADUNEXPECTEDERROR; | ||||||
| 	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_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_free(res.value.data);   //?????   need or not | ||||||
|  |  | ||||||
| 	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; |                 }  //end for | ||||||
|  |  | ||||||
| 	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; |             else | ||||||
|  |             { | ||||||
|  |  | ||||||
| 	UA_Boolean outHistorizing; |                 retval = UA_STATUSCODE_BADUNEXPECTEDERROR; | ||||||
| 	UA_Boolean_init(&outHistorizing); |  | ||||||
| 	retval=UA_Client_readHistorizingAttribute(c,NODEID,&outHistorizing); |  | ||||||
| 	if(retval!=0){ |  | ||||||
| 		ErrorIDs[17]=retval; |  | ||||||
| 		ret=retval; |  | ||||||
|             } |             } | ||||||
| 	NodeInfo->Historizing=outHistorizing; |         }//end if(retval == UA_STATUSCODE_GOOD) | ||||||
|  |       //  printf("------------#f8 --------------\n"); | ||||||
| 	UA_Boolean outExecutable; |         // UA_ReadResponse_clear(&response); | ||||||
| 	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; |     return retval; | ||||||
| 	UA_Boolean_init(&outUserExecutable); | } | ||||||
| 	retval=UA_Client_readUserExecutableAttribute(c,NODEID,&outUserExecutable); |  | ||||||
| 	if(retval!=0){ | u32 UA_WriteList(long ConnectionHdl,u16 NodeHdlCount,long *NodeHdls,UANodeAdditionalInfo *NodeAddInfos,UA_Value *variables,u32 ErrorIDs[]){ | ||||||
| 		ErrorIDs[19]=retval; | 	UA_Client *c = (UA_Client*)ConnectionHdl; | ||||||
| 		//ret=retval; | 	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 = 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; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | 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[]) { | ||||||
| @@ -304,12 +385,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("%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; | 			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, 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; | 			nodes[j].IdentifierType = ref->nodeId.nodeId.identifierType; | ||||||
| @@ -320,8 +401,14 @@ int main(int argc, char *argv[]) { | |||||||
|     UA_BrowseRequest_clear(&bReq); |     UA_BrowseRequest_clear(&bReq); | ||||||
|     UA_BrowseResponse_clear(&bResp); |     UA_BrowseResponse_clear(&bResp); | ||||||
|  |  | ||||||
| 	UANodeInformation *nodeinfo = (UANodeInformation*)malloc(sizeof(UANodeInformation)); | 	UA_NodeGetHandleList(hdl,4,nodes,nodeHdls,errors); | ||||||
| 	UA_NodeGetInformation(hdl,nodes[1],nodeinfo,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 */ |     /* Clean up */ | ||||||
|     UA_Client_disconnect(client); |     UA_Client_disconnect(client); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user