mpylab.device.communication_generic module¶
This is the mpylab.device.communication_generic module.
- author:
Hans Georg Krauthäuser (main author)
- license:
GPLv3 or higher
- mpylab.device.communication_generic.generic_query(query_fn, cmd, tmpl=None, send_opc=False)
- Parameters:
query_fn – device query function
cmd – str, command to send
tmpl – str, a re pattern for re.match or None
send_opc – bool, append
; *OPC?to a non-query command and return the resulting response (usually ‘1’)
- Returns:
str or dict or None: dict with the parsed result
Safety rule: send_opc=True is only allowed for commands that do not already contain a query marker ‘?’, because
<query>; *OPC?may create multiple responses and is transport- / instrument-dependent.
- mpylab.device.communication_generic.generic_read(read_fn, tmpl=None)
- Parameters:
read_fn – device read function
tmpl – str, a re pattern for re.match or None
- Returns:
str or dict or None: dict with the parsed result or raw result as str or None if no match
This is how the pattern works: tmpl = r’Test (?P<dbval>d+) dB’ # d+ matches decimals; here 3 and 0; this is stored with key dbval m = re.match(tmpl, ‘Test 30 dB’) m[‘dbval’] -> ‘30’ # access only one ‘named’ match m.groupdict() -> {‘dbval’: ‘30’} # access all ‘named’ matches
- mpylab.device.communication_generic.generic_write(write_fn, cmd)
- Parameters:
write_fn – function to write to the device
cmd – str, command to send
- Returns:
int: status code; number of bytes sent or 0