-
Notifications
You must be signed in to change notification settings - Fork 21
Usb device fixes #205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Usb device fixes #205
Changes from 2 commits
12922cb
77b14b2
094710d
4d87cae
66b4835
f58ed8e
b397b5b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,7 @@ | |
|
|
||
| from labrad.server import LabradServer, setting | ||
| from twisted.internet.defer import inlineCallbacks | ||
| from twisted.internet import defer | ||
| from twisted.internet.reactor import callLater | ||
| from labrad.errors import DeviceNotSelectedError | ||
| import labrad.units as units | ||
|
|
@@ -107,15 +108,10 @@ def refreshDevices(self): | |
| deletions = set(self.devices.keys()) - set(addresses) | ||
| for addr in additions: | ||
| try: | ||
| if addr.startswith('GPIB'): | ||
| instName = addr | ||
| elif addr.startswith('TCPIP'): | ||
| instName = addr | ||
| elif addr.startswith('USB'): | ||
| instName = addr + '::INSTR' | ||
| else: | ||
| device_prefixes = ('GPIB', 'USB', 'TCPIP') | ||
| if not (addr.startswith(device_prefixes)): | ||
| continue | ||
| instr = rm.get_instrument(instName) | ||
| instr = rm.get_instrument(addr) | ||
| instr.write_termination = '' | ||
| instr.clear() | ||
| if addr.endswith('SOCKET'): | ||
|
|
@@ -145,6 +141,23 @@ def getDevice(self, c): | |
| instr = self.devices[c['addr']] | ||
| return instr | ||
|
|
||
| def asynchronous_wait(self, seconds, result=None): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we have a utility function to do exactly this:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| """ | ||
| Pause the reactor for seconds to wait for GPIB devices that require | ||
| time between read and write calls. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| seconds: float, sleep time in seconds | ||
|
|
||
| Returns | ||
| ------- | ||
| Deferred | ||
| """ | ||
| d = defer.Deferred() | ||
| callLater(seconds, d.callback, result) | ||
| return d | ||
|
|
||
| @setting(0, addr='s', returns='s') | ||
| def address(self, c, addr=None): | ||
| """Get or set the GPIB address for this context. | ||
|
|
@@ -176,10 +189,26 @@ def read(self, c, n_bytes=None): | |
| Otherwise, reads until the device stops sending. | ||
| """ | ||
| instr = self.getDevice(c) | ||
| if n_bytes is None: | ||
| ans = instr.read_raw() | ||
| if instr.resource_name.startswith('USB'): | ||
| try: | ||
| if n_bytes is None: | ||
| ans = instr.read() | ||
| else: | ||
| ans = instr.read(n_bytes) | ||
| except: | ||
|
||
| self.asynchronous_wait(0.1) | ||
|
||
| if n_bytes is None: | ||
| ans = instr.read() | ||
| else: | ||
| ans = instr.read(n_bytes) | ||
|
||
| ans = str(ans) | ||
| if ",," in ans: | ||
| ans = ans.replace(",,", ",") # rigol specific stupidity | ||
|
||
| else: | ||
| ans = instr.read_raw(n_bytes) | ||
| if n_bytes is None: | ||
| ans = instr.read_raw() | ||
| else: | ||
| ans = instr.read_raw(n_bytes) | ||
| return str(ans).strip() | ||
|
|
||
| @setting(5, data='s', returns='s') | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
didn't know you could pass a tuple to
startswith. nice.