Skip to content

Commit

Permalink
use glob to find device and use read for binary data
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-demin committed Oct 12, 2017
1 parent 8231437 commit d7049bc
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions PyQtScope.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import os
import sys
import glob
import struct

import usb.core
Expand Down Expand Up @@ -116,7 +117,8 @@ def __init__(self):
self.device.set_configuration()
else:
try:
self.device = open('/dev/usbtmc1', 'r+b')
list = glob.glob('/dev/usbtmc*')
self.device = open(list[0], 'r+b')
except:
pass
while self.device is None:
Expand All @@ -125,7 +127,8 @@ def __init__(self):
sys.exit(1)
elif reply == QMessageBox.Retry:
try:
self.device = open('/dev/usbtmc1', 'r+b')
list = glob.glob('/dev/usbtmc*')
self.device = open(list[0], 'r+b')
except:
pass
else:
Expand All @@ -150,7 +153,7 @@ def transmit_command(self, command):
else:
self.device.write(command + b'\n')

def receive_result(self):
def receive_result(self, size = None):
if os.name == 'nt':
result = b''
stop = 0
Expand All @@ -162,8 +165,10 @@ def receive_result(self):
data = self.device.read(0x85, 1036, 1000).tobytes()
size, stop = struct.unpack_from('<LBxxx', data, 4)
result += data[12:size+12]
else:
elif size is None:
result = self.device.readline()
else:
result = self.device.read(size)
return result

def read_data(self):
Expand Down Expand Up @@ -210,10 +215,10 @@ def read_data(self):
progress.setValue(2)
# read curves
self.transmit_command(b'DAT:SOU CH1;:CURV?')
self.buffer1[:] = self.receive_result()[6:-1]
self.buffer1[:] = self.receive_result(2507)[6:-1]
self.curve1.set_ydata(self.data1)
self.transmit_command(b'DAT:SOU CH2;:CURV?')
self.buffer2[:] = self.receive_result()[6:-1]
self.buffer2[:] = self.receive_result(2507)[6:-1]
self.curve2.set_ydata(self.data2)
self.canvas.draw()
progress.setValue(3)
Expand Down

0 comments on commit d7049bc

Please sign in to comment.