Converting Byte Value to Bit (on / off) targetId

Just wondering if there is a way to convert a byte when it is a specific value to an on/off bit type targetId?

Specifically, when the byte value is 13 (decimal) I would like this to on (1) \and every other value off (0).

You could use enum for that:

enum="13:1,#:0"

@realdashdev thanks using enum already but didn’t think of using # to abbreviate all other results, presumably I can’t feed this into targetId143, which is on / off?

I don’t see any reason why you could not.

This didn’t work with the on/off targetId

Yes, if you specify units=“bit”, only the least significant bit is read from the value.

@realdashdev the following example does not work, I assume this is because the units apply to the value and not the enumerated value, although when the value =13, bit 0 is actually set with bits 2 and 3

value targetId=“143” offset=“6” length=“1” units=“bit” enum=“13:1,#:0”

The following works but it can’t be assigned to the targetId which is on/off

value name=“MP: TC_Lockup” offset=“6” length=“1” enum=“13:1,#:0”

If you specify units=“bit”, value can be either 0 or 1. enum is handled after the units conversion, so that is why it does not work with units=“bit”.

Edit: Added conversion for bitwise and, as I do not know what other data may be on those bytes.

Lets see:

- Value 13 in binary is 1101, so we can do a bitwise AND to confirm that those bits (and only those) are on.

value name="MP: TC_Lockup" offset="6" length="1" units="bit" conversion="V & 13"

Also noticed that in your examples you are using special double quota characters, so copy-pasting from your posts probably will not work. For that reason, always use a text editor that immediately shows any syntactic errors in your XML.

1 Like

I have tried this; I am trying to work out my Ignition Status; to get Ignition on (ID167) i’m looking at 5 bits, and Ignition on is value 6 (00110) so using the example above I have this in my XML;

  	<value targetId="167" startbit="19" bitcount="5" units="bit" conversion="V &amp; 6" enum="6:1,#:0"> </value> <!-- Ignition On -->

but it doesn’t work, I just see a value of 0, I am also reading the value into a custom name and using enum I get all the correct values as text; using this;

    <value name="RS: Ignition Status" startbit="19" bitcount="5" enum="9:Cranking, 7:Running, 6:Ign On, 5:Post Ignition, 4:Accessory, 3:Post Accessory, 2:Key Approved, 1:Key Recently Out, 0:Key Out"></value> <!-- Ignition Status -->

So my question is as usual what am I doing wrong :D??

@Cl_eav the units=“bit” means its only looking at the first bit and not the second and third bits which are of interest to you, delete this and it should work

@mmain I just tried that, I used;

<value targetId="167" startbit="19" bitcount="5" conversion="V &amp; 6" enum="6:1,#:0"> </value> <!-- Ignition On -->

and still no change, I ran a datalog as well here is a snap shot…

image

In the datalog, I see the custom value changing, but not the ID167

I think there is a bug, I tried putting the data intoa different target ID, used ID94 (dummy 02) and it works

  	<value targetId="167" startbit="19" bitcount="5" conversion="V &amp; 6" enum="6:1,#:0"> </value> <!-- Ignition On -->
  	<value targetId="94" startbit="19" bitcount="5" conversion="V &amp; 6" enum="6:1,#:0"> </value> <!-- Dummy 03 -->

So I don’t think the XML upload clears all the attribute data against a value, I had this eairler today as well, this kinda confirms the issue? my guess is ID167 still thinks it has units=“bit” even though this is now removed from the XML?

Need away now to “reset” ID167 ?? any idea’s??

@Cl_eav you are right ID167 only accepts a bit result, and your result is the conversion and not the result of the enum, neither are single bit

Hmmm, so what I thought I was doing was converting the value of 6 to 1 using the enum, I see the dummy value shows 1 or 0, which is perfect, so why doesn’t that get set as the bit value for ID167?

Ok I went back to basics,

<value targetId="167" startbit="21" bitcount="1" units="bit"></value> <!-- Ignition On -->

still no joy; the Can Frame looks like this - I have hi lighted the BIT i want

image

Am i missing something, its a Ford, I’ve got other bit values to work, i.e. parking brake, I don’t think i’m doing anything different, I know its been asked before but i’ve not seen a clear answer, how are the bits numbered when using startbit and bitcount?

@Cl_eav I replicated your Kvaser selection and converted to xml with same output as you

Are you getting desired results when assigned to another named value or alternatively another on/off targetId?

@mmain this make’s no sense now!

so:

    <value targetId="167" startbit="21" bitcount="1" units="bit"></value> <!-- Ignition On -->
    <value targetId="182" startbit="21" bitcount="1" units="bit"></value> <!-- Ignition On (Fuel Pump 1) -->
    <value targetId="97" startbit="21" bitcount="1"></value> <!-- Dummy 05 Ignition On -->

ID167 - Does NOT work
ID182 - Does work
ID97 - Does work

Maybe ID167 is labeled wrong? @realdashdev ?

Bit more testing,

I’ve also got a similar problem with mapping the headlight switch, I created a page in the dash to see the values, and added some notes. to get Parking Lights and Low Beam i’m using the following XML;

    <value targetId="96" startbit="56" bitcount="2" conversion="V &amp; 3" ></value>  <!-- Dummy 04 for Lights --> 
    <value targetId="155" startbit="56" bitcount="1"></value> <!-- Parking Lights --> 
    <value targetId="156" startbit="57" bitcount="1" units="bit"></value> <!-- Low Beam --> 

I have also included the dummy 4 so you can see the value is working as expected, but the single bit to ID155 and ID156 doesn’t seem to work either

Ignition


Dummy 2 - is based on enum, swaps the value 6 to a 1 if ign is on

<value targetId="94" startbit="19" bitcount="3" conversion="V &amp; 6" enum="6:1,#:0"></value>

LIghts



@realdashdev - figured it out, I was trying all sorts of combinations, none appeared to be working, I restarted the application, full close and reload and the values started to populate!!!

Arggggghhh, turning it off and back on again fixed the issue! :laughing:

2 Likes

Alright, for now I’d recommend that when you are actively working on the XML, clear all custom values before importing an updated XML. I will investigate why custom values do not update.

1 Like