Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Really simple CML driver questions
Oh, yeh, sorry. That's for dealing with them as their binary values. You can just do a SetOrdinal() on a char to set that into a character and then append it. So,

Dean Roddey
Software Geek Extraordinaire
I have 8 digital inputs represented by a boolean (True/False 1/0)


1 1 0 1 0 0 1 1 (Inputs 7 to 0)

I need to create a string that looks like this

0D 03
where 0Dh = 1101 = 13.
and 03h = 0011 = 3.

I can do the conversion with a bunch of if statements, but it looks messy and there must be something that will do it better.

I can go the other way using the GetBit() to make each input true or false based on the value. Is there a way to reverse this cleany rather than using 8 if statements.

Do you mean you have a string of 1 and 0 characters, i.e. "11010011", or that you have a binary byte with those bits set?

For the former, just use the ToCard4R method of the string, and indicate a binary radix. That'll convert it to a Card4 value. Ten you can just format that as hex back out to a string again to get "13".

If it's the later, then just to the last step above.
Dean Roddey
Software Geek Extraordinaire
Its either or both, but you need to take a step back.

I need to construct the binary/string from 8 separate booleans. Each boolean value represents a bit in the byte.
X0 True, X1 False, X2 False, X3 True, ..... X7 True

At the moment I do this to build the card value
If (X0)
   byte++;        //2^0 if field is true
   byte:=byte+(2);        //Add 2^1 if field is true
  byte:=byte+(4);        //Add 2^2 if field is true
   byte:=byte+(128);   //Add 2^7 if field is true

This builds the value up and as a card, which converting to a string as a he value is not the issue

Is there a better way to to do the above then what I have done?

Also, is there an exponential operator, We can do mul, add, gt, lt etc., but I want to try the above in a while look and do a Sum=Sum+(2^i) where i is 0 to 7. This should tidy it up a lot more.
Oh, yeh, I'd use an array of 8 booleans. Then you can use a loop to loop throgh them. To do the bit fliddling, using the ShiftLeft() method of the card value. That will shift the bits left, leaving the 0th bit free again, so you just keep OR'ing each subsequent bit into the accumulator that you are building up the binary value in. Since you have the booleans in an array, you can just do the whole thing in a very simple loop, something like:

   Int4 Index(7);
   Card1 HexVal(0);

While(Index >= 0)
   If (m_BoolArray[Index])
       HexVal |= 1;

You go backwards (7 downwards) because the 0th bit, will be at the 0th position in the array (because that's much more convience because the number of a given bit can be used to just directly access the array.) You only have to look at it backwards at the end when you run the loop like above. So you put the last bit in, shift it left, put the next to the last in, shift it left, and at the end you've built up the whole value.
Dean Roddey
Software Geek Extraordinaire
I wont pretend that I understood much of that.

I am trying to work out now how to get the values into the array as a first step.
I'm back onto this CML black magic....

I am trying to do a simple math operation


where x and w are floats and z & y are Card4 (or integers)

I get an error that both sides need to be the same type.

How do I convert the Card4's to a Float8, there is no ToFloat in the Card4 class?
How do I get around this problem?

w := x * TypeCast(MEng.Float8,z - y);
It's the early bird that catches the worm, but it's the second mouse that gets the cheese...
excellent thanks

And under what class do I find this. I still cant find reference to it in the CML Runtime classes?
It is in the cml guide. I'm not sure it is anywhere in the CML online docs.
It's the early bird that catches the worm, but it's the second mouse that gets the cheese...

Possibly Related Threads...
Thread Author Replies Views Last Post
  RCS V2 Driver kblagron 2 66 06-10-2018, 04:35 PM
Last Post: Dean Roddey
  New Z-Wave driver preview Dean Roddey 13 1,042 05-17-2018, 01:02 PM
Last Post: Dean Roddey
  What device model to put for a Jasco/GE switch? And a questions about V1/V2/V3. ghurty 1 76 05-16-2018, 09:06 PM
Last Post: Dean Roddey
  Sonos Driver with Sonos Connect Amp zra 5 279 05-05-2018, 09:43 AM
Last Post: Dean Roddey
  Radio RA driver issue dogman 7 384 04-22-2018, 08:33 AM
Last Post: Dean Roddey
  Elk Driver fails Ron Haley 11 709 03-08-2018, 07:28 PM
Last Post: Ron Haley
  Nest driver disconnecting and reconnecting dogman 59 5,384 03-08-2018, 05:23 PM
Last Post: dogman
  Aeotec USB stick, existing zWave (v3) driver? IVB 3 316 03-05-2018, 08:57 PM
Last Post: znelbok
  Problem with Jetstream Driver RichardU 16 1,078 02-27-2018, 03:05 PM
Last Post: batwater
  Problem with fooBarV2 driver pjgregory 2 371 02-21-2018, 01:01 PM
Last Post: Dean Roddey

Forum Jump:

Users browsing this thread: 1 Guest(s)