外星RFID阅读器的Python接口

外星RFID阅读器的Python接口,python,rfid,alien,Python,Rfid,Alien,更正。请参阅下面我自己问题的答案 我正试图通过使用Python 2.7的TCP/IP接口与外来RFID 9800阅读器通信。 但是,附加的测试代码不会超出读卡器登录的范围,读卡器也不会处理“get ReaderName”命令。 我使用的是默认用户名(外国人)和密码(密码)。从外星接口可以很好地工作。登录交换有问题吗?什么不对 import socket cmdHost, cmdPort = '192.168.1.106', 23 CmdDelim = '\n' #

更正。请参阅下面我自己问题的答案

我正试图通过使用Python 2.7的TCP/IP接口与外来RFID 9800阅读器通信。
但是,附加的测试代码不会超出读卡器登录的范围,读卡器也不会处理“get ReaderName”命令。
我使用的是默认用户名(外国人)和密码(密码)。从外星接口可以很好地工作。登录交换有问题吗?什么不对

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()

您有一些
打印响应
命令。是否打印任何内容?

在进一步实验后,我可以确认命令终止符对于TCP接口来说只是'\n'[LF],而不是'\r\n'[CR][LR]。因此,如果将上述代码更正为:

CmdDelim = '\n'
现在,一切正常


不幸的是,外星人文档非常明确地指出[CR][LF]是命令终止符。对于串行接口可能是这样,但对于TCP不起作用。

我得到了alien reader头。然而,我没有得到任何其他东西。在检查web上的某些Java代码时,使用“\n”[LR]分隔符,而不是文档中的“\r\n”[CR][LF]。TCP/IP分隔符是否仅为“\n”[LF]?