Skip to content

Commit

Permalink
Merge pull request #114 from Galvant/cc1-adding-ack
Browse files Browse the repository at this point in the history
Cc1 adding ack
  • Loading branch information
scasagrande committed May 13, 2016
2 parents a0fec6a + 3558a65 commit a943f9e
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 16 deletions.
13 changes: 6 additions & 7 deletions doc/examples/ex_qubitekk_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
from sys import platform as _platform

import instruments as ik

import Tkinter as tk
import tkinter as tk
import re


Expand Down Expand Up @@ -88,10 +87,10 @@ def reset(*args):
# open connection to coincidence counter. If you are using Windows, this will be a com port. On linux, it will show
# up in /dev/ttyusb
if _platform == "linux" or _platform == "linux2":
cc = ik.qubitekk.CC1.open_serial('/dev/ttyUSB0', 19200, timeout=1)
cc = ik.qubitekk.CC1.open_serial('/dev/ttyUSB0', 19200, timeout=10)
else:
cc = ik.qubitekk.CC1.open_serial('COM8', 19200, timeout=1)
print cc.firmware
cc = ik.qubitekk.CC1.open_serial('COM9', 19200, timeout=10)
print(cc.firmware)
# i is used to keep track of time
i = 0
# read counts every 0.5 seconds
Expand Down Expand Up @@ -191,8 +190,8 @@ def reset(*args):
tk.Button(mainframe, text="Clear Counts", font="Verdana 24", command=clear_counts).grid(column=2, row=10,
sticky=tk.W)

tk.Label(mainframe, text="Firmware Version: " + cc.firmware, font="Verdana 20").grid(column=1, row=11,
columnspan=2, sticky=tk.W)
tk.Label(mainframe, text="Firmware Version: " + str(cc.firmware),
font="Verdana 20").grid(column=1, row=11, columnspan=2, sticky=tk.W)

for child in mainframe.winfo_children():
child.grid_configure(padx=5, pady=5)
Expand Down
44 changes: 44 additions & 0 deletions instruments/qubitekk/cc1.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,35 @@ def __init__(self, filelike):
self.terminator = "\n"
self._channel_count = 3
self._firmware = None
self._ack_on = False
self.sendcmd(":ACKN OF")
# a readline is required because if the firmware is prior to 2.2,
# the cc1 will respond with 'Unknown Command'. After
# 2.2, it will either respond by acknowledging the command (turning
# acknowledgements off does not take place until after the current
# exchange has been completed), or not acknowledging it (if the
# acknowledgements are off). The try/except block is required to
# handle the case in which acknowledgements are off.
try:
self.read(-1)
except OSError:
pass
_ = self.firmware # prime the firmware

if self.firmware[0] >= 2 and self.firmware[1] > 1:
self._bool = ("ON", "OFF")
self._set_fmt = ":{}:{}"
self.TriggerMode = self._TriggerModeNew

else:
self._bool = ("1", "0")
self._set_fmt = ":{} {}"
self.TriggerMode = self._TriggerModeOld

def _ack_expected(self, msg=""):
return msg if self._ack_on and self.firmware[0] >= 2 and \
self.firmware[1] > 1 else None

# ENUMS #

class _TriggerModeNew(Enum):
Expand Down Expand Up @@ -119,6 +137,32 @@ def count(self):

# PROPERTIES #

@property
def acknowledge(self):
"""
Gets/sets the acknowledge message state. If True, the CC1 will echo
back every command sent, then print the response (either Unable to
comply, Unknown command or the response to a query). If False,
the CC1 will only print the response.
:units: None
:type: boolean
"""
return self._ack_on

@acknowledge.setter
def acknowledge(self, new_val):
if self.firmware[0] >= 2 and self.firmware[1] > 1:
if self._ack_on and not new_val:
self.sendcmd(":ACKN OF")
self._ack_on = False
elif not self._ack_on and new_val:
self.sendcmd(":ACKN ON")
self._ack_on = True
else:
raise NotImplementedError("Acknowledge message not implemented in "
"this version.")

@property
def gate(self):
"""
Expand Down
Loading

0 comments on commit a943f9e

Please sign in to comment.