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
  Problem with fooBarV2 driver pjgregory 1 17 Yesterday, 09:48 AM
Last Post: Dean Roddey
  Problem with Jetstream Driver RichardU 4 36 Yesterday, 08:27 AM
Last Post: RichardU
  Does GC-100 Driver Support Tri-Port Cable? Jnetto 18 644 01-29-2018, 08:16 AM
Last Post: RichardU
  Logic Server- Few questions EST 13 321 01-19-2018, 10:53 AM
Last Post: EST
  Nest driver disconnecting and reconnecting dogman 58 2,098 01-17-2018, 12:24 PM
Last Post: Dean Roddey
  SSL certificate for HTTP trigger driver RichardU 7 193 01-16-2018, 09:50 AM
Last Post: Dean Roddey
  Variables Driver jkmonroe 10 268 01-05-2018, 08:29 PM
Last Post: jkmonroe
  Russound V2 Driver - no install button bpaetzold 1 109 12-24-2017, 07:13 PM
Last Post: Dean Roddey
  Is there a driver out there for the Honeywell Wi-Fi Smart Thermostat? ghurty 18 3,595 12-21-2017, 06:29 PM
Last Post: Dean Roddey
  Simple field change trigger action Bugman 15 1,392 10-23-2017, 11:55 AM
Last Post: Dean Roddey

Forum Jump:

Users browsing this thread: 1 Guest(s)