Banner PresencePLUS BCR 1.3 Series User Manual

Page 79

Advertising
background image

connect_error:
RETURN

.END

;
; Close the TCP connection
;
.PROGRAM tcp_close()

.ret_val = 0 ; Initialize the return value

TCP_CLOSE .ret_val, tcp_sock_id

; Check for errors
IF (.ret_val < 0) THEN
PRINT "Unable to close TCP connection, error id = ", .ret_val
ELSE
PRINT "TCP Connection has been closed"
END
.END

;
; Receive data over TCP connection
;
.PROGRAM tcp_recv(.ret_val, .$receive)
.ret_val = 0 ; Initialize the return value
.error_return = -99 ; Return value from TCP_RECV
.timeout_recv = 60 ; Timeout of 60 seconds
.max_recv_len = 255 ; Maximum length of single string element
.$receive = "" ; Empty the return string
.num_elem_recv = 0 ; Number of elements received

; Read the TCP socket
TCP_RECV .error_return, tcp_sock_id, .$recv_buf[1], .num_elem_recv,
.timeout_recv, .max_recv_len

; Process data
IF .error_return < 0 THEN
PRINT "Error receiving data, TCP_RECV error #", .error_return
.ret_val = -1
ELSE
IF .num_elem_recv > 0 THEN

; Ensure the combined return string element lengths do
; not exceed 255 (maximum allowed length of string) – the
; multiplication allows .max_recv_len to be less than 255
IF .num_elem_recv * .max_recv_len <= 255 THEN

; Copy all of the received elements into output buffer
FOR .j = 1 TO .num_elem_recv
.$receive = .$receive+.$recv_buf[.j]
END

79

Banner Engineering Corp. - Minneapolis, MN USA - www.bannerengineering.com

Tel: 763.544.3164

P/N 000000

System Setup Window Overview

7/2009

Advertising
This manual is related to the following products: