0

Corrected. See answer to my own question below.

I am trying to communicate with an Alien RFID 9800 reader through the TCP/IP interface with Python 2.7.
However, the attached test code does not get beyond the reader login, and the reader does not process the "Get ReaderName" command.
I am using the default username (alien) and password (password). Things work fine from the Alien interface. Is there something wrong with the login exchange? What isn't right?

import socket

cmdHost, cmdPort = '192.168.1.106', 23

CmdDelim = '\n'               # Corrected from '\n\r' to '\n'.  Delimiter of Alien commands (sent to reader).
ReaderDelim = '\r\n\0'        # Delimiter of Alien reader responses (received from reader).
CmdPrefix = chr(1)            # Causes Alien reader to suppress prompt on response.

def getResponse( conn ):
    ''' Get the reader's response with correct terminator. '''
    response = ''
    while not response.endswith( ReaderDelim ):
        more = conn.recv( 4096 )
        if not more:
            break
        response += more
    return response

def GetReaderName():
    ''' Log into the reader, get the reader name, then quit. '''
    print 'Sending commands to the Alien reader...'
    cmdSocket = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
    try:
        cmdSocket.connect( (cmdHost, int(cmdPort)) )
    except Exception as inst:
        log( 'Reader Connection Failed: CmdAddr=%s:%d' % (cmdHost, cmdPort) )
        log( '%s' % inst )
        cmdSocket.close()
        return False

    # Read the initial header from the reader.
    response = getResponse( cmdSocket )
    print response

    # UserName
    cmdSocket.sendall( 'alien%s' % CmdDelim )
    response = getResponse( cmdSocket )
    print response

    # Password
    cmdSocket.sendall( 'password%s' % CmdDelim )
    response = getResponse( cmdSocket )
    print response

    # Get ReaderName command
    cmdSocket.sendall( '%sGet ReaderName%s' % (CmdPrefix, CmdDelim) )
    response = getResponse( cmdSocket )
    print response

    # Quit
    cmdSocket.sendall( '%sQuit%s' % (CmdPrefix, CmdDelim) )
    response = getResponse( cmdSocket )
    print response

    cmdSocket.close()
    return True

if __name__ == '__main__':
    GetReaderName()
EMS
  • 1,033
  • 1
  • 9
  • 11

2 Answers2

0

You have a some print response commands. Prints anything, or not?

Pavel Stárek
  • 959
  • 5
  • 6
  • I get the alien reader header. However, I don't get anything else. On checking some Java code on the web, a '\n' [LR] delimiter is used rather then the documented '\r\n' [CR][LF]. Is the TCP/IP delimiter just '\n' [LF]? – EMS Feb 18 '13 at 16:38
0

After further experimentation, I can confirm that the command terminator is simply '\n' [LF], not '\r\n' [CR][LR] for the TCP interface. So if the code above is corrected to:

CmdDelim = '\n'

Now, everything works fine.

Unfortunately, the Alien documentation was very specific that [CR][LF] is the command terminator. Perhaps that is true for the serial interface, but it does not work for TCP.

EMS
  • 1,033
  • 1
  • 9
  • 11