      SUBROUTINE PLX.TCP.WRITE.FIN(R.PLCB,R.ERR)
*PIC-LAN
*
*ALL
*PC
*N
*
*
*
*
      INCLUDE SYS.TYPE.INCLUDE
*
      INCLUDE PL.DEFS
      DIM CONFIG.ARRAY(50)
      INCLUDE PL.COMMON.DEFS
*
      DIM PLIP$VARS(100)
      INCLUDE PLIP.VARS
*
      CALL PLXX.INIT(MAT CONFIG.ARRAY,MAT PLIP$VARS,0)
*
      CALL PLXX.TCP.STATUS(MAT CONFIG.ARRAY,MAT PLIP$VARS,R.PLCB,ST,R.ERR)
      IF R.ERR <> '' THEN RETURN
*
      BEGIN CASE
         CASE ST < 5
            R.ERR = 'Connection is not OPEN'
         CASE ST = 6 OR ST = 7 OR ST = 9 OR ST = 10 OR ST = 11
            R.ERR = 'Connection has already been CLOSED'
         CASE ST = 5 OR ST = 8
            PL_TCP_CLOSE R.PLCB ELSE
               R.ERR = 'Error during TCP CLOSE'
               CALL PLXX.TCP.RESET(MAT CONFIG.ARRAY,MAT PLIP$VARS,R.PLCB)
            END
         CASE YES
            R.ERR = 'Undefined TCP state ' : ST
      END CASE
*
      RETURN
   END
