ACR9000 Ethernet Stream Connection Status Sample

'This is an example of reading through the various "Command Connections" to
'determine which STREAM a device has connected through.  It will then open that
'STREAM to allow PRINT, INPUT, GETCH and other ASCII communication commands to be
'used by programs to control external devices

'This program uses FOR-NEXT loops to make the program very concise.

'Command Connection P-parameters
'Connection #                             0     1     2    3     4 
'----------------------------------------------------------
'Connection Status                    7680  7688  7696  7704  7712 
'Client's IP Address                   7681  7689  7697  7705  7713 
'Client's IP Port                          7682  7690  7698  7706  7714 
'Attached ACR Stream Number  7684  7692  7700  7708  7716 

#DEFINE CmdConn LV0
#DEFINE ConnStatus LV1
#DEFINE ClientIPOctet LV2     : REM last group of numbers of IP address
#DEFINE StreamUsed LV3       : REM which Stream is used for the device
#DEFINE ConnStream LV4      : REM used to reference the P-parameters for
#DEFINE ConnectedIP LV5
#DEFINE DeviceNumber LV7

 

PROGRAM
DIM LV10
_start
IF (BIT24) THEN GOSUB Connect
IF (BIT25) THEN GOSUB Disconnect
GOTO start

_Connect
DeviceNumber = 0 : REM reset the device number back to zero when connecting again
ClientIPOctet = 35 : REM I am looking for device with IP address xxx.xxx.xxx.35
FOR CmdConn = 0 TO 4 STEP 1
StreamUsed = 0
    ConnStatus  = 7680 + CmdConn * 8  : REM determine parameters to check for the desired command connection
    ConnectedIP = 7681 + CmdConn * 8
    ConnStream  = 7684 + CmdConn * 8

    IF ((P(ConnStatus) = 1) OR (P(ConnStatus) = 2))
        DeviceNumber = DeviceNumber + 1 : REM increment what device # we OPEN, this allows up to 3 devices to be used.
        PRINT "Command ";CmdConn;" Connected: ";
        IF (ClientIPOctet = (P(ConnectedIP) AND 255))
        print "IP Matched: ";
            StreamUsed = P(ConnStream)
            ENDIF
        ENDIF
    IF (DeviceNumber > 3) THEN PRINT "Too many devices opened, cannot open another, ending..." : BREAK
    IF (StreamUsed = 2) THEN OPEN "STREAM2:" AS #(DeviceNumber) : PRINT "Connected Stream 2"
    IF (StreamUsed = 3) THEN OPEN "STREAM3:" AS #(DeviceNumber) : PRINT "Connected Stream 3"
    IF (StreamUsed = 4) THEN OPEN "STREAM4:" AS #(DeviceNumber) : PRINT "Connected Stream 4"
    IF (StreamUsed = 5) THEN OPEN "STREAM5:" AS #(DeviceNumber) : PRINT "Connected Stream 5"
NEXT
INH -24 : REM debounce switch
RETURN
_Disconnect
PRINT "CLOSING #1" : CLOSE #1
PRINT "CLOSING #2" : CLOSE #2
PRINT "CLOSING #3" : CLOSE #3
INH-25 : REM debounce switch
RETURN
ENDP