KB-28855: Writing multiple values at once in a block.

Question:

Can I write all the values in a block at once, instead of writing them individually in each element?

Solution:

Yes. To do so, disable the IOBlock’s AllowWrite property (False). It establishes that the block will not perform automatic writes.

There are two possibilities for writing in the block:

1. By using WriteEx method:

  • Create an Array with the same size (i.e., number of elements) of your IOBlock;
  • Pass the value to be written in the block element to each of the Array’s elements;
  • After loading the Array with these values, use WriteEx method to write the values.

Example of script:

'Declaring the Array's size
Dim ArrayValue(4)

'Loading the Array's elements
ArrayValue(0) = 10
ArrayValue(1) = 20
ArrayValue(2) = 30
ArrayValue(3) = 40
ArrayValue(4) = 50
'Writing the block
Application.GetObject("Driver1.Block").WriteEx ArrayValue

2. By using Write method:

  • Disable the AllowRead property (automatic read) of the IOBlock where you want to write;
  • Load the block elements with the desired values;
  • After the values have been loaded, use Write method to write the values of the elements previously loaded;
  • After writing them, enable the block’s AllowRead property (True) again.

Example of script:

'Disables read 
Application.GetObject("Driver1.Block").AllowRead = False

'Loads values into elements
Application.GetObject("Driver1.Block.Element1").Value = 10
Application.GetObject("Driver1.Block.Element2").Value = 20
Application.GetObject("Driver1.Block.Element3").Value = 30
Application.GetObject("Driver1.Block.Element4").Value = 40
Application.GetObject("Driver1.Block.Element5").Value = 50

'Writes the block
Application.GetObject("Driver1.Block").Write()

'Enables read
Application.GetObject("Driver1.Bloco").AllowRead = True

Attached to this article is a sample application that illustrates the procedures seen above.

 

Attachments:

Sample.zip

Print Friendly, PDF & Email

Este artigo foi útil? Was this helpful?

Classificação média - Average rating 0 / 5. Count: 0

Leave a Reply

Your email address will not be published.Required fields are marked *