Jump to content

Recommended Posts

Posted

desculpem mas ja ta resolvido, fica aqui o codigo para alguem querer..

    Private Function ll_ConvByteEmBool(ByVal bt As Byte) As Boolean()

        Dim lobt As Integer = bt : Dim b(8 ) As Boolean

        If lobt >= 128 Then

            lobt -= 128 : b(7) = True : End If

        If lobt >= 64 Then

            lobt -= 64 : b(6) = True : End If

        If lobt >= 32 Then

            lobt -= 32 : b(5) = True : End If

        If lobt >= 16 Then

            lobt -= 16 : b(4) = True : End If

        If lobt >= 8 Then

            lobt -= 8 : b(3) = True : End If

        If lobt >= 4 Then

            lobt -= 4 : b(2) = True : End If

        If lobt >= 2 Then

            lobt -= 2 : b(1) = True : End If

        If lobt >= 1 Then

            lobt -= 1 : b(0) = True

        End If

        Return b

    End Function

Luis Lourenço

Posted

Eu faço mais assim, acho que é mais linear, e não estás limitado a 8 bits, por exemplo uma DoubleWord (32 bits ou 4x8 bits) ou mais bytes seguidos:

                        Dim h As Integer = 0
                        For i As Integer = 0 To NúmeroBytes
                            For j As Integer = i * 8 To (i * 8 + 7)
                                Inputs(j) = InputBuffer(i) And (2 ^ h)
                                If Inputs(j) > 1 Then Inputs(j) = 1
                                h += 1
                            Next
                            h = 0
                        Next

Ricardo Timóteo

Posted

hmm nao percebi muito bem essa formula, podes explicar melhor?

é que eu queria fazer uma class para ler os timer e a doublewords, esses tipos todos..

Mas ainda nao fiz muita coisa.. porque o sistema responde muito mais rápido do que no s7..

Luis Lourenço

Posted

O InputBuffer é um array de bytes

O Inputs é um array de bits

O h varia entre 0 e 7, basicamente é o índice do bit do byte, 2^0 até 2^7

o i é o nº de byte do array de bytes

o j é o nº de bit de do byte i

Em cada ciclo do for do j faço um E (ao bit) entre o byte actual e 2^h (1,2,4,8,16,...,256) se o bit não estiver activo o resultado é 0, se tiver o resultado será 1,2,4,8,16,...,256 por isso como quero 0 e 1 então o resultado é 1

Ricardo Timóteo

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.