I have use following function I made. Remember to select correct notation you need and change it inside my function.
I guess you can also try to change your group input to analog input and use it directly. I think you can search this forum to find thread about it.
FUNC num GetSIntGi(
VAR signalgi giRead)
! Function: GetSIntGi 4.9.2006
! Get signed integer from 16bit (bits 0-15) group input.
! Bit 15 is the sign bit, so values equal or bigger than 32768 are negatives
! and needed to be converted to corresponding negative decimal value
VAR num notation;
VAR num value;
! There are 2 interpretations for negative binary numbers.
! Select which notation to use for negative binary numbers.
! notation:=1 – sign magnitude notation - Returned values are between -32767 to 32767
! notation:=2 – two’s complement notation - Returned values are between -32768 to 32767
notation:=2;
! Get the integer value from group input (from PLC)
value:=0;
value:=GInput(giRead);
! Convert unsignad integer to the signed integer according the notation used by PLC
IF notation=1 THEN
! Sign magnitude notation
! bit15 is sign bit, otherwise same as positive binary numbers
IF value>32767 THEN
value:=32768-value;
ENDIF
ELSEIF notation=2 THEN
! Two’s complement notation
! bit15 is sign bit, negative values are inverted and added 1
IF value>32767 THEN
value:=value-65536;
ENDIF
ELSE
! Notation not set.
! Return value as it is read.
ENDIF
RETURN value;
ENDFUNC