Technical FAQs

Ask a Question

How to manage 16bit UINT ( range 0-65535) variables inside a M221/SoMachineBasic application?

The 16 bit  available variables %MWi are named/described as WORD, but in reality works  always same as INT , signed 16 bit value range (-32768;+32767)
(means into an animation table the value  45000 inside %MWx is seen -20536, and this is not possible to enter any value>32767  from the animation table)

For local variables , we know there are positive  with some maximum value equal to something >32767 ( it’s definition of UNIT) , then is necessary only to use  a 32bit format %MD instead a %MW into the whole program

For variables exchanged IN/OUT with some device outside of the M221, sometimes there is no choice, the 16 bit format of the variable is defined/fixed with the 3rd device equipement
    Exemple:   the object %MWa is writen into the M221 over modbus communication , and we need to use this value inside the M221 application, within arithmetic operations

Then, we need to use in addition to the initial %MWa, another variable %MDb  and an operation to transform  the %MWa into %MDb by keeping the initial positive UINT value.
For that purpose we have to use only this operation
                              %MDb := CONCATW(%MWa, 0 )   ,                 it’s forcing the upper word being 0
Result is :
If %MWa=2000;  then %MDb=2000
If %MWa=45000 (-20536 seen)  then %MDb=45000
Was this helpful?
What can we do to improve the information ?