-
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 all 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 |
|---|---|---|
|
|
@@ -37,7 +37,9 @@ | |
| # connections work, and should be improved. | ||
|
|
||
| from labrad.server import LabradServer, setting | ||
| from labrad import util | ||
| 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 +109,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'): | ||
|
|
@@ -176,10 +173,27 @@ 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 Exception, e: | ||
| util.wakeupCall(.3) | ||
| if n_bytes is None: | ||
| ans = instr.read() | ||
| else: | ||
| ans = instr.read(n_bytes) | ||
|
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. I'd rather not have this delay/retry logic here in the gpib server, since it seems like a device-specific requirement. Ideally, this would go in the device server for the devices that need it. One thing we might want to do is add a setting on the gpib server that just does a delay, so that then the device server could send a single packet that includes the required delays, e.g.: p = cxn.gpib_bus.packet()
p.write(msg).delay(0.1).read()
result = yield p.send()
result.readYou could also do multiple writes with interleaved delays, etc, but all in one packet to the gpib bus server. Similarly, we could add a delay parameter to the |
||
| # Handles a special use case for a device (Rigol DG1022) that | ||
| # returns an address with ,, instead of ,. | ||
| if ",," in ans: | ||
| ans = ans.replace(",,", ",") # rigol specific stupidity | ||
|
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. what's going on here?
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. I added a clarifying comment in https://github.com/CampbellGroup/servers/commit/66b48359c2ac336a5ea292f17bec261f374338cc. With this device connected we get the following with pyvisa 1.7. >>> import visa
>>> rm = visa.ResourceManager()
>>> rigol = rm.get_instrument('USB0::0x09C4::0x0400::DG1D150900538::INSTR')
>>> rigol.write('*IDN?')
>>> rigol.read()
u'RIGOL TECHNOLOGIES,DG1022 ,DG1D150900538,,00.03.00.09.00.02.11\n'The double commas, before 00.03 are the use case we are taking care of. |
||
| 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.