Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Really simple CML driver questions
#11
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,

SomeChar.SetOrdinal(ASCII.kETX);
SomeString.AppendChar(SomeChar);
Dean Roddey
Software Geek Extraordinaire
Reply
#12
I have 8 digital inputs represented by a boolean (True/False 1/0)

i.e.

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.

Mick
Reply
#13
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
Reply
#14
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
Code:
If (X0)
   byte++;        //2^0 if field is true
EndIf;
If(X1)
   byte:=byte+(2);        //Add 2^1 if field is true
EndIf;
If(X2)
  byte:=byte+(4);        //Add 2^2 if field is true
EndIf;
...
...
...
If(X7)
   byte:=byte+(128);   //Add 2^7 if field is true
EndIf;

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.
Reply
#15
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:

Code:
Locals=
   Int4 Index(7);
   Card1 HexVal(0);
EndLocals;

While(Index >= 0)
   HexVal.ShiftLeft(1);
   If (m_BoolArray[Index])
       HexVal |= 1;
   EndIf;
   Index--;
EndWhile;

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
Reply
#16
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.
Reply
#17
I'm back onto this CML black magic....

I am trying to do a simple math operation

w=x(z-y)

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?
or
How do I get around this problem?

Mick
Reply
#18
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...
Reply
#19
excellent thanks

And under what class do I find this. I still cant find reference to it in the CML Runtime classes?
Reply
#20
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...
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  music & movie driver experiences and or suggestions zane 1 119 Yesterday, 09:33 AM
Last Post: Dean Roddey
  Simple check before setting Elk M1 to Arm State KenC 7 130 10-03-2017, 05:55 PM
Last Post: Dean Roddey
  Kramer Protocol 2000 driver and VS-1616v Help Please! NightLight 6 245 09-12-2017, 05:08 PM
Last Post: Dean Roddey
  Next V2 driver problem kjaerligkatt 9 294 09-05-2017, 01:33 PM
Last Post: kjaerligkatt
  RCS Thermostat Driver help sic0048 10 599 08-19-2017, 08:01 AM
Last Post: Dean Roddey
  Harmony Hub driver tom 43 4,445 08-17-2017, 09:00 AM
Last Post: Dean Roddey
  ISY Driver not able to change value on a specific switch Sendero 9 721 07-18-2017, 09:54 AM
Last Post: Dean Roddey
  If you got a notification from Nest about the CQC driver Dean Roddey 1 329 07-12-2017, 02:44 PM
Last Post: potts.mike
  Variable Driver Trigger Error zra 4 498 07-06-2017, 01:00 PM
Last Post: zra
  Marantz V2 Driver Feature Request zra 21 1,190 07-06-2017, 10:02 AM
Last Post: Dean Roddey

Forum Jump:


Users browsing this thread: 1 Guest(s)