Skip to content

Commit

Permalink
Merge branch 'thliebig-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
hgrecco committed Jun 2, 2015
2 parents bc744e6 + 8c0af80 commit ef0fc09
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pyvisa-py/tcpip.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import random
import socket
import select
import time

from pyvisa import constants, attributes
Expand Down Expand Up @@ -333,11 +334,10 @@ def after_parsing(self):
# TODO: board_number not handled

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

self.interface.setblocking(0)

try:
self.interface.connect((self.parsed.host_address, self.parsed.port))
self.interface.connect_ex((self.parsed.host_address, int(self.parsed.port)))
except Exception as e:
raise Exception("could not create socket: %s" % e)

Expand Down Expand Up @@ -374,7 +374,7 @@ def read(self, count):

end_byte = common.int_to_byte(end_char) if end_char else b''

read_fun = self.socket.recv
read_fun = self.interface.recv

now = start = time.time()

Expand All @@ -387,6 +387,8 @@ def read(self, count):
constants.StatusCode.success_termination_character_read)

while now - start <= timeout:
# use select to wait for read ready
select.select([self.interface], [], [])
last = read_fun(chunk_length)

if not last:
Expand Down Expand Up @@ -429,7 +431,9 @@ def write(self, data):
block = data[offset:min(offset+chunk_size, sz)]

try:
size = self.socket.send(block)
# use select to wait for write ready
select.select([], [self.interface], [])
size = self.interface.send(block)
except socket.timeout as e:
return offset, StatusCode.error_io

Expand Down

0 comments on commit ef0fc09

Please sign in to comment.