Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Really simple CML driver questions
#21
It's not a method, it's an intrinsic function of the language, so it's described in the CML guide.
Dean Roddey
Software Geek Extraordinaire
Reply
#22
next dumb question

I want to days date, and I can get it. It returns a card4 2455235.

What is this number and how do I use it?

Its not the number of days since 1/1/70, nor is it the number of seconds.

I am trying to calculate the number of days from a date in the past that is entered in by the user (eg 25/1/2010). I used GetJulianDate() to get the above number.
Reply
#23
For time variables you deal with stamps and the native format is a Card8 (100 nanosecond intervals since epoch - Jan. 1, 1970). In order to get it into a readable string value you set the default format for the time variable of interest. So for example the code fragment below would give you a string with the current time formatted as HH:MM:SS (14:54:35). If you have a stamp you got from somewhere else you would use the SetFromStamp to set the Time variable and then append that to a string using AppendFmt. Take a look at the Time class for all the different formats you can use for SetDefFmt.

Code:
Locals=
    Card8   Stamp;
    String  StrTime;
    String  StrTimeFromStamp;
    Time    MyTime(SpecialTimes.CurTime);
EndLocals;

    MyTime.SetDefFmt("%(H,2,0):%(u,2,0):%(s,2,0)");
    StrTime.AppendFmt(MyTime);

    // Same effect as setting it above using the SpecialTimes
    // this time using a 12 hour format
    Stamp := MyTime.GetCurStamp();
    MyTime.SetFromStamp(Stamp);
    MyTime.SetDefFmt("%(h,2,0):%(u,2,0):%(s,2,0)");
    StrTimeFromStamp.AppendFmt(MyTime);

Addendum. To get the the number of days from today from a past value that is entered like that you would first need to set a time variable using the SetDate() method and then set another time variable to the current date. Get the Julian date from each and subtract. So something like

Code:
Locals=
    Card4   Delta;
    Months  Month;
    Time     CurDate(SpecialTimes.CurDate);
    Time     PastDate;
EndLocals;
    
    Month.SetOrdinal(Month as card from date);
    PastDate.SetDate(Year as card, Month,day as card);

    Delta := CurDate.GetJulianDate() - PastDate.GetJulianDate();
It's the early bird that catches the worm, but it's the second mouse that gets the cheese...
Reply
#24
I understand that, just - thanks

In the Month.SetOrdinal line, I get an error when the month is set to 12 (December). I know this is because it starts at 0 and not 1.
I have this now
Code:
Monthstr.SetOrdinal(ReadDate.ExtractCard4(3,2));
and it fails in December. How can I subtract 1 from the extracted card value.
I tried
Code:
Monthstr.SetOrdinal(ReadDate.ExtractCard4(3,2)-1);
but it does not work.
I can do it with some extra locals and getting the card from the string and then decrementing it by 1 and then substituting it, but that seems like a waste of lines.
Mick
Reply
#25
What you have will work. You need to put in spaces like below. The compiler doesn't like parameters that have math operations to not be separated. And if you are doing any multi-value calculations it is usually best to add parenthesis to make sure you get the proper value. The compiler works left to right so things aren't always as they seem when it comes to the order of math operations.
Code:
Monthstr.SetOrdinal(ReadDate.ExtractCard4(3,2) - 1);
It's the early bird that catches the worm, but it's the second mouse that gets the cheese...
Reply
#26
Quote:The compiler doesn't like parameters that have math operations to not be separated

Yeah, what is up with that anyway. I have never seen a parser that was picky like that. If your operators are your delimiters, why is the whitespace necessary?
Wuench
My Home Theater/Automation Website

[THREAD=5957]BlueGlass CQC Config[/THREAD]
[THREAD=10624]Wuench's CQC Drivers[/THREAD]
Reply
#27
In this case it's because it thinks that -1 is a number, and so it looks like you have no operator. It's a quirk of the parser. So it's the need for a space between the minus and the 1 that does it.
Dean Roddey
Software Geek Extraordinaire
Reply
#28
Ah, got it. I know I have run into it many times, but I never sat down to think through it. Just usually let the compiler catch me and add spaces when it does.
Wuench
My Home Theater/Automation Website

[THREAD=5957]BlueGlass CQC Config[/THREAD]
[THREAD=10624]Wuench's CQC Drivers[/THREAD]
Reply
#29
Thanks guys. I have my macro working now at a point that I am happy.
The macro uses the power meter reading on the bill and takes the current meter reading from the PLC and creates a live bill value.

Mick
Reply
#30
If the purpose of this is to just create another field, is it something you could have done with the logic server? It provides a math formula type field that lets you do mathematical formulas based on other fields.
Dean Roddey
Software Geek Extraordinaire
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Nest driver disconnecting and reconnecting dogman 42 926 12-04-2017, 07:17 PM
Last Post: dogman
  Simple field change trigger action Bugman 15 805 10-23-2017, 11:55 AM
Last Post: Dean Roddey
  Logitech Media Server/squeezebox driver freezes Admin interface lleo 7 503 10-21-2017, 11:11 AM
Last Post: Dean Roddey
  music & movie driver experiences and or suggestions zane 2 399 10-18-2017, 06:48 AM
Last Post: pjgregory
  Simple check before setting Elk M1 to Arm State KenC 7 380 10-03-2017, 05:55 PM
Last Post: Dean Roddey
  Kramer Protocol 2000 driver and VS-1616v Help Please! NightLight 6 506 09-12-2017, 05:08 PM
Last Post: Dean Roddey
  Next V2 driver problem kjaerligkatt 9 533 09-05-2017, 01:33 PM
Last Post: kjaerligkatt
  RCS Thermostat Driver help sic0048 10 994 08-19-2017, 08:01 AM
Last Post: Dean Roddey
  Harmony Hub driver tom 43 6,103 08-17-2017, 09:00 AM
Last Post: Dean Roddey
  ISY Driver not able to change value on a specific switch Sendero 9 1,168 07-18-2017, 09:54 AM
Last Post: Dean Roddey

Forum Jump:


Users browsing this thread: 1 Guest(s)