Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting socket Timeout on Instrument Class #21

Open
kchau101 opened this issue Jan 23, 2017 · 3 comments
Open

Setting socket Timeout on Instrument Class #21

kchau101 opened this issue Jan 23, 2017 · 3 comments

Comments

@kchau101
Copy link

Reading through the code, seems as though doing:

instrument_handle = "TCPIP::169.254.14.7::INSTR"
c = vxi11.Instrument(instrument_handle)
c.timeout = MY_TIMEOUT_IN_SECONDS

would work appropriately for setting the socket timeout duration.
Unfortunately, it seems the socket timeout duration is the same regardless of me setting this value.
Any thoughts on this?

@alexforencich
Copy link
Contributor

What leads you to believe that the timeout is not set on the socket?

In [1]: import vxi11

In [2]: vxi11.list_devices()
Out[2]: ['192.168.1.108']

In [3]: instr = vxi11.Instrument('192.168.1.108')

In [4]: instr.client

In [5]: instr.open()

In [6]: instr.client
Out[6]: <vxi11.vxi11.CoreClient at 0x7ff6cb26aa58>

In [7]: instr.client.sock.timeout
Out[7]: 11.0

In [8]: instr.timeout
Out[8]: 10

In [9]: instr.timeout = 30

In [10]: instr.client.sock.timeout
Out[10]: 31.0

@kchau101
Copy link
Author

kchau101 commented Jan 23, 2017

I am using your library to search for instruments at predetermined IP addresses and rely on quick timeouts on addresses to make my search reasonably quick. Admittedly, this is a pretty dumb way to do this, but it's what I have to work with. I was using this method, and changing the timeout parameter in the instrument class did not seem to have an effect.

Looking through your code some more, it seems on first connection, the first socket opened on line 260,

self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

as part of TCPClient does not have a timeout set explicitly. Only after a valid connection is established is the timeout set to the socket. I don't believe this is a bug in your implementation, just a weird use case I have.

I managed to set a timeout for initial connections by calling socket.setdefaulttimeout(val) before attempting to communicate with an instrument. This solved my particular issue. After seeing your list_devices() command, I may be abandoning this method sometime in the future.

I'm closing this as I don't think that the average user will need to set this parameter for initial socket connections. I have no idea how VXI-11 is laid out, so I have no idea how useful this info will be to others. Thanks for an amazing library.

@alexforencich
Copy link
Contributor

Aha, I see. You're talking about the timeout for the portmapper call. I will take a look at implementing a good way of setting that. It may also be a good idea to roll a similar function into the list_devices call. Right now it uses UDP broadcast, which is not completely reliable. Having the option to attempt TCP connections to an explicit list could be a useful feature.

@alexforencich alexforencich reopened this Jan 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants