Honeywell TPS Program Control Language(CL) for packing and unpacking digital signals

Some devices like the SLC500 can read single bit but cannot write. The customer is then forced to write a program that takes a numeric value and stores the single bits into this numeric. Then this numeric must be written to the plc and unpacked .

SEQUENCE PEER (PM; POINT PMLMPRMD)

  • This sequence demonstrates how to use the bit-packing and bit-unpacking
  • subroutines. The subroutines can be called as many times as there are
  • numeric values to unpack, without the sequence pre-empting (subject to PM
  • processor overruns)

EXTERNAL PMLMNUM1 -The numeric point containing packed LM flags EXTERNALPMLMNUM2 -The numeric point containing packed PM flags EXTERNAL!BOX - The PM box reference

LOCAL UNPKBIT: LOGICAL ARRAY (1… 16) AT!BOX(11) - Destination for PM flap LOCAL PACKBIT: LOGICAL ARRAY (1- 16) AT! BOX (27) - Origin for PM flags LOCAL UNPKNUM AT NN (80) -Local variable for use in unpack subroutine LOCAL PACKNUM AT NN (79) -Local variable for use in pack subroutine

PHASE DECODE

S1: CALL UNPACK (PMLMNUM1.PV, UNPKBIT) CALL PACK (PMLMNUM2.PV, PACKBIT) GOTO S1 END PEER

SUBROUTINE UNPACK(PACKEDNUM:IN NUMBER; UPBIT:OUT LOGICAL ARRAY (1… 16))


—This subroutine unpacks a PM numeric containing packed digitals —(Probably sent or read from an LM into flags.) —PACKEDNUM is some numeric value containing 16 packed digitals. —UPBIT is the array of flags that will store the digitals. —UNPKNUM is a local numeric variable.

SET UNPKNUM=ABS(PACKEDNUM) -Must remove sign

IF UNPKNUM > 32767 THEN (SET UPBIT (16)=ON; SET UNPKNUM=UNPKNUM- 32768) ELSE SET UPBIT(16)=OFF

IF UNPKNUM > 16383 THEN (SET UPBIT (16)=ON; SET UNPKNUM=UNPKNUM- 16384) ELSE SET UPBIT(16)=OFF

IF UNPKNUM > 8191 THEN (SET UPBIT (16)=ON; SET UNPKNUM=UNPKNUM- 8192) ELSE SET UPBIT(16)=OFF IF UNPKNUM > 4095 THEN (SET UPBIT (16)=ON; SET UNPKNUM=UNPKNUM- 4096) ELSE SET UPBIT(16)=OFF IF UNPKNUM > 2047 THEN (SET UPBIT (16)=ON; SET UNPKNUM=UNPKNUM- 2048) ELSE SET UPBIT(16)=OFF IF UNPKNUM > 1023 THEN (SET UPBIT (16)=ON; SET UNPKNUM=UNPKNUM- 1024) ELSE SET UPBIT(16)=OFF IF UNPKNUM > 511 THEN (SET UPBIT (16)=ON; SET UNPKNUM=UNPKNUM- 512) ELSE SET UPBIT(16)=OFF IF UNPKNUM > 255 THEN (SET UPBIT (16)=ON; SET UNPKNUM=UNPKNUM- 256) ELSE SET UPBIT(16)=OFF IF UNPKNUM > 127 THEN (SET UPBIT (16)=ON; SET UNPKNUM=UNPKNUM- 128) ELSE SET UPBIT(16)=OFF IF UNPKNUM > 63 THEN (SET UPBIT (16)=ON; SET UNPKNUM=UNPKNUM- 64) ELSE SET UPBIT(16)=OFF IF UNPKNUM > 31 THEN (SET UPBIT (16)=ON; SET UNPKNUM=UNPKNUM- 32) ELSE SET UPBIT(16)=OFF IF UNPKNUM > 15 THEN (SET UPBIT (16)=ON; SET UNPKNUM=UNPKNUM- 16) ELSE SET UPBIT(16)=OFF IF UNPKNUM > 7 THEN (SET UPBIT (16)=ON; SET UNPKNUM=UNPKNUM- 8) ELSE SET UPBIT(16)=OFF IF UNPKNUM > 3 THEN (SET UPBIT (16)=ON; SET UNPKNUM=UNPKNUM- 4) ELSE SET UPBIT(16)=OFF IF UNPKNUM > 1 THEN (SET UPBIT (16)=ON; SET UNPKNUM=UNPKNUM -2) ELSE SET UPBIT(16)=OFF

SET UNPKNUM = PACKNUM

END PACK.