Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Really simple CML driver questions
#31
I have created about 30 fields for the power calculations, to expose some of the calculated values from the macro. I have three power meters, main 3 phase, off peak and solar power. All are monitored into a PLC (which when Mark gets back to me will hopefully have a driver for it) and then this macro estimates the current value of the bill.
I started with the logic server, but is was not capable of handling the tiered tariffs. I had two options, try and write a CML driver that does not connect to a real device, but rather just reads fields from others and have its own, or use another instance of the variable driver (dedicated to the macro) with a macro.
I went with the variable driver and macro as it was easier for me (as you can see I struggle with this, reading is not how I learn, I need to do examples and be shown).

I find the logic server a bit restrictive. I needed an if statement with the maths formula. I tried to use it a couple of time, but ran into restrictions.

Thanks for pointing it out though.
Reply
#32
I have a driver with an array, I am creating the override for the writes, but I need to use the index as a value in the command.

How do I get the index of the field (which is an element in an array) being written.

Also

I have this line

command.AppendCard4(valmod,Radices.Hex);

The value of valmod needs to be two characters (ie 02 instead of 2). How do I ensure that it is always two and not one or more then two?

And finally

How do I cast an int to a card?

Mick
Reply
#33
znelbok Wrote:command.AppendCard4(valmod,Radices.Hex);

The value of valmod needs to be two characters (ie 02 instead of 2). How do I ensure that it is always two and not one or more then two?

And finally

How do I cast an int to a card?

Mick

Does TypeCast not work for ints to cards? It *should* be:

mycard = TypeCast(MEng.Card4, myInt);

For the append card4, I'd write it to a temporary string var, then check the length of it, and if the length is less than 2, then just prepend a "0".
Reply
#34
The method below allows for submitting a Card4, width, and prefix and returns a string. The prefix would be if you were formatting for display or something and wanted a "0x" in front. For the field write it really depends. Would need a little more information. When you say the field is an element in an array is the array a Card4Array of the FldId's? If so then you just have to do a brute force loop to determine the index. The 2nd listing is one of many ways you could do it.

Realized I put a decimal string return method instead of hex so changed the method.

Code:
//
//  GETHEXSTRING
//
    Method GetHexString([In] Card4 ToFmt, [In] Card4 Width, [In] String Prefix) Returns String
    Begin

    Locals=
        Card4   i;
        String  StrVal;
    EndLocals;

        StrVal.AppendCard4(ToFmt,Radices.Hex);
        i := StrVal.GetLength();
        
        While(i<Width)
            StrVal.Prepend("0");
            i++;
        EndWhile;

        StrVal.Prepend(Prefix);

        Return StrVal;

    EndMethod;

Code:
...
i:=0;
Count := MyArray.GetElemCount();
While(i<Count)
    If(MyArray[i]=FldId)
        Flag := True;
        Break;
    EndIf;
    i++;
EndWhile;

' If flag is set then i is the index we were looking for
If(Flag)
  Do Stuff
EndIf;
It's the early bird that catches the worm, but it's the second mouse that gets the cheese...
Reply
#35
The String::FormatToFld() method will do all that for you, though you have to do it into a separate string, then append it to the actual string you are building up.
Dean Roddey
Software Geek Extraordinaire
Reply
#36
jrlewis Wrote:The method below allows for submitting a Card4, width, and prefix and returns a string. The prefix would be if you were formatting for display or something and wanted a "0x" in front. For the field write it really depends. Would need a little more information. When you say the field is an element in an array is the array a Card4Array of the FldId's? If so then you just have to do a brute force loop to determine the index. The 2nd listing is one of many ways you could do it.

Realized I put a decimal string return method instead of hex so changed the method.

Code:
//
//  GETHEXSTRING
//
    Method GetHexString([In] Card4 ToFmt, [In] Card4 Width, [In] String Prefix) Returns String
    Begin

    Locals=
        Card4   i;
        String  StrVal;
    EndLocals;

        StrVal.AppendCard4(ToFmt,Radices.Hex);
        i := StrVal.GetLength();
        
        While(i<Width)
            StrVal.Prepend("0");
            i++;
        EndWhile;

        StrVal.Prepend(Prefix);

        Return StrVal;

    EndMethod;

Code:
...
i:=0;
Count := MyArray.GetElemCount();
While(i<Count)
    If(MyArray[i]=FldId)
        Flag := True;
        Break;
    EndIf;
    i++;
EndWhile;

' If flag is set then i is the index we were looking for
If(Flag)
  Do Stuff
EndIf;

Ok, I thought that it would be cleaner than this so what I did was this
Code:
If (valrem < 10)
                    command += "0";
                EndIf;
basically, if the value 'valrem' is less then 10, append the 0 - same stuff really.

Thanks

Mick
Reply
#37
I have used that for formatting width's but just missed the fill character. Need to modify my string methods. For your value check Mick you need to check against 0x10 since 10 in Hex is A. If the value will always be less than 0x10 no need to even check and just prepend a 0.
It's the early bird that catches the worm, but it's the second mouse that gets the cheese...
Reply
#38
Thanks

I append the value as a hex, so I am actually checking for a value of <16 (<Fh). The value does go as high as 512, so the check needs to be done all the time.
Reply
#39
Next one

I need to get a value from a field in the driver to create a string for setting another value (a word is sent, and so I need to know the 15 other bits to create the word).

how do I get the driver to give me the current value of a field (its a boolean field)?
Reply
#40
Just have a member variable shadow the field value. So define a m_MyBooleanValue and set it where appropriate to track the field value. You can use ReadBoolFld or ReadBoolFldByName if you don't want to track it internally, but if you got the info you may as well track it.
It's the early bird that catches the worm, but it's the second mouse that gets the cheese...
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 379 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)