open62541 and HOLDING_REGISTR

12 views
Skip to first unread message

Акакий Бездрищенко

unread,
Feb 2, 2026, 2:37:28 PM (6 days ago) Feb 2
to open62541
Hello guys! I'm trying to read tags from MasterOPC using the open62541 C library in Visual Studio. Here's how:
  int main(void)
 { 
   UA_Client *client = UA_Client_new();       UA_ClientConfig_setDefault(UA_Client_getConfig(client));
 const char *endpoint = "opc.tcp://localhost:4840";
 UA_StatusCode retval = UA_Client_connect(client, endpoint);
 if(retval != UA_STATUSCODE_GOOD)
 {
 printf("Failed to connect: %s (0x%08x)\n", UA_StatusCode_name(retval), retval); UA_Client_delete(client); 
return (int)retval;
 } 
printf("Connected to %s\n", endpoint);
 UA_NodeId nodeId = UA_NODEID_STRING(1, "Channel1.Device1.TagName"); 
UA_Variant value; UA_Variant_init(&value); 
retval = UA_Client_readValueAttribute(client, nodeId, &value);
 if(retval == UA_STATUSCODE_GOOD)
 { 
// Check the type and print the value
 if(UA_Variant_hasScalarType(&value, &UA_TYPES[UA_TYPES_FLOAT]))
 { 
float val = *(float*)value.data; printf("Value (Float): %.3f\n", val);
 } 
else
 if(UA_Variant_hasScalarType(&value, &UA_TYPES[UA_TYPES_INT32]))
 { 
UA_Int32 val = *(UA_Int32*)value.data; 
printf("Value (Int32): %d\n", (int)val);
 } 
else
 if(UA_Variant_hasScalarType(&value, &UA_TYPES[UA_TYPES_BOOLEAN]))
 { 
UA_Boolean val = *(UA_Boolean*)value.data; printf("Value (Bool): %s\n", val ? "true" : "false");
 
else
 if(UA_Variant_hasScalarType(&value, &UA_TYPES[UA_TYPES_STRING]))
 { 
UA_String str = *(UA_String*)value.data; printf("Value (String): %.*s\n", (int)str.length, str.data);
 } 
else
 { printf("Value of another type (not processed)\n");
 } 
else
 { 
printf("Read error: %s (0x%08x)\n", UA_StatusCode_name(retval), retval);
 } 
UA_Variant_clear(&value); UA_Client_disconnect(client); UA_Client_delete(client); printf("\nDone. Press Enter...\n"); getchar(); return 0;
 } 

I inserted the server IP, port, and nodeI. And here's the problem: Tags like SERVER_ONLY are read correctly, but other types, like HOLDING_REGISTR, aren't read at all. What could be wrong, please tell me. Grock insists that the ns value might be incorrect, but I'm checking it in UaExpert. And just to be sure, I tried reading in a loop, iterating through ns values ​​from 0 to 32. It didn't work. Please help a noob.


Jacky Bek

unread,
Feb 3, 2026, 10:21:09 AM (5 days ago) Feb 3
to bezdri...@gmail.com, open62541
what is the error code return from
1. UA_Client_connect()
2. UA_Client_readValueAttribute()

Sent from my iPhone

On 3 Feb 2026, at 03:37, Акакий Бездрищенко <bezdri...@gmail.com> wrote:


--
You received this message because you are subscribed to the Google Groups "open62541" group.
To unsubscribe from this group and stop receiving emails from it, send an email to open62541+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/open62541/2999eb1f-5db5-4298-adfe-9216d9402e04n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages