OkiePC
Lifetime Supporting Member
It seems that I recall there is a function to find the first bit set in a tag in Crimson. I am reading a fault word from a VFD and converting it to a value which is formatted as multiple states. The states of the tag have the fault text copied from the Yaskawa manual. Multiple bits can be set at any given time, but I will be satisfied to just return a value representing the first bit set in a word.
Right now I am using complex code to do this:
if (FaultWord.0) return 1;
if (FaultWord.1) return 2;
if (FaultWord.2) return 3;
if (FaultWord.3) return 4;
if (FaultWord.4) return 5;
if (FaultWord.5) return 6;
if (FaultWord.6) return 7;
if (FaultWord.7) return 8;
if (FaultWord.8) return 9;
if (FaultWord.9) return 10;
if (FaultWord.10) return 11;
if (FaultWord.11) return 12;
if (FaultWord.12) return 13;
if (FaultWord.13) return 14;
if (FaultWord.14) return 15;
if (FaultWord.15) return 16;
return 0;
The advantage to this is that I could re-order the bit checking to better match the fault bits I may want to prioritize, but I am quite sure there is a simple function to do about the same thing.
Any thoughts?
Right now I am using complex code to do this:
if (FaultWord.0) return 1;
if (FaultWord.1) return 2;
if (FaultWord.2) return 3;
if (FaultWord.3) return 4;
if (FaultWord.4) return 5;
if (FaultWord.5) return 6;
if (FaultWord.6) return 7;
if (FaultWord.7) return 8;
if (FaultWord.8) return 9;
if (FaultWord.9) return 10;
if (FaultWord.10) return 11;
if (FaultWord.11) return 12;
if (FaultWord.12) return 13;
if (FaultWord.13) return 14;
if (FaultWord.14) return 15;
if (FaultWord.15) return 16;
return 0;
The advantage to this is that I could re-order the bit checking to better match the fault bits I may want to prioritize, but I am quite sure there is a simple function to do about the same thing.
Any thoughts?
Last edited: