How to manipulate bits in a PictureWindow by script?

ProTool, WinCC flexible, WinCC, PP/OP/TP/TD/MP
heracliolmj
Posts: 7
Joined: Mon Jan 09, 2012 6:17 pm

How to manipulate bits in a PictureWindow by script?

Post by heracliolmj »

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!
heracliolmj
Posts: 7
Joined: Mon Jan 09, 2012 6:17 pm

Re: How to manipulate bits in a PictureWindow by script?

Post by heracliolmj »

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: Select all

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