Browse Source

make client work

Julius Pfrommer 9 years ago
parent
commit
f6329a7015
2 changed files with 13 additions and 12 deletions
  1. 8 8
      examples/opcuaClient.c
  2. 5 4
      examples/opcuaServer.c

+ 8 - 8
examples/opcuaClient.c

@@ -40,7 +40,7 @@ static UA_Int32 sendHello(UA_Int32 sock, UA_String *endpointURL) {
 	UA_ByteString message;
 	UA_ByteString_newMembers(&message, messageHeader.messageSize);
 
-	UA_UInt32 offset = 0;
+	size_t offset = 0;
 	UA_TcpMessageHeader_encodeBinary((UA_TcpMessageHeader const*) &messageHeader, &message, &offset);
 	UA_TcpHelloMessage_encodeBinary((UA_TcpHelloMessage const*) &hello, &message, &offset);
 
@@ -95,7 +95,7 @@ static int sendOpenSecureChannel(UA_Int32 sock) {
 
 	UA_ByteString message;
 	UA_ByteString_newMembers(&message, 1000);
-	UA_UInt32 offset = 0;
+	size_t offset = 0;
 	UA_TcpMessageHeader_encodeBinary(&msghdr, &message, &offset);
 	UA_UInt32_encodeBinary(&secureChannelId, &message, &offset);
 	UA_String_encodeBinary(&securityPolicy, &message, &offset);
@@ -123,7 +123,7 @@ static UA_Int32 sendCreateSession(UA_Int32 sock, UA_UInt32 channelId, UA_UInt32
     UA_ByteString message;
 	UA_ByteString_newMembers(&message, 65536);
 	UA_UInt32 tmpChannelId = channelId;
-	UA_UInt32 offset = 0;
+	size_t offset = 0;
 
 	UA_TcpMessageHeader msghdr;
 	msghdr.messageTypeAndFinal = UA_MESSAGETYPEANDFINAL_MSGF;
@@ -171,7 +171,7 @@ static UA_Int32 sendCreateSession(UA_Int32 sock, UA_UInt32 channelId, UA_UInt32
 }
 
 static UA_Int32 closeSession(ConnectionInfo *connectionInfo) {
-	UA_UInt32 offset = 0;
+	size_t offset = 0;
 
 	UA_ByteString message;
 	UA_ByteString_newMembers(&message, 65536);
@@ -218,7 +218,7 @@ static UA_Int32 closeSession(ConnectionInfo *connectionInfo) {
 }
 
 static UA_Int32 closeSecureChannel(ConnectionInfo *connectionInfo) {
-	UA_UInt32 offset = 0;
+	size_t offset = 0;
 
 	UA_ByteString message;
 	UA_ByteString_newMembers(&message, 65536);
@@ -259,7 +259,7 @@ static UA_Int32 sendActivateSession(UA_Int32 sock, UA_UInt32 channelId, UA_UInt3
 	UA_ByteString *message = UA_ByteString_new();
 	UA_ByteString_newMembers(message, 65536);
 	UA_UInt32 tmpChannelId = channelId;
-	UA_UInt32 offset = 0;
+	size_t offset = 0;
 
 	UA_TcpMessageHeader msghdr;
 	msghdr.messageTypeAndFinal = UA_MESSAGETYPEANDFINAL_MSGF;
@@ -306,7 +306,7 @@ static UA_Int64 sendReadRequest(ConnectionInfo *connectionInfo, UA_Int32 nodeIds
 	UA_ByteString *message = UA_ByteString_new();
 	UA_ByteString_newMembers(message, 65536);
 	UA_UInt32 tmpChannelId = connectionInfo->channelId;
-	UA_UInt32 offset = 0;
+	size_t offset = 0;
 
 	UA_TcpMessageHeader msghdr;
 	msghdr.messageTypeAndFinal = UA_MESSAGETYPEANDFINAL_MSGF;
@@ -395,7 +395,7 @@ static int ua_client_connectUA(char* ipaddress,int port, UA_String *endpointUrl,
 			sendOpenSecureChannel(sock);
 			recv(sock, reply.data, reply.length, 0);
 
-			UA_UInt32 recvOffset = 0;
+			size_t recvOffset = 0;
 			UA_TcpMessageHeader msghdr;
 			UA_TcpMessageHeader_decodeBinary(&reply, &recvOffset, &msghdr);
 

+ 5 - 4
examples/opcuaServer.c

@@ -88,13 +88,14 @@ int main(int argc, char** argv) {
     char str[15];
     for(UA_UInt32 i = 0;i<nodeCount;i++) {
         UA_Int32 *data = UA_Int32_new();
-        UA_QualifiedName *nodeName = UA_QualifiedName_new();
         *data = 42;
+        UA_Variant *variant = UA_Variant_new();
+        UA_Variant_setValue(variant, data, UA_TYPES_INT32);
+        UA_QualifiedName *nodeName = UA_QualifiedName_new();
         sprintf(str,"%d",i);
         UA_QualifiedName_copycstring(str, nodeName);
-        UA_Server_addVariableNode(server, nodeName,
-                                  data, UA_NODEID_STATIC(UA_TYPES_IDS[UA_TYPES_INT32],0),
-                                  &UA_EXPANDEDNODEID_STATIC(UA_NS0ID_OBJECTSFOLDER,0),
+        UA_Server_addVariableNode(server, variant, nodeName,
+                                  &UA_NODEID_STATIC(UA_NS0ID_OBJECTSFOLDER,0),
                                   &UA_NODEID_STATIC(UA_NS0ID_ORGANIZES,0));
     }
 #endif