0

I'm using Codesys V3 ST language I'm writing a code to communicate motor controller unit which uses CANOpen protocol I want to use CAN raw messages to communicate

I put CAN bus messages bytes in an array -- myDataFF82 : ARRAY [0..7] OF BYTE; //(incoming message)

Then I put together first byte and second byte

raw := UserVarGlobal.myDataFF82[1] ; 
raw1 := UserVarGlobal.myDataFF82[0] ;
raw2 := MEM.PackBytesToWord(byHighByte:=raw1 , byLowByte:=raw); //real message is '01F4' which is Hex

At this point I want to convert '01F4' into Decimal value ('01F4' Hex is '500' in Dec)

I don't see any function to do that in Codesys Can you help?

Thank you in advance

2
  • 2
    Either you are mixing something, or I can't understand what you are trying to do. Talking about hexadecimal/decimal numbers only makes sense when we are dealing with strings. If you have a WORD with some value, you can already use it however you want, no conversion is necessary. Commented Jul 6, 2024 at 13:01
  • Thanks @Guiorgy you gave me insight how to solve my problem. no conversion needed. cheers. Commented Jul 7, 2024 at 6:00

1 Answer 1

1

You do not convert HEX to DEC because there is no conversion, it is the same set of bits. It is only a matter of representation. You can see the number as a HEX or as a DEC

a := 16#01F4;
b := 500;

You assign equal value to a and b, but you write this value as HEX or DEC.

Sign up to request clarification or add additional context in comments.

1 Comment

Cheers thank you @Sergey Romanov

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.