Compare commits

...

3 Commits
main ... origin

Author SHA1 Message Date
ubiboy
a36c844457 trans 2024-12-20 19:31:19 +08:00
ubiboy
c8373c2d34 originAdd 2024-12-20 19:27:37 +08:00
ubiboy
04e94b70f2 origin 2024-12-20 19:18:14 +08:00
5 changed files with 161 additions and 222 deletions

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"C_Cpp.errorSquiggles": "disabled"
}

View File

@ -1,64 +0,0 @@
#include <string.h>
#include "UA_PLC.h"
UA_Client *client;
u32 Connect(long *ConnectionHdl){
UA_Client *c = UA_Client_new();
UA_StatusCode flag = UA_ClientConfig_setDefault(UA_Client_getConfig(c));
UA_ClientConfig *config=UA_Client_getConfig(c);
if (flag == UA_STATUSCODE_GOOD) {
flag=UA_Client_connect(c, "opc.tcp://localhost:4840");
}else
{
UA_Client_delete(c);
//memset(c,0,100);
return flag;
}
client = c;
*ConnectionHdl = (long *)c;
printf("ConnectionHdl %lld \n",*ConnectionHdl);
return flag;
}
u32 NamespaceGetIndexList(long ConnectionHdl,u16 NamespaceUrisCount,STRING *NamespaceUris,u16 *NamespaceIndexes){
UA_Client *c = (UA_Client*)ConnectionHdl;
int i;
u32 retval=0;
if(NamespaceUrisCount>MAX_ELEMENTS_NAMESPACES){
retval=0xA0000002;
return retval;
}
for(i=0;i<NamespaceUrisCount;i++){
UA_String NamespaceUri;
NamespaceUri.length = NamespaceUris[i].length;
NamespaceUri.data = NamespaceUris[i].data;
retval=UA_Client_NamespaceGetIndex(c,&NamespaceUri,&NamespaceIndexes[i]);
if (retval!= UA_STATUSCODE_GOOD) {
printf("Failed to get namespace index for URI %.*s\n", (int)NamespaceUri.length, NamespaceUri.data);
break; // 出现错误时立即退出循环
}
}
return retval;
}
int main(int argc, char *argv[]) {
long connectionHdl;
Connect(&connectionHdl);
STRING str[3];
str[0].data = (UA_Byte*)"http://opcfoundation.org/UA/";
str[0].length = 28;
str[1].data = (UA_Byte*)"urn:open62541.server.application";
str[1].length = 32;
str[2].data = (UA_Byte*)"http://example.com/MyNamespace";
str[2].length = 30;
u16 num[3] = {0};
NamespaceGetIndexList(connectionHdl,3,str,num);
printf("Namespace Indexes:\n");
for (int i = 0; i < 3; i++) {
printf("URI %d: Index = %u\n", i, num[i]);
}
}

Binary file not shown.

Binary file not shown.