Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions basil/utils/USBBinds.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import ruamel.yaml


def query_identification(rm, resource, baud_rate, read_termination=None, write_termination=None, timeout=1000 * 5):
def query_identification(rm, resource, baud_rate, read_termination=None, write_termination=None, timeout=1000 * 5, indentifer_cmd="*IDN?", read_after_query=False):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in indentifier

"""
Queries the identification of the instrument connected via USB.

Expand All @@ -31,12 +31,16 @@ def query_identification(rm, resource, baud_rate, read_termination=None, write_t
inst.read_termination = read_termination
inst.write_termination = write_termination
try:
reply = inst.query("*IDN?", delay=0.1)
reply = inst.query(indentifer_cmd, delay=0.1)
except pyvisa.VisaIOError:
# This retries the query a second time, since some devices do not answer the first time.
# If a second exception arrises, it will be handled in calling function.
reply = inst.query("*IDN?", delay=0.1)
return reply
reply = inst.query(indentifer_cmd, delay=0.1)

if read_after_query:
return inst.read()
else:
return reply
Comment on lines +40 to +43

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the SHQ 122m returns as query response the command string as check if the command was executed successfully. To get the return value of an command (or in this case the identification string) one has to additionally perform a read operation.



def find_usb_binds(rm, log,
Expand Down Expand Up @@ -105,7 +109,10 @@ def find_usb_binds(rm, log,
log.debug(f"Found memorized bind {res}")
result = memorized_binds[res]
else:
result = query_identification(rm, res, instrument['baud_rate'], instrument['read_termination'], instrument['write_termination'], timeout=timeout)
if instrument["type"].lower() == "iseg_hv":

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make a global "devices_with_non_default_values" dict, so that it is easier to potentially add more devices there instead of blowing up an if clause?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, will do!

result = query_identification(rm, res, instrument['baud_rate'], instrument['read_termination'], instrument['write_termination'], timeout=timeout, indentifer_cmd="#", read_after_query=True)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same typo as above

else:
result = query_identification(rm, res, instrument['baud_rate'], instrument['read_termination'], instrument['write_termination'], timeout=timeout)

memorized_binds.append({res, result})

Expand Down Expand Up @@ -228,6 +235,8 @@ def modify_basil_config(conf, log, skip_binds=[], save_modified=None):
port = None

instruments.append({
"name": tf["name"],
"type": "", # Standard instruments with *IQN? command

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is happening here exactly? Is this a way to define different devices with non-*IDN? identifier commands?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done to identify serial transfer layers which uses implemented non-*IDN? devices. Without the addition of "name" and "type" in this temporary instrument dictionary the linking in the code block below would not work and thus also not the logic which you commented in your third comment.

TL;DR: The serial transfer layer does not know if it is used for e.g. an SHQ 122M. Therefore this part is needed to identify an instrument correctly.

"identification": instrument,
"baud_rate": baud_rate,
"read_termination": read_termination,
Expand All @@ -236,6 +245,13 @@ def modify_basil_config(conf, log, skip_binds=[], save_modified=None):
})

insts_idx_map[instrument.lower().strip()] = i

for hw_driver in conf["hw_drivers"]:
interface = hw_driver["interface"]
for instrument in instruments:
if instrument["name"].lower().strip() == interface.lower().strip():
instrument["type"] = hw_driver["type"].lower()
break

found_binds = find_usb_binds(rm, log=log, instruments=instruments, binds_to_skip=skip_binds)

Expand Down