def write (self, vm_address, value):
        """
        Writes to VM addresses of Siemens Logo.
        Example: write("VW10", 200) or write("V10.3", 1)

        :param vm_address: write offset
        :param value: integer
        """
        area = snap7types.S7AreaDB
        db_number = 1
        start = 0
        amount = 1
        wordlen = 0
        data = bytearray(0)
        logger.debug("write, vm_address:%s, value:%s" %
                     (vm_address, value))
        if re.match("^V[0-9]{1,4}\.[0-7]{1}$", vm_address):
            ## bit value
            logger.info("read, Bit address: " + vm_address)
            address = vm_address[1:].split(".")
            # transform string to int
            address_byte = int(address[0])
            address_bit = int(address[1])
            start = (address_byte*8)+address_bit
            wordlen = snap7types.S7WLBit
            if value > 0:
                data = bytearray([1])    
            else:
                data = bytearray([0])
        elif re.match("^V[0-9]+$", vm_address):
            ## byte value
            logger.info("Byte address: " + vm_address)
            start = int(vm_address[1:])
            wordlen = snap7types.S7WLByte
            data = bytearray(struct.pack(">B", value))
        elif re.match("^VW[0-9]+$", vm_address):
            ## byte value
            logger.info("Word address: " + vm_address)
            start = int(vm_address[2:])
            wordlen = snap7types.S7WLWord
            data = bytearray(struct.pack(">h", value))
        elif re.match("^VD[0-9]+$", vm_address):
            ## byte value
            logger.info("DWord address: " + vm_address)
            start = int(vm_address[2:])
            wordlen = snap7types.S7WLDWord
            data = bytearray(struct.pack(">l", value))
        else:
            logger.info("write, Unknown address format: " + vm_address)
            return 1
        
        if wordlen == snap7types.S7WLBit:
            type_ = snap7.snap7types.wordlen_to_ctypes[snap7types.S7WLByte]
        else:
            type_ = snap7.snap7types.wordlen_to_ctypes[wordlen]
        
        cdata = (type_ * amount).from_buffer_copy(data)

        logger.debug("write, vm_address:%s value:%s" % (vm_address, value))

        result = self.library.Cli_WriteArea(self.pointer, area, db_number, start,
                                          amount, wordlen, byref(cdata))
        check_error(result, context="client")
        return result
def write ( self , vm_address , value ) : area = snap7types . S7AreaDB db_number = 1 start = 0 amount = 1 wordlen = 0 data = bytearray ( 0 ) logger . debug ( "write, vm_address:%s, value:%s" % ( vm_address , value ) ) if re . match ( "^V[0-9]{1,4}\.[0-7]{1}$" , vm_address ) : logger . info ( "read, Bit address: " + vm_address ) address = vm_address [ 1 : ] . split ( "." ) address_byte = int ( address [ 0 ] ) address_bit = int ( address [ 1 ] ) start = ( address_byte * 8 ) + address_bit wordlen = snap7types . S7WLBit if value > 0 : data = bytearray ( [ 1 ] ) else : data = bytearray ( [ 0 ] ) elif re . match ( "^V[0-9]+$" , vm_address ) : logger . info ( "Byte address: " + vm_address ) start = int ( vm_address [ 1 : ] ) wordlen = snap7types . S7WLByte data = bytearray ( struct . pack ( ">B" , value ) ) elif re . match ( "^VW[0-9]+$" , vm_address ) : logger . info ( "Word address: " + vm_address ) start = int ( vm_address [ 2 : ] ) wordlen = snap7types . S7WLWord data = bytearray ( struct . pack ( ">h" , value ) ) elif re . match ( "^VD[0-9]+$" , vm_address ) : logger . info ( "DWord address: " + vm_address ) start = int ( vm_address [ 2 : ] ) wordlen = snap7types . S7WLDWord data = bytearray ( struct . pack ( ">l" , value ) ) else : logger . info ( "write, Unknown address format: " + vm_address ) return 1 if wordlen == snap7types . S7WLBit : type_ = snap7 . snap7types . wordlen_to_ctypes [ snap7types . S7WLByte ] else : type_ = snap7 . snap7types . wordlen_to_ctypes [ wordlen ] cdata = ( type_ * amount ) . from_buffer_copy ( data ) logger . debug ( "write, vm_address:%s value:%s" % ( vm_address , value ) ) result = self . library . Cli_WriteArea ( self . pointer , area , db_number , start , amount , wordlen , byref ( cdata ) ) check_error ( result , context = "client" ) return result
Writes to VM addresses of Siemens Logo.
        Example: write("VW10", 200) or write("V10.3", 1)

        :param vm_address: write offset
        :param value: integer