Chroma 61604/pychroma.py

From sigrok
Revision as of 18:00, 1 May 2015 by Mrnuke (talk | contribs) (Created page with " <nowiki> """This module implements the Chroma AC Source control.""" import sigrok.core as sr from sigrok.core.classes import ConfigKey class ACSource(object): sr_ctx = 0...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
"""This module implements the Chroma AC Source control."""

import sigrok.core as sr
from sigrok.core.classes import ConfigKey


class ACSource(object):
	sr_ctx = 0

	def __init__(self, port, portcomm='19200/8n1', model=0):
		if not ACSource.sr_ctx:
			ACSource.sr_ctx = sr.Context.create()

		driver = ACSource.sr_ctx.drivers['scpi-pps']
		devs = driver.scan(conn=port, serialcomm=portcomm)

		if not devs:
			raise hell

		self.device = devs[0]

		if model and model != self.device.model:
			print('Expected model %s, but found model %s on port %s'
			      % (model, self.device.model, port))
			raise hell
		self.device.open()

		self.output = self.device.channel_groups['1']

	def set_param(self, what, value):
		sr_key = ConfigKey.get_by_identifier(what)
		self.output.config_set(sr_key, value)

	def read_param(self, what):
		sr_key = ConfigKey.get_by_identifier(what)
		return self.output.config_get(sr_key)

	def enable_output(self):
		self.set_param('output_enabled', True)

	def disable_output(self):
		self.set_param('output_enabled', False)

	def set_voltage(self, volts):
		self.set_param('output_voltage_target', volts)

	def set_ocp_limit(self, amps):
		self.set_param('ocp_threshold', amps)

	def get_ocp_limit(self):
		return self.set_param('ocp_threshold')

	def set_ovp_limit(self, amps):
		self.set_param('ovp_threshold', amps)

	def get_ovp_limit(self):
		return self.set_param('ovp_threshold')

	def measure_voltage(self):
		return self.read_param('output_voltage')

	def measure_current(self):
		return self.read_param('output_current')