Skip to content

Commit

Permalink
Extend to all power supply channels, each with both voltage and current
Browse files Browse the repository at this point in the history
  • Loading branch information
ivalaginja committed Dec 11, 2023
1 parent 11bca01 commit 734bec7
Showing 1 changed file with 40 additions and 12 deletions.
52 changes: 40 additions & 12 deletions catkit2/services/aim_tti_plp/aim_tti_plp.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,65 @@ def __init__(self):
super().__init__('aim_tti_plp')

self.visa_id = self.config['visa_id']
self.channel = self.config['channel']
self.max_volts = self.config['max_volts']
self.max_current = self.config['max_current']

self.current = self.make_data_stream(f'current', 'float32', [1], 20)
self.voltage = self.make_data_stream(f'voltage', 'float32', [1], 20)
self.lock = threading.Lock()

self.streams = {}
self.stream_names = ['voltage', 'current']
self.stream_threads = {}
for channel_name in self.config['channels']:
self.add_channel(channel_name)

def add_channel(self, channel_name):
for name in self.stream_names:
stream = channel_name.lower() + '_' + name
self.streams[stream] = self.make_data_stream(stream, 'float32', [1], 20)

def open(self):
self.device = AimTTiPPL(self.visa_id)
self.device.open()

if not self.device.isOutputOn(self.channel):
self.device.outputOn(self.channel)
for channel_name in self.config['channels']:
if not self.device.isOutputOn(channel_name['channel']):
self.device.outputOn(channel_name['channel'])

def main(self):
# Start channel monitoring threads
for channel_name in self.channels.keys():
thread = threading.Thread(target=self.monitor_channel, args=(channel_name,))
thread.start()

self.channel_threads[channel_name] = thread

while not self.should_shut_down:
time.sleep(0.01)

for thread in self.channel_threads.values():
thread.join()
self.channel_threads = {}

def monitor_channel(self, channel_name):
while not self.should_shut_down:
try:
# Get an update for this channel
voltage = self.voltage.get_next_frame(10).data[0]
current = self.current.get_next_frame(10).data[0]
self.channels[channel_name].get_next_frame(10)

self.device.setVoltage(voltage, channel=self.channel)
self.device.setCurrent(current, channel=self.channel)
# TODO: differentiate between voltage and current, then apply respective command
self.device.setVoltage(voltage, channel=self.config[self.channels[channel_name]]['channel'])
self.device.setCurrent(current, channel=self.config[self.channels[channel_name]]['channel'])

except Exception:
# Timed out. This is used to periodically check the shutdown flag.
continue

def close(self):
self.device.setVoltage(0, channel=self.channel)
self.device.setCurrent(0, channel=self.channel)
for channel_name in self.config['channels']:
self.device.setVoltage(0, channel=channel_name['channel'])
self.device.setCurrent(0, channel=channel_name['channel'])
self.device.outputOff(channel_name['channel'])

self.device.outputOff(self.channel)
self.device.setLocal()
self.device.close()

Expand Down

0 comments on commit 734bec7

Please sign in to comment.