Compare commits
	
		
			6 Commits
		
	
	
		
			NodeReleas
			...
			MonitoredI
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| c9370e53db | |||
| 2692cbfa14 | |||
| 92dc482f10 | |||
| f014791721 | |||
| d2290d43a7 | |||
| 26b2939a5c | 
							
								
								
									
										4
									
								
								UA_PLC.c
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								UA_PLC.c
									
									
									
									
									
								
							| @@ -233,9 +233,7 @@ u32 UA_NodeReleaseHandleList(long ConnectionHdl,u16 NodeHdlCount,long *NodeHdls, | |||||||
| 		return retval; | 		return retval; | ||||||
| 	} | 	} | ||||||
| 	for(i=0;i<NodeHdlCount;i++){ | 	for(i=0;i<NodeHdlCount;i++){ | ||||||
| 		//UA_NodeId nodeId = *(UA_NodeId*)NodeHdls[i]; | 		UA_NodeId nodeId = *(UA_NodeId*)NodeHdls[i]; | ||||||
| 		UA_NodeId *nodeId = (UA_NodeId*)NodeHdls[i]; |  | ||||||
| 		UA_NodeId_clear(nodeId); |  | ||||||
| 		NodeHdls[i]=0; | 		NodeHdls[i]=0; | ||||||
| 		//UA_NodeId_delete(&nodeId); | 		//UA_NodeId_delete(&nodeId); | ||||||
| 		ErrorIDs[i]=0; | 		ErrorIDs[i]=0; | ||||||
|   | |||||||
							
								
								
									
										297
									
								
								myClient.c
									
									
									
									
									
								
							
							
						
						
									
										297
									
								
								myClient.c
									
									
									
									
									
								
							| @@ -62,8 +62,285 @@ u32 UA_NodeGetHandleList(long ConnectionHdl,u16 NodeIDCount,UANodeID *NodeIDs,lo | |||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| void Browser(){ | u32 UA_ReadList(long ConnectionHdl,u16 NodeHdlCount,long *NodeHdls,UANodeAdditionalInfo *NodeAddInfos,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 = 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; | ||||||
|  |  | ||||||
|  | 							} | ||||||
|  | 							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; | ||||||
|  | 							} | ||||||
|  | 							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; | ||||||
|  | 							} | ||||||
|  | 							else | ||||||
|  | 							{ | ||||||
|  | 								retval = UA_STATUSCODE_BADUNEXPECTEDERROR; | ||||||
|  | 							} | ||||||
|  |  | ||||||
|  | 						} | ||||||
|  | 						UA_free(res.value.data);   //?????   need or not | ||||||
|  | 					} | ||||||
|  |                 }  //end for | ||||||
|  |             } | ||||||
|  |             else | ||||||
|  |             { | ||||||
|  |  | ||||||
|  |                 retval = UA_STATUSCODE_BADUNEXPECTEDERROR; | ||||||
|  |             } | ||||||
|  |         }//end if(retval == UA_STATUSCODE_GOOD) | ||||||
|  |       //  printf("------------#f8 --------------\n"); | ||||||
|  |         // UA_ReadResponse_clear(&response); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     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; | ||||||
|  | 	} | ||||||
|  | 	//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; | ||||||
|  |  | ||||||
|  | 	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[]) { | ||||||
| @@ -77,7 +354,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]; | ||||||
| @@ -108,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; | ||||||
| @@ -124,9 +401,15 @@ 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); | 	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); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |  | ||||||
| 	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); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user