예제 #1
0
 async def move_or_copy(self, object_to_move_or_copy: NodeId,
                        target_directory: NodeId, create_copy: bool,
                        new_name: str) -> NodeId:
     """
     MoveOrCopy is used to move or copy a file or directory organized by this Object
     to another directory or to rename a file or directory.
     :param object_to_move_or_copy: The NodeId of the file or directory to move or copy.
     :param target_directory: The NodeId of the target directory of the move or copy command.
     If the file or directory is just renamed, the targetDirectory matches the ObjectId
     passed to the method call.
     :param create_copy: A flag indicating if a copy of the file or directory should be
     created at the target directory.
     :param new_name: The new name of the file or directory in the new location.
     If the string is empty, the name is unchanged.
     :return: The NodeId of the moved or copied object. Even if the Object is moved,
     the Server may return a new NodeId.
     """
     _logger.debug(
         "Request to %s%s file system object %s from %s to %s, new name=%s",
         '' if create_copy else 'move', 'copy' if create_copy else '',
         object_to_move_or_copy, self._directory_node, target_directory,
         new_name)
     move_or_copy_node = await self._directory_node.get_child("MoveOrCopy")
     arg3_create_copy = Variant(create_copy, VariantType.Boolean)
     arg4_new_name = Variant(new_name, VariantType.String)
     return await self._directory_node.call_method(move_or_copy_node,
                                                   object_to_move_or_copy,
                                                   target_directory,
                                                   arg3_create_copy,
                                                   arg4_new_name)
예제 #2
0
 async def create_file(self, file_name: str,
                       request_file_open: bool) -> [NodeId, int]:
     """
     CreateFile is used to create a new FileType Object organized by this Object.
     The created file can be written using the Write Method of the FileType.
     :param file_name: The name of the file to create. The name is used for the
     BrowseName and DisplayName of the file object and also for the file in the
     file system.
     For the BrowseName, the fileName is used for the name part of the QualifiedName.
     The namespace index is Server specific. For the DisplayName, the fileName is
     used for the text part of the LocalizedText. The locale part is Server specific.
     :param request_file_open: Flag indicating if the new file should be opened
     with the Write and Read bits set in the open mode after the creation of the file.
     If the flag is set to True, the file is created and opened for writing.
     If the flag is set to False, the file is just created.
     :return: The NodeId of the created file Object.
     The fileHandle is returned if the requestFileOpen is set to True.
     The fileNodeId and the fileHandle can be used to access the new file
     through the FileType Object representing the new file.
     If requestFileOpen is set to False, the returned value shall be 0
     and shall be ignored by the caller.
     """
     _logger.debug("Request to create file %s in %s", file_name,
                   self._directory_node)
     print(f"Request to create file {file_name} in {self._directory_node}")
     create_file_node = await self._directory_node.get_child("CreateFile")
     arg1_file_name = Variant(file_name, VariantType.String)
     arg2_request_file_open = Variant(request_file_open,
                                      VariantType.Boolean)
     return await self._directory_node.call_method(create_file_node,
                                                   arg1_file_name,
                                                   arg2_request_file_open)
예제 #3
0
 async def read(self) -> bytes:
     """
     Read is used to read a part of the file starting from the current file position.
     The file position is advanced by the number of bytes read.
     :return: Contains the returned data of the file.
     If the ByteString is empty it indicates that the end of the file is reached.
     """
     _logger.debug("Request to read from file %s", self._file_node)
     size = await self.get_size()
     if self._read_node is None:
         self._read_node = await self._file_node.get_child("Read")
     arg1_file_handle = Variant(self._file_handle, VariantType.UInt32)
     arg2_length = Variant(size, VariantType.Int32)
     return await self._file_node.call_method(self._read_node,
                                              arg1_file_handle, arg2_length)
예제 #4
0
 async def set_position(self, position: int) -> None:
     """
     SetPosition is used to set the current position of the file handle.
     :param position: The position to be set for the fileHandle in the file.
     If a Read or Write is called it starts at that position.
     If the position is higher than the file size the position is set to the end of the file.
     """
     _logger.debug("Request to set position in file %s", self._file_node)
     if self._set_position_node is None:
         self._set_position_node = await self._file_node.get_child(
             "SetPosition")
     arg1_file_handle = Variant(self._file_handle, VariantType.UInt32)
     arg2_position = Variant(position, VariantType.UInt64)
     return await self._file_node.call_method(self._set_position_node,
                                              arg1_file_handle,
                                              arg2_position)
예제 #5
0
 async def write(self, data: bytes) -> None:
     """
     Write is used to write a part of the file starting from the current file position.
     The file position is advanced by the number of bytes written.
     :param data: Contains the data to be written at the position of the file.
     It is server-dependent whether the written data are persistently
     stored if the session is ended without calling the Close Method with the fileHandle.
     Writing an empty or null ByteString returns a Good result code without any
     affect on the file.
     """
     _logger.debug("Request to write to file %s", self._file_node)
     if self._write_node is None:
         self._write_node = await self._file_node.get_child("Write")
     arg1_file_handle = Variant(self._file_handle, VariantType.UInt32)
     arg2_data = Variant(data, VariantType.ByteString)
     await self._file_node.call_method(self._write_node, arg1_file_handle,
                                       arg2_data)
예제 #6
0
 async def close(self) -> None:
     """
     Close is used to close a file represented by a FileType.
     When a client closes a file the handle becomes invalid.
     """
     _logger.debug("Request to close file %s", self._file_node)
     read_node = await self._file_node.get_child("Close")
     arg1_file_handle = Variant(self._file_handle, VariantType.UInt32)
     await self._file_node.call_method(read_node, arg1_file_handle)
예제 #7
0
    async def get_existing_alarms(self, subscription_id):
        refresh_node = self._client.get_node('i=3875')
        condition_node = self._client.get_node('i=2782')

        try:
            await condition_node.call_method(
                refresh_node,
                Variant(int(subscription_id), varianttype=VariantType.UInt32))
        except uaerrors.BadNothingToDo:
            logging.warning('refresh failed')
예제 #8
0
 async def get_position(self) -> int:
     """
     GetPosition is used to provide the current position of the file handle.
     :return: The position of the fileHandle in the file.
     If a Read or Write is called it starts at that position.
     """
     _logger.debug("Request to get position from file %s", self._file_node)
     if self._get_position_node is None:
         self._get_position_node = await self._file_node.get_child(
             "GetPosition")
     arg1_file_handle = Variant(self._file_handle, VariantType.UInt32)
     return await self._file_node.call_method(self._get_position_node,
                                              arg1_file_handle)
예제 #9
0
 async def open(self, open_mode: OpenFileMode = None) -> None:
     """
     Open is used to open a file represented by an Object of FileType.
     The open mode of OPC UA differs significantly from the
     python build-in functionality.
     => See the OPC UA specification for more information.
     :param open_mode: Open mode defined in C.2.1.
     :return: The file handle.
     """
     _logger.debug("Request to open file %s in mode: %s", self._file_node,
                   OpenFileMode)
     open_node = await self._file_node.get_child("Open")
     arg1_mode = Variant(open_mode or self._open_mode, VariantType.Byte)
     self._file_handle = await self._file_node.call_method(
         open_node, arg1_mode)
예제 #10
0
 async def create_directory(self, directory_name: str) -> NodeId:
     """
     CreateDirectory is used to create a new FileDirectoryType Object organized by this Object.
     :param directory_name: The name of the directory to create.
     The name is used for the BrowseName and DisplayName of the directory object and also
     for the directory in the file system.
     For the BrowseName, the directoryName is used for the name part of the QualifiedName.
     The namespace index is Server specific.
     For the DisplayName, the directoryName is used for the text part of the LocalizedText.
     The locale part is Server specific.
     :return: The NodeId of the created directory Object.
     """
     _logger.debug("Request to create directory %s in %s", directory_name,
                   self._directory_node)
     create_directory_node = await self._directory_node.get_child(
         "CreateDirectory")
     arg1_directory_name = Variant(directory_name, VariantType.String)
     return await self._directory_node.call_method(create_directory_node,
                                                   arg1_directory_name)