12.19
This commit is contained in:
parent
b9fb32c6bc
commit
e0d02db1f0
52
myClient.c
52
myClient.c
@ -3,13 +3,10 @@
|
||||
|
||||
UA_Client *client;
|
||||
|
||||
u32 CA_Connect(long *ConnectionHdl,TIME timeout){
|
||||
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);
|
||||
|
||||
config->securityMode=1;
|
||||
config->timeout = timeout;
|
||||
if (flag == UA_STATUSCODE_GOOD) {
|
||||
flag=UA_Client_connect(c, "opc.tcp://localhost:4840");
|
||||
|
||||
@ -25,12 +22,43 @@ u32 CA_Connect(long *ConnectionHdl,TIME timeout){
|
||||
return flag;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
long *hdl;
|
||||
TIME timeout = 200000;
|
||||
CA_Connect(*hdl,timeout);
|
||||
while(1)
|
||||
{
|
||||
|
||||
}
|
||||
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]);
|
||||
}
|
||||
|
||||
}
|
@ -49,6 +49,12 @@ helloMethodCallback(UA_Server *server,
|
||||
|
||||
static void manuallyDefinePump(UA_Server *server)
|
||||
{
|
||||
//Add NameSpace
|
||||
|
||||
const char *namespaceUri = "http://example.com/MyNamespace";
|
||||
UA_UInt16 namespaceIndex = UA_Server_addNamespace(server, namespaceUri);
|
||||
|
||||
|
||||
// 声明并获取服务器分配的节点 ID
|
||||
UA_NodeId pumpId;
|
||||
|
||||
@ -58,7 +64,7 @@ static void manuallyDefinePump(UA_Server *server)
|
||||
|
||||
// 添加泵对象节点
|
||||
UA_Server_addObjectNode(server,
|
||||
UA_NODEID_NULL,
|
||||
UA_NODEID_NUMERIC(namespaceIndex, 1),
|
||||
UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
|
||||
UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
|
||||
UA_QUALIFIEDNAME(1, "Pump (Manual)"),
|
||||
|
BIN
opcua_client
BIN
opcua_client
Binary file not shown.
BIN
opcua_server
BIN
opcua_server
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user