0
Answered

shl and shr - function do not work on MAC

Andy Pauly 2 weeks ago in IQANdesign updated by Gustav Widén (System support) 3 days ago 7

Hello

I need to send out a 8 digit numbers on the JPOUT-J1939 CANBUS in an 4-byte data frame.

IQAN only handle 7 digits so I split up the number in two MAC blocks to be send in 2xJPOUT 2 bytes

But the shift-bits to the left and shift byte to the right  [shl] and [shr] only works on JPOUT; JPIN; GPOUT and GPIN - channels. shl+shr-problem.idsx

Instead of a MAC channel I had to use a JPOUT channels to get the shl to work. I even have to put the data on the J1939 bus only to get the shl to work? Why is shl and shr not avaiable with a math channel???,

Regards

Andy

Answer

Answer

I does work in the MAC channel.

You do have a round down or up function, it is "Floor(xxx)" or "Ceil(xxx)"

I did some changes and used the bitwise and function to simplify your function.

shl+shr-problem (2).idsx

1st 2bytes

Result:= (round(xxxxxx*100) band 65535 )+ yy

2nd 2bytes

Result:= Round(xxxxxx*100) shr 16

Hello Andy.

You can only use the the bitwise shift on integer value types.

That is why you can use it on the JPOUT channel but not the function parameter that has the value type real.

If you use a integer parameter instead of the function parameter it will work.

Or you can use the round function on the parameter you have in the math to make it to a integer.

something like this;

Result:= round(xxxxxx) shr 16

Hello

I still do not know why this function is not allow to be used in MAC channels. Sorry.

I programmed already the alternative solution.

Regards

Andy

The value type of the MAC channel is also real, so if you want to shift a value from a MAC you need to use the round function on it to convert it to a integer value type.

You do have a Integer math (IMAC) channel that could be used instead also.

Hello

I still do not know why shl and shr is not working on MAC? Sorry. Yes there are ways around it:

My solution around it: 
shl+shr-problem (2).idsx

First 2xbytes:

Var_1:= xxxxxx * 100
Var_2:= Var_1 / 0x10000
Var_22:= Var_2 - 0.5
Var_3:= Round ( Var_2 )
Var_33:= Round ( Var_22 )

if Var_3 = Var_33 then
Var_4:= Var_2 - Var_3
else
Var_4:= Var_2 - Var_33
endif

Result:= Var_4 * 0x10000 + yy

Secound 2x bytes:

Var_1:= xxxxxx * 100
Var_2:= Var_1 / 0x10000
Var_22:= Var_2 - 0.5
Var_3:= Round ( Var_2 )
Var_33:= Round ( Var_22 )

if Var_3 = Var_33 then
Result:= Var_3
else
Result:= Var_33
endif

I also would not mind to have a round up and round-down function. 

Regards

Andy

Answer

I does work in the MAC channel.

You do have a round down or up function, it is "Floor(xxx)" or "Ceil(xxx)"

I did some changes and used the bitwise and function to simplify your function.

shl+shr-problem (2).idsx

1st 2bytes

Result:= (round(xxxxxx*100) band 65535 )+ yy

2nd 2bytes

Result:= Round(xxxxxx*100) shr 16

Hello Thomas

Thanks for the new approaching ideas. Every day you learn with Iqan. 

In the main software the number is coming out of a MAC-Array and not out of a FP.  I still need to use therefore the round up function as shl, shr, band ... does not work in a MAC or Array.

Regards

Andy