Showing results 1 to 9 of 9

Thread: SetValueWithStatus

  1. #1
    Join Date
    19.01.2017
    Posts
    16

    Default SetValueWithStatus

    Hi,

    I have some problems with the SetValueWithStatus function in which the DateAndTime has to be supplied as a long, instead of a Date Type ...

    In my program, if an alarm is selected in the AML and then a button is pushed, I set the M3 StatusBit of the selected alarm variable using the following line:

    /*
    oAmlVar.SetValueWithStatus oAmlVar.Value oAmlVar.StatusValue + 4, SelectedAlarmDateRaised, 0
    */

    (with SelectedAlarmDateRaised is the time the selected alarm was raised)

    The goal is to set the M3 bit (this works) using the value of the Alarm in the Alarmlist and using the same time the Alarm was raised.

    The problem is that SelectedAlarmDateRaised gets its timestamp from the AML in a Date type and the SetValueWithStatus function expects a long to supply the Date and Time.

    Anybody knows an easy way to convert the timestamp into a long ?

    I also tried setting M3 using oAmlVar.StatusString = "M3=1". This works fine and keeps the correct RaisedTime for 61850 Variables, but this doesn't seem to work on Internal Variables ...

    Best regards,
    Philippe
    Last edited by PhilippeVDT : 23rd February 2017 at 14:29

  2. #2
    Join Date
    15.09.2016
    Posts
    61

    Default Re: SetValueWithStatus

    Hello Philippe,



    a Way to convert Values into a Long is the function cLng(SelectedAlarmDateRaised)

    but i donīt know if it works with DateTime Values.



    a other way you can try is to split the DateTime value like this




    dim MyLong as long
    dim LongText as string
    LongText = CStr(Day(Var)) + CStr(Month(Var)) + CStr(Year(Var)) + CStr(Hour(Var)) + CStr(Minute(Var)) + CStr(Second(Var))
    MyLongVar = cLng(LongText)



    I hope i could help you

  3. #3
    Join Date
    15.11.2016
    Posts
    109

    Default Re: SetValueWithStatus

    Hello Philippe,

    Status Information can also be set like this:
    thisProject.Variables.Item("Varname").StatusString = "M3=1"
    thisProject.Variables.Item(
    "Varname").StatusString = "M3=0"

    Please tell us if this solution would work for you.

    BR,
    Georg

  4. #4
    Join Date
    19.01.2017
    Posts
    16

    Default Re: SetValueWithStatus

    Hi Goergk,

    I tried that on 61850 variables.  In that case, I don't have the TimeStampProblem, but that way of working doesn't seem to work on Internal Variables (the StatusBit is never set).

    BestRegards,
    Philippe

  5. #5
    Join Date
    15.11.2016
    Posts
    109

    Default Re: SetValueWithStatus

    Hello Philippe,

    Internal Variables do not allow setting of Status Bits.

    This can only be done on driver-variables.

    BR,
    Georg

  6. #6
    Join Date
    19.01.2017
    Posts
    16

    Default Re: SetValueWithStatus

    Hi Georgk,

    The strange thing is, when I use the following code, then it is possible to set StatusBits on Internal Variables, only the Time Stamp changes to 1/1/1970 12h53'11"000 ...

    oAmlVar.SetValueWithStatus oAmlVar.Value oAmlVar.StatusValue + 4, now, 0
     
    Philippe

  7. #7
    Join Date
    19.01.2017
    Posts
    16

    Default Re: SetValueWithStatus

    Hi Florian,

    I just tried what you suggested, but that results in Overlfow Errors as the values are bigger than 2147483647 ...

    Philippe
    Last edited by PhilippeVDT : 28th February 2017 at 13:18

  8. #8
    Join Date
    01.07.2008
    Location
    Salzburg, AT
    Posts
    1,061

    Default Re: SetValueWithStatus

    SetValueWithStatus and SetValueWithStatusEx expect in input Time an UNIX-Time (=seconds since 1.1.1970 UTC). But the Now() gives a DATE value (=days since 31.12.1899 localtime), thus is not suitable as input. The example in Help has an mistake, sorry.

  9. #9
    Join Date
    15.11.2016
    Posts
    109

    Default Re: SetValueWithStatus

    Hello Philippe,

    I recently tested with the SetValueWithStatus method and used the following code to get the timestamp:

    Option Explicit

    Private Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)

    Private Type SYSTEMTIME
    wYear As Integer
    wMonth As Integer
    wDayOfWeek As Integer
    wDay As Integer
    wHour As Integer
    wMinute As Integer
    wSecond As Integer
    wMilliseconds As Integer
    End Type

    Private Function GetUnixTimestamp() As Long
    Dim st As SYSTEMTIME

    GetSystemTime st

    GetUnixTimestamp = DateDiff("s", DateSerial(1970, 1, 1), DateSerial(st.wYear, st.wMonth, st.wDay) + TimeSerial(st.wHour, st.wMinute, st.wSecond))

    End Function

    This function uses the system time to calculate the UNIX time considering the local timezone and dalight saving.

    You can get the UNIX time by using the function GetUnixTimestamp to write the result to a Long:
    Dim Tnow As Long
    Tnow = GetUnixTimestamp()

    I hope this helped.

    BR,
    Georg
    Last edited by georgk : 6th March 2017 at 13:04

Posting Rules

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •