Regarding PCAN Explorer Macro

This forum covers issues concerning multiple software products.

Regarding PCAN Explorer Macro

Postby howard » Fri 16. Dec 2011, 17:17

I have an virtual variable which is 4 bytes unsigned type
I have to put this value in a char array before transmitting via PCAN

Set TrimValue = Signals("Trim Value (Set)")

Data(2) = TrimValue.Value/16777216 '2^24 i used this because i think right shift does not work in 'PCAN
Data(3) = TrimValue.Value/65536 '2^16
Data(4) = TrimValue.Value/256 '2^8
Data(2) = TrimValue.Value & &HFF

But Data(2) keeps overflowing.

Please can anyone help me resolve this issue.
howard
 
Posts: 1
Joined: Fri 16. Dec 2011, 17:10

Re: Regarding PCAN Explorer Macro

Postby M.Maidhof » Mon 19. Dec 2011, 10:28

Hi,

to cut a 4byte value into bytes, you should use the integer division "\"

Data(2) = (TrimValue.Value \ 16777216) And &HFF
Data(3) = (TrimValue.Value \ 65536) And &HFF
Data(4) = (TrimValue.Value \ 256) And &HFF

Data[2] was used a second time, sure you want do that, or is it just a typo?

Data(2) = TrimValue.Value & &HFF will not work in that way, it will add 255 to an existing value:
example: TrimValue.Value = 10 , the result of your line will be 10255 than.

here is a better solution:
Data(2) = TrimValue.Value And &HFF

best regards

Michael
M.Maidhof
Support
Support
 
Posts: 1157
Joined: Wed 22. Sep 2010, 13:00
Location: Darmstadt, Germany


Return to Software



cron

This website uses cookies for analytics, for logins to the online shop and the forum, and for the handling of an order. By browsing this website you agree to the use of cookies. Detailed information on their use can be found in our privacy policy.

OKPrivacy Policy