Convert data from decimal to hex and transmit via CanBus

  • Software
  • Convert data from decimal to hex and transmit via CanBus
ersin basaran

Posted on 12.07.2024 19:36

Hi

I am trying to send a data to 3rd party device with CanBus

For example:

The set value is 1000. It equals to 03 E8 in hex format. And I will create a Can message including 2 x 8-bit channels. " 03 " will transfer with one channel and "E8" with the other one. What is the easiest way to do this?

Thx in advance

Nejc Ucman

Posted on 16.07.2024 09:27

Dear Esrin,


If I understand correctly, you want to split the bits in the CAN message and create two channels from one. I'm not sure you can do that in DewesoftX natively. Maybe it could be done in Dewesoft Math, but I haven't found a straightforward way. Perhaps it would be easier to do this on the device that is reading the data?


Can I ask you what the application for this is, maybe we can figure a different solution for your problem?


Best Regards,

Nejc Ucman,

Customer Support Engineer

ersin basaran

Posted on 16.07.2024 18:34

The problem was solved. I assume that it is not the easiest way but the only one i found.

Basically, I converted to value from base-10 to base-16. To do this: I created 4 different one-byte-signals in one CAN message and used mod and div functions in math. According to byte order;

Last byte is equal to the value div 16^6

And for the next one; (value mod 16^6) div 16^4

And ((value mod 16^6) mod 16^4) div 16^2 ....

:)


Nejc Ucman

Posted on 17.07.2024 06:42

Dear Ersin,


Thank you for letting me know you have found a solution. Using mod and div in Math is a good trick!


Best Regards.

Harley Hahn

Posted on 13.11.2024 09:15

Thanks for sharing your effective solution. Using division and remainder (mod and div geometry dash scratch) to convert values ​​from base Converting 10 to hexadecimal and splitting it into separate bytes is actually a smart approach.

Login to reply to this topic. If you don't have account yet, you can signup for free account .