|
70 | 70 |
|
71 | 71 | USBTMC_HEADER_SIZE = 12 |
72 | 72 |
|
| 73 | +RIGOL_QUIRK_PIDS = [0x04ce, 0x0588] |
| 74 | + |
73 | 75 |
|
74 | 76 | def parse_visa_resource_string(resource_string): |
75 | 77 | # valid resource strings: |
@@ -173,6 +175,8 @@ def __init__(self, *args, **kwargs): |
173 | 175 | self.term_char = None |
174 | 176 | self.advantest_quirk = False |
175 | 177 | self.advantest_locked = False |
| 178 | + self.rigol_quirk = False |
| 179 | + self.rigol_quirk_ieee_block = False |
176 | 180 |
|
177 | 181 | self.bcdUSBTMC = 0 |
178 | 182 | self.support_pulse = False |
@@ -326,6 +330,12 @@ def open(self): |
326 | 330 | self.max_transfer_size = 63 |
327 | 331 | self.advantest_quirk = True |
328 | 332 |
|
| 333 | + if self.device.idVendor == 0x1ab1 and self.device.idProduct in RIGOL_QUIRK_PIDS: |
| 334 | + self.rigol_quirk = True |
| 335 | + |
| 336 | + if self.device.idProduct == 0x04ce: |
| 337 | + self.rigol_quirk_ieee_block = True |
| 338 | + |
329 | 339 | self.connected = True |
330 | 340 |
|
331 | 341 | self.clear() |
@@ -495,21 +505,50 @@ def read_raw(self, num=-1): |
495 | 505 | read_data = b'' |
496 | 506 |
|
497 | 507 | while not eom: |
498 | | - req = self.pack_dev_dep_msg_in_header(read_len, term_char) |
499 | | - self.bulk_out_ep.write(req) |
| 508 | + if not self.rigol_quirk or read_data == b'': |
| 509 | + |
| 510 | + # if the rigol sees this again, it will restart the transfer |
| 511 | + # so only send it the first time |
500 | 512 |
|
| 513 | + req = self.pack_dev_dep_msg_in_header(read_len, term_char) |
| 514 | + self.bulk_out_ep.write(req) |
| 515 | + |
501 | 516 | resp = self.bulk_in_ep.read(read_len+USBTMC_HEADER_SIZE+3, timeout = int(self.timeout*1000)) |
502 | 517 |
|
503 | 518 | if sys.version_info >= (3, 0): |
504 | 519 | resp = resp.tobytes() |
505 | 520 | else: |
506 | 521 | resp = resp.tostring() |
| 522 | + |
| 523 | + if self.rigol_quirk and read_data: |
| 524 | + pass # do nothing, the packet has no header if it isn't the first |
| 525 | + else: |
| 526 | + msgid, btag, btaginverse, transfer_size, transfer_attributes, data = self.unpack_dev_dep_resp_header(resp) |
507 | 527 |
|
508 | | - msgid, btag, btaginverse, transfer_size, transfer_attributes, data = self.unpack_dev_dep_resp_header(resp) |
509 | 528 |
|
510 | | - eom = transfer_attributes & 1 |
| 529 | + if self.rigol_quirk: |
| 530 | + # rigol devices only send the header in the first packet, and they lie about whether the transaction is complete |
| 531 | + if read_data: |
| 532 | + read_data += resp |
| 533 | + else: |
| 534 | + if self.rigol_quirk_ieee_block and data.startswith(b"#"): |
| 535 | + |
| 536 | + # ieee block incoming, the transfer_size usbtmc header is lying about the transaction size |
| 537 | + l = int(chr(data[1])) |
| 538 | + n = int(data[2:l+2]) |
| 539 | + |
| 540 | + transfer_size = n + (l+2) # account for ieee header |
511 | 541 |
|
512 | | - read_data += data |
| 542 | + read_data += data |
| 543 | + |
| 544 | + if len(read_data) >= transfer_size: |
| 545 | + read_data = read_data[:transfer_size] # as per usbtmc spec section 3.2 note 2 |
| 546 | + eom = True |
| 547 | + else: |
| 548 | + eom = False |
| 549 | + else: |
| 550 | + eom = transfer_attributes & 1 |
| 551 | + read_data += data |
513 | 552 |
|
514 | 553 | # Advantest devices never signal EOI and may only send one read packet |
515 | 554 | if self.advantest_quirk: |
|
0 commit comments