New bug in Write and Read
This commit is contained in:
parent
f014791721
commit
92dc482f10
137
myClient.c
137
myClient.c
@ -163,7 +163,55 @@ u32 UA_ReadList(long ConnectionHdl,u16 NodeHdlCount,long *NodeHdls,UANodeAdditio
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
void readTest(long ConnectionHdl,u16 NodeHdlCount,long *NodeHdls,u32 ErrorIDs[])
|
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;
|
UA_Client *c = (UA_Client*)ConnectionHdl;
|
||||||
int i;
|
int i;
|
||||||
@ -189,9 +237,87 @@ void readTest(long ConnectionHdl,u16 NodeHdlCount,long *NodeHdls,u32 ErrorIDs[])
|
|||||||
request.nodesToReadSize = 1;
|
request.nodesToReadSize = 1;
|
||||||
UA_ReadResponse response = UA_Client_Service_read(c, request);
|
UA_ReadResponse response = UA_Client_Service_read(c, request);
|
||||||
retval = response.responseHeader.serviceResult;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
// long connecthdl;
|
// long connecthdl;
|
||||||
@ -251,8 +377,13 @@ int main(int argc, char *argv[]) {
|
|||||||
UA_BrowseResponse_clear(&bResp);
|
UA_BrowseResponse_clear(&bResp);
|
||||||
|
|
||||||
UA_NodeGetHandleList(hdl,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,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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user