【问题标题】:Python: Receiving Data through Sockets - [Errno 11] Resource temporarily unavailablePython:通过套接字接收数据 - [Errno 11] 资源暂时不可用
【发布时间】:2013-07-10 07:01:58
【问题描述】:

背景

我需要通过 python 与 Tektronix MSO 4104 通信。使用 vxi11 以太网协议和 python 的套接字库通过 LAN 进行通信。

情况

现在这工作得很好;我可以连接到范围,我可以发送任何我想要的命令(例如:<socket object>.send('*IDN?'))。但是,每当一个命令应该发送响应(如 *IDN? 应该这样做)时,我尝试使用 <socket object>.recv(1024) 但我总是收到错误“[Errno 11] 资源暂时不可用。”

我知道连接良好,因为我可以接收到同一个“*IDN?”的信息通过内置的 HTTP 接口提示。

代码

以下是 scope.py 中的 sn-p,它创建了与范围的套接字接口。

import socket
import sys
import time

class Tek_scope(object):
    '''
    Open up socket connection for a Tektronix scope given an IP address
    '''
    def __init__(self, IPaddress, PortNumber = 4000):
        self.s = socket.socket(socket.AF_INET , socket.SOCK_STREAM)
        self.s.connect((IPaddress, PortNumber))
        self.s.setblocking(False)
        print "Scope opened Successfully"

现在要得到错误,我运行以下命令:

import scope # Imports the above (and other utility functions)

scope1 = scope.Tek_scope("10.1.10.15") #Connects to the scope

scope1.s.send('*IDN?') #Sends the *IDN? command to the scope. 

# I have verified these signals are always recieved as I can 
# see them reading out on the display

scope1.s.recv(1024) 

# This should receive the response... but it always gives the error

系统

  • Fedora 16
  • Python 2.7
  • 泰克 MSO4104

问题

那么,为什么我没有收到任何响应我的提示的数据?我忘记了某种准备吗?数据是否在我没有检查的地方?我是不是用错了模块?任何帮助将不胜感激!

【问题讨论】:

    标签: python sockets recv


    【解决方案1】:

    这适用于我使用相同的范围。

    设置 setblocking(True) 并将 \n 添加到 *IDN?命令。

    import socket
    import sys
    import time
    
    class Tek_scope(object):
    
        def __init__(self, IPaddress, PortNumber = 4000):
            self.s = socket.socket(socket.AF_INET , socket.SOCK_STREAM)
            self.s.connect((IPaddress, PortNumber))
            self.s.setblocking(True)
            print "Scope opened Successfully"
    
    scope1 = Tek_scope("10.1.10.15") # Connects to the scope
    
    scope1.s.send('*IDN?\n') # Sends the *IDN? command to the scope. 
    
    print scope1.s.recv(1024) 
    

    【讨论】:

    • 嘿,谢谢!对我来说不幸的是,我最终只是报废了所有内容并用 C 编写了它。但是感谢您的修复!
    猜你喜欢
    • 2016-11-08
    • 2012-11-13
    • 1970-01-01
    • 2017-11-29
    • 2011-08-09
    • 1970-01-01
    • 2018-01-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多