Skip to content

Commit

Permalink
Always return cached version number
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasstraka committed Sep 5, 2023
1 parent 4b808c6 commit ad3ab52
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
28 changes: 19 additions & 9 deletions pyOxygenSCPI/oxygenscpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self, ip_addr, tcp_port = 10001):
#self.connect()
self._headersActive = True
self.channelList = []
self._scpi_version = (1,5)
self._scpi_version = None
self._value_dimension = None
self._value_format = self.NumberFormat.ASCII
self.elogChannelList = []
Expand All @@ -63,7 +63,7 @@ def connect(self):
sock.connect((self._ip_addr, self._tcp_port))
self._sock = sock
self.headersOff()
self.getVersion()
self._scpi_version = self._read_version()
self._getTransferChannels(False)
self._getElogChannels(False)
self._getElogTimestamp()
Expand Down Expand Up @@ -129,24 +129,34 @@ def _askRaw(self, cmd: str):
log.error(template.format(msg))
return False

def getIdn(self) -> Union[str, bool]:
def getIdn(self) -> Optional[str]:
"""
The query returns a colon-separated four-field ASCII string.
The first field contains the manufacturer name, the second field is the product name,
the third field is the device serial number, and the fourth field is the product revision number
"""
ret = self._askRaw('*IDN?')
if isinstance(ret, bytes):
return ret.decode().strip()
return False
return None

def getVersion(self) -> Optional[Tuple[int, int]]:
def _read_version(self):
"""
SCPI,"1999.0",RC_SCPI,"1.6",OXYGEN,"2.5.71"
"""
ret = self._askRaw('*VER?')
if isinstance(ret, bytes):
ret = ret.decode().strip().split(',')
self._scpi_version = ret[3].replace('"','').split('.')
self._scpi_version = (int(self._scpi_version[0]), int(self._scpi_version[1]))
return self._scpi_version
scpi_version = ret[3].replace('"','').split('.')
return (int(scpi_version[0]), int(scpi_version[1]))
return None

def getVersion(self) -> Optional[Tuple[int, int]]:
"""
Returns the current SCPI version of the server
"""
return self._scpi_version

def reset(self) -> None:
"""
Resets the current SCPI session
Expand Down Expand Up @@ -837,7 +847,7 @@ def __init__(self, oxygen: OxygenSCPI):
def setItems(self, channelNames: List[str], streamGroup=1):
""" Set Datastream Items to be transfered
"""
if not is_minimum_version(self.oxygen._scpi_version, (1,7)):
if not is_minimum_version(self.oxygen.getVersion(), (1,7)):
log.warning('SCPI Version 1.7 or higher required')
return False
channelListStr = '"'+'","'.join(channelNames)+'"'
Expand Down
1 change: 0 additions & 1 deletion tests/test_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def handle_init_sequence(self, client):

def handle_client(self, client):
self.handle_init_sequence(client)
self.handle_ver(client)
self.handle_idn(client)

def run(self):
Expand Down

0 comments on commit ad3ab52

Please sign in to comment.