【问题标题】:Python interface to Alien RFID reader外星人RFID阅读器的Python接口
【发布时间】:2013-02-02 21:44:51
【问题描述】:

已更正。请参阅下面对我自己的问题的回答。

我正在尝试通过 Python 2.7 的 TCP/IP 接口与 Alien RFID 9800 阅读器通信。
但是,附加的测试代码并没有超出阅读器登录,阅读器不处理“获取阅读器名称”命令。
我使用的是默认用户名(外星人)和密码(密码)。外星人界面一切正常。登录交换有问题吗?哪里不对?

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

【问题讨论】:

    标签: python rfid alien


    【解决方案1】:

    你有一些print response 命令。是否打印任何内容?

    【讨论】:

    • 我得到了外星读者的标题。但是,我没有得到任何其他东西。在检查 Web 上的一些 Java 代码时,使用了 '\n' [LR] 分隔符,而不是文档中的 '\r\n' [CR][LF]。 TCP/IP 分隔符是否只是 '\n' [LF]?
    【解决方案2】:

    经过进一步的实验,我可以确认命令终止符只是 '\n' [LF],而不是 TCP 接口的 '\r\n' [CR][LR]。所以如果上面的代码改正为:

    CmdDelim = '\n'
    

    现在,一切正常。

    不幸的是,Alien 文档非常明确地指出 [CR][LF] 是命令终止符。也许串行接口是这样,但对 TCP 就不行了。

    【讨论】:

      猜你喜欢
      • 2016-02-28
      • 2017-05-22
      • 1970-01-01
      • 2014-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多