Binary representation of the data

Binary representation of the data

  • 17 April 2019 um 1:57 pm #32126
    moskvichov
    Teilnehmer

    Hi all.

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

    • Dieses Thema wurde geändert vor 1 Monat von moskvichov.
  • 18 April 2019 um 5:20 pm #32141
    MODERATOR
    Teilnehmer

    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 April 2019 um 7:00 am #32170
    moskvichov
    Teilnehmer

    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 April 2019 um 5:12 pm #32204
    Robin
    Teilnehmer

    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

    • Diese Antwort wurde geändert vor 3 Wochen, 5 Tagen von Robin.
  • 26 April 2019 um 8:44 am #32213
    moskvichov
    Teilnehmer

    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 April 2019 um 5:29 pm #32214
    MODERATOR
    Teilnehmer

    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 April 2019 um 3:39 pm #32215
    moskvichov
    Teilnehmer

    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?

    • Diese Antwort wurde geändert vor 3 Wochen, 3 Tagen von moskvichov.

Du musst angemeldet sein, um auf dieses Thema antworten zu können.