Binary representation of the data

Binary representation of the data

  • 17 aprile 2019 alle 1:57 pm #32126
    moskvichov
    Partecipante

    Hi all.

    Tell me please the best way to show some data in binary mode.

    • Questo argomento è stato modificato 5 mesi fa da moskvichov.
  • 18 aprile 2019 alle 5:20 pm #32141
    MODERATOR
    Partecipante

    Hi MOSKVICHOV,
    If I well understood your needs, it is possible bring in a byte, word or double word and split it in to individual bits.

    In the Movicon objects and resources, (except the scripts), you can always use this simple way, working on the variable sintax “Variablename.Bitnumber” (eg wordexample.0 for use the first bit of a word variable called “wordexample” to access individual bits).

    wordexample.0 > first bit
    wordexample.1 > second bit
    ….
    wordexample.15

    You can use this syntax in all the objects like buttons, lamps displays and also datalogger.

  • 20 aprile 2019 alle 7:00 am #32170
    moskvichov
    Partecipante

    No no, i want to show word data in binary

    I have the variable BYTE. For example VAR0001=255

    I want to show on the screen this value in binary i.e 11111111

  • 25 aprile 2019 alle 5:12 pm #32204
    Robin
    Partecipante

    Hi Moskvichov,
    I think you need a script customization to adapt the values.
    You can manage bit mask of the BYTE variable and populate an additional string variable with these data.

    Try with this (script under a button)
    VAR00001 defined in the project

    Option Explicit
    Dim bRet As String
    Public Sub Click()
    bRet = GetBitValue()
    MsgBox “VAR00001 in binay: ” & CStr(bRet)
    End Sub

    Public Function GetBitValue() As String
    Dim i As Integer
    Dim Bin_VAR00001 As String
    For i = 0 To 7 ‘in this case 0 to 7 because is a byte variable (8 bit)
    If (VAR00001 And 2^i) > 0 Then
    Bin_VAR00001 = Bin_VAR00001 & 1
    Else
    Bin_VAR00001 = Bin_VAR00001 & 0
    End If
    Next
    GetBitValue = StrReverse(Bin_VAR00001)
    End Function

    I hope this will Help

    Best Regards
    Robin

    • Questa risposta è stata modificata 4 mesi, 3 settimane fa da Robin.
  • 26 aprile 2019 alle 8:44 am #32213
    moskvichov
    Partecipante

    Robin thanks for your answer.

    Ok i have the variable VAR00001. This variable is dynamically changing. I want to show its value (binary) in EditBox.

    You script will show, if i click.

  • 26 aprile 2019 alle 5:29 pm #32214
    MODERATOR
    Partecipante

    Hello Moskvichov,

    ok , you need to change the script context ….

    E.g. you can create a variable script event on the synoptic….

    Take a screen > Right Click > Add New Variable script Event …and select VAR00001….
    Then under the screen script context you can write the code like this:

    Option Explicit
    Dim bRet As String

    Public Sub OnVAR00001Changed(ByRef value As Variant)

    bRet = GetBitValue()
    MsgBox “VAR00001 in binay: ” & CStr(bRet)
    End Sub

    Public Function GetBitValue() As String
    Dim i As Integer
    Dim Bin_VAR00001 As String
    For i = 0 To 7 ‘in this case 0 to 7 because is a byte variable (8 bit)
    If (VAR00001 And 2^i) > 0 Then
    Bin_VAR00001 = Bin_VAR00001 & 1
    Else
    Bin_VAR00001 = Bin_VAR00001 & 0
    End If
    Next
    GetBitValue = StrReverse(Bin_VAR00001)
    End Function

    ….the result, every time the VAR00001 changes its value, will be extracted in binary in this case shown over a msgbox but you can copy/move the result over another string varibale inside the script….

    Kind Regards

  • 27 aprile 2019 alle 3:39 pm #32215
    moskvichov
    Partecipante

    MODERATOR many thanks. I absolutely forgot about Variable Script. Now is all OK.

    Thanks once again.

    PS If possible clould you add in theme name RESOLVED?

    • Questa risposta è stata modificata 4 mesi, 3 settimane fa da moskvichov.

Devi essere loggato per rispondere a questa discussione.