fix a connection timeout bug

When connecting to a fast reacting server, if may be possible that
the "_communicate" function sends it command earlier than the question
for the SECoP version inside the "_inner_run" function. A new variable
showing the connection status forces to wait inside "_communicate".

Change-Id: Id521bbd53fea9e2e980b9c11b849d36cfdeb1ec2
Signed-off-by: Lutz Rossa <rossa@helmholtz-berlin.de>
Reviewed-on: https://forge.frm2.tum.de/review/17006
Tested-by: JenkinsCodeReview <bjoern_pedersen@frm2.tum.de>
Reviewed-by: Enrico Faulhaber <enrico.faulhaber@frm2.tum.de>
This commit is contained in:
Lutz Rossa 2018-01-09 13:47:33 +01:00 committed by Enrico Faulhaber
parent 8220067795
commit 79d91d1f23

View File

@ -29,6 +29,7 @@ from select import select
import threading
from collections import OrderedDict
import time
import serial
# Py2/3
@ -164,6 +165,7 @@ class Client(object):
secop_id = 'unknown'
describing_data = {}
stopflag = False
connection_established = False
def __init__(self, opts, autoconnect=True):
if 'testing' not in opts:
@ -234,6 +236,7 @@ class Client(object):
while not self.stopflag:
line = self.connection.readline()
self.connection_established = True
self.log.debug('got answer %r' % line)
if line.startswith(('SECoP', 'SINE2020&ISSE,SECoP')):
self.log.info('connected to: ' + line.strip())
@ -467,6 +470,9 @@ class Client(object):
# send request
msg = self.encode_message(msgtype, spec, data)
while not self.connection_established:
self.log.debug('connection not established yet, waiting ...')
time.sleep(0.1)
self.connection.writeline(msg)
self.log.debug('sent msg %r' % msg)