|
11 | 11 | """ |
12 | 12 | import re |
13 | 13 | import time |
| 14 | +import random |
14 | 15 | import logging |
15 | 16 | from textwrap import fill |
16 | 17 | from inspect import cleandoc |
@@ -506,6 +507,38 @@ def to_send(self, name, waveform): |
506 | 507 | self._driver.write_binary_values(header, waveform, datatype='B') |
507 | 508 | self.write('*WAI') |
508 | 509 |
|
| 510 | + @secure_communication() |
| 511 | + def send_load_awg_file(self, awg_file, filename='setup', timeout=100): |
| 512 | + """Command to send and load and .awg file into the AWG |
| 513 | + awg_file = bytearray |
| 514 | + filename = str |
| 515 | + timeout = float |
| 516 | + """ |
| 517 | + # Add a random int at the the end of the file to make it unique |
| 518 | + filename += str(random.randint(0, 10000)) |
| 519 | + name_str = 'MMEMory:DATA "{}",'.format(filename+'.awg').encode('ASCII') |
| 520 | + size_str = ('#' + str(len(str(len(awg_file)))) |
| 521 | + + str(len(awg_file))).encode('ASCII') |
| 522 | + mes = name_str + size_str + awg_file |
| 523 | + self.write('MMEMory:CDIRectory "/Users/OEM/Documents"') |
| 524 | +# mes = self._driver.read_raw() |
| 525 | + self._driver.write_raw(mes) |
| 526 | + self.write('AWGCONTROL:SRESTORE "{}"'.format(filename+'.awg')) |
| 527 | + |
| 528 | + # Wait for the AWG to finish loading the file |
| 529 | + start_time = time.clock() |
| 530 | + current_file = '' |
| 531 | + while time.clock() - start_time <= timeout and\ |
| 532 | + filename not in current_file: |
| 533 | + time.sleep(0.5) |
| 534 | + try: |
| 535 | + current_file = self.ask('AWGCONTROL:SNAMe?') |
| 536 | + except VisaIOError: |
| 537 | + continue |
| 538 | + if filename not in current_file: |
| 539 | + raise InstrIOError(cleandoc('''Timeout during AWG file loading''')) |
| 540 | + |
| 541 | + |
509 | 542 | @secure_communication() |
510 | 543 | def clear_sequence(self): |
511 | 544 | """Command to delete the sequence |
|
0 commit comments