首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >到Alien RFID读取器的Python接口

到Alien RFID读取器的Python接口
EN

Stack Overflow用户
提问于 2013-02-18 20:46:10
回答 2查看 1.5K关注 0票数 0

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

我正在尝试使用Python 2.7通过TCP/IP接口与Alien RFID 9800读取器通信。

但是,附加的测试代码不会超出读取器登录,并且读取器不会处理"Get ReaderName“命令。

我使用的是默认用户名(外国人)和密码(密码)。在Alien界面中,一切运行正常。登录交换有什么问题吗?有什么不对吗?

代码语言:javascript
复制
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()
EN

回答 2

Stack Overflow用户

发布于 2013-02-18 21:57:31

您有一些print response命令。打印任何东西,还是不打印?

票数 0
EN

Stack Overflow用户

发布于 2013-02-19 01:33:39

经过进一步的实验,我可以确认对于TCP接口,命令终止符只是'\n‘LF,而不是'\r\n’CR。因此,如果将上面的代码更正为:

代码语言:javascript
复制
CmdDelim = '\n'

现在,一切工作正常。

不幸的是,Alien文档非常明确地指出CR是命令终止符。这可能适用于串行接口,但不适用于TCP。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14936683

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档