plcforum.uz.ua

International PLC Forum
It is currently Fri Sep 21, 2018 7:23 pm

All times are UTC + 3 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Sun Feb 24, 2013 12:22 am 

Joined: Mon Jan 09, 2012 9:17 pm
Posts: 7
How to manipulate bits in a PictureWindow by script?

I can read the bits, but I can not write or send commands bit to bit on a word in PictureWindow.

I used only the suffix as tag, but still did not work.

Tanks!


Top
 Profile  
 
PostPosted: Mon Feb 25, 2013 10:30 pm 

Joined: Mon Jan 09, 2012 9:17 pm
Posts: 7
I did not find solution. I developed a function in VBS:

0 = Reset Bit, 1 and 2 = Set bit Inverts bit.

Following is the code with comments in Portuguese:



Code:
Sub Converte_bit (Byval set_reset_inverte, Byval bit, Byval tag)

'set_reset_inverte: 0=reset bit - 1=set bit - 2=invert bit

'bit: Número do bit que será alterado

'tag: Lembrando que quando utilizado dentro de uma picture window usar somente o sufixo da tag

Dim decimal, aux ' numero decimal
Dim  cont ' contador
Dim Vetor(32) ' Vetor de 16 Posições
Dim Valor_Bit

Valor_Bit = 2^bit


decimal  = HMIRuntime.Tags(tag).Read ' Busca valor atual da Tag
aux = decimal

cont = 0 ' inicializa contador


While (cont <= 32)

Vetor(cont) = aux Mod 2 ' Vetor

aux = (aux - Vetor(cont))/2 ' atualiza valor decimal

'MsgBox Vetor(cont)
cont = cont + 1 ' for stupid contador
Wend

If set_reset_inverte = 1 Then ' Set bit
   If Vetor(bit) = 0 Then ' Verifica se o bit não está setado
      decimal = decimal + Valor_Bit 'set o bit na Dword
   End If
End If

If set_reset_inverte = 0 Then 'Reset bit
   If Vetor(bit) = 1 Then 'Verifica se o bit está setado
      decimal = decimal - Valor_Bit ' reset bit na Dword
   End If
End If


If set_reset_inverte = 2 Then 'Invert bit

   If Vetor(bit) = 0 Then 'verifica se o bit não está setado
      decimal = decimal + Valor_Bit ' set bit na Dword
   End If
   
   If Vetor(bit) = 1 Then 'verifica se o bit  está setado
      decimal = decimal - Valor_Bit ' reset bit na Dword
   End If    
   
End If

HMIRuntime.Tags(tag).Write decimal

End Sub


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by International PLCforum® Forum Software © PLCforum
Mobile version