mpylab.device.communication_gpib module

This is the mpylab.device.communication_gpib module.

author:

Hans Georg Krauthäuser (main author)

license:

GPLv3 or higher

class mpylab.device.communication_gpib.CommunicationGpib(res_name, lock=None, timeout_s=3, chunk_size=20480, query_delay_s=0, send_end=True, read_term=None, write_term=None)

Bases: object

CommunicationGpib class.

query(cmd, tmpl=None, send_opc=False)
Parameters:
  • cmdstr, command to send

  • tmplstr, a re pattern for re.match or None

  • send_opcbool, append ; *OPC? to a non-query command

Returns:

str or dict or None: dict with the parsed result

See read function for more explanation regarding the re pattern

read(tmpl=None)
Parameters:

tmplstr, 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

write(cmd)
Parameters:

cmdstr, command to send

Returns:

int: status code; number of bytes sent or 0