示例#1
0
 def __init__(self, com_port):
     self.com_port = com_port
     self.device = KoradSerial(com_port, True)
     self.device.output.off()
     channel = self.device.channels[0]
     channel.voltage = 12.0
     channel.current = 2.0
示例#2
0
    def load(self):
        h5path = time.strftime('/Date_%Y-%m-%d/Time_%H_%M_%S').split('/')
        if '/' + h5path[1] not in self.h5:
            h5group = self.h5.createGroup('/', h5path[1])
        h5group = self.h5.createGroup('/' + h5path[1], h5path[2])
        h5table = self.h5.createTable(h5group, 'load', LoadRow)

        ps = KoradSerial(DEVSERIAL)
        ps.output.off()
        ps.beep.off()
        ch1 = ps.channels[0]
        ch1.current = self.current
        ch1.voltage = self.voltage
        ps.output.on()

        starttime = time.time()

        currenttime = time.time()
        while (currenttime - starttime) < self.maxtime * HOUR_TO_SEC:
            time.sleep(5)
            currenttime = time.time()
            voltage = ch1.output_voltage
            current = ch1.output_current
            print time.ctime(currenttime), 'V: ', voltage, '  I: ', current
            row = h5table.row
            row['time'] = currenttime
            row['voltage'] = voltage
            row['current'] = current
            row.append()
        h5table.flush()

        ps.output.off()
示例#3
0
class PowerSupply():
    def __init__(self, com_port):
        self.com_port = com_port
        self.device = KoradSerial(com_port, True)
        self.device.output.off()
        channel = self.device.channels[0]
        channel.voltage = 12.0
        channel.current = 2.0

    def poweroff(self):
        self.device.output.off()

    def poweron(self):
        self.device.output.on()

    def __del__(self):
        self.device.close()
示例#4
0
def korad(ctx, port):
    """Interfacing a Korad KA3005P power supply.

    If KORADPORT is in the environment, the --port option is optional:
    export KORADPORT=/dev/ttyACM0

    """
    try:
        global korad_device
        korad_device = KoradSerial(port)
    except SerialException as e:
        error(e)
        ctx.exit(1)

    ctx.call_on_close(korad_device.close)
示例#5
0
class KoradSerialTest(TestCase):
    def setUp(self):
        self.device = KoradSerial('/dev/tty.usbmodemfd121', True)
        self.overrideSkippedTests = False

    def tearDown(self):
        self.device.close()

    def _pause(self, delay=1):
        """ Give the power supply time to digest the commands.

        :param delay: How long to pause. The default 1 second is overkill.
        """
        sleep(delay)

    def test_beep(self):
        """ Test the BEEP command.

        According to what I've read on the Internet, and confirmed by my trials, is that BEEP0 doesn't work.

        Thus this test is useless.

        :return:
        """
        if not self.overrideSkippedTests:
            return

        self.device.beep.off()
        status = self.device.status
        self.assertEqual(OnOffState.off, status.beep)

        self._pause()

        self.device.beep.on()
        status = self.device.status
        self.assertEqual(OnOffState.on, status.beep)

    def test_channel1(self):
        """ Test Channel 1's functionality.

        This test assumes a small load (perhaps 100 ohm) is on the power supply so a small amount of current is drawn.
        """
        channel = self.device.channels[0]

        # Turn off output and ensure that it's reading zeroes.
        self.device.output.off()
        self._pause()
        self.assertEqual(0, channel.output_voltage)
        self.assertEqual(0, channel.output_current)

        # Set the current and voltage and ensure it's reporting back correctly.
        channel.voltage = 12.34
        channel.current = 1.234
        self.assertAlmostEqual(12.34, channel.voltage, 2)
        self.assertAlmostEqual(1.234, channel.current, 3)

        # Set a different current and voltage to ensure that we're not reading old data.
        channel.voltage = 3.30
        channel.current = 0.123
        self.assertAlmostEqual(3.30, channel.voltage, 2)
        self.assertAlmostEqual(0.123, channel.current, 3)

        # Turn on the output and ensure that current is flowing across the small load.
        self.device.output.on()
        self._pause()
        self.assertAlmostEqual(3.30, channel.output_voltage, 2)
        self.assertLess(0, channel.output_current)

        self.device.output.off()

    def test_lock(self):
        """ Test the lock state.

        Ha! Just kidding. This is a stub.

        It appears that there is no command to alter the lock state.
        While connected to a serial line and processing commands, the power supply is in a lock state.
        """
        if not self.overrideSkippedTests:
            return

        pass

    def test_memory(self):
        """  Ensure that memory store/recall works.

        A two-step process is required to set a memory.
        *   First, one must choose the memory number with a `recall()` command.
        *   Second, one must set the desired voltage and current limit.
        *   Third, one must save the memory with a `save()` command.

        Recalling a memory setting simply requires calling the `recall()` command.

        This goes through the test twice with different values to ensure what is read isn't old data.
        """
        channel = self.device.channels[0]
        m1 = self.device.memories[0]
        m2 = self.device.memories[1]
        m3 = self.device.memories[2]
        m4 = self.device.memories[3]

        # Pass one with the first set  of values.

        m1.recall()
        channel.voltage = 1.00
        channel.current = 0.100
        m1.save()

        m2.recall()
        channel.voltage = 2.00
        channel.current = 0.200
        m2.save()

        m3.recall()
        channel.voltage = 3.00
        channel.current = 0.300
        m3.save()

        m4.recall()
        channel.voltage = 4.00
        channel.current = 0.400
        m4.save()

        m1.recall()
        self.assertAlmostEqual(1.00, channel.voltage, 2)
        self.assertAlmostEqual(0.100, channel.current, 3)

        m2.recall()
        self.assertAlmostEqual(2.00, channel.voltage, 2)
        self.assertAlmostEqual(0.200, channel.current, 3)

        m3.recall()
        self.assertAlmostEqual(3.00, channel.voltage, 2)
        self.assertAlmostEqual(0.300, channel.current, 3)

        m4.recall()
        self.assertAlmostEqual(4.00, channel.voltage, 2)
        self.assertAlmostEqual(0.400, channel.current, 3)

        # Pass two with different values.

        m1.recall()
        channel.voltage = 5.00
        channel.current = 0.500
        m1.save()

        m2.recall()
        channel.voltage = 10.00
        channel.current = 1.000
        m2.save()

        m3.recall()
        channel.voltage = 15.00
        channel.current = 1.500
        m3.save()

        m4.recall()
        channel.voltage = 20.00
        channel.current = 2.000
        m4.save()

        m1.recall()
        self.assertAlmostEqual(5.00, channel.voltage, 2)
        self.assertAlmostEqual(0.500, channel.current, 3)

        m2.recall()
        self.assertAlmostEqual(10.00, channel.voltage, 2)
        self.assertAlmostEqual(1.000, channel.current, 3)

        m3.recall()
        self.assertAlmostEqual(15.00, channel.voltage, 2)
        self.assertAlmostEqual(1.500, channel.current, 3)

        m4.recall()
        self.assertAlmostEqual(20.00, channel.voltage, 2)
        self.assertAlmostEqual(2.000, channel.current, 3)

    def test_model(self):
        """ Test the IDN command.

        Read the model number from the device.
        """
        model = self.device.model
        self.assertTrue(model.startswith("KORAD"))

    def test_ocp(self):
        """ Test Over Current Protection

        There's no way to get feedback on these, so simply ensure that no exceptions are thrown.
        """
        self.device.over_current_protection.on()
        self._pause()
        self.device.over_current_protection.off()

    def test_ovp(self):
        """ Test Over Voltage Protection

        There's no way to get feedback on these, so simply ensure that no exceptions are thrown.
        """
        self.device.over_voltage_protection.on()
        self._pause()
        self.device.over_voltage_protection.off()

    def test_output(self):
        """ Ensure the device is reporting the output on/off state correctly.
        """
        self.device.output.on()
        status = self.device.status
        self.assertEqual(OnOffState.on, status.output)

        self._pause()

        self.device.output.off()
        status = self.device.status
        self.assertEqual(OnOffState.off, status.output)

    def test_track(self):
        """ Test the TRACK commands.

        **NOTE:** The tests here are hypothetical.
        I don't have a multi-channel power supply to actually test this against.
        """
        if not self.overrideSkippedTests:
            return

        self.device.track(Tracking.parallel)
        status = self.device.status
        self.assertEqual(Tracking.parallel, status.tracking)

        self._pause()

        self.device.track(Tracking.series)
        status = self.device.status
        self.assertEqual(Tracking.series, status.tracking)

        self._pause()

        self.device.track(Tracking.independent)
        status = self.device.status
        self.assertEqual(Tracking.independent, status.tracking)
示例#6
0
global i1Graphic
global i2Graphic

# .ini variables
global ps1Vini
global ps2Vini
global ps1Vmaxini
global ps2Vmaxini
global ps1Imaxini
global ps2Imaxini
global runPS1
global runPS2

maxPSV = 5.0
maxPSI = 5.0
ps1 = KoradSerial(ps1serialPort) # handle def
ps2 = KoradSerial(ps2serialPort) # handle def

# Acquiring initial readings from PS1
ps1currentActual  = ps1.current_actual    # actual current being given out
ps1currentRead    = ps1.current_set         # read what you previously set
ps1deviceStatus   = ps1.status

# Acquiring initial readings from PS2
ps2currentActual  = ps2.current_actual    # actual current being given out
ps2voltageRead    = ps2.voltage_set         # read what you previously set
ps2currentRead    = ps2.current_set         # read what you previously set
ps2deviceStatus   = ps2.status

# Acquiring the values from the INI file
ps1Voltage     = float(parser.get("Settings", 'ps1Voltage'))      # Initial voltage definition for PS1
import ConfigParser
from ConfigParser import SafeConfigParser

# from koradcli import korad

# Definition of serial ports for 2 power supplies
ps1serialPort = 'COM4'  # COMM PORT 1
ps2serialPort = 'COM5'  # COMM PORT 2

# Variable definitions
global ps1
global ps2
global ps1output
global ps2output

ps1 = KoradSerial(ps1serialPort)  # handle def
ps2 = KoradSerial(ps2serialPort)  # handle def
ps1.output = 'off'
ps2.output = 'off'

# Acquiring initial readings from PS1
ps1voltageActual = ps1.voltage_actual  # actual voltage being given out
ps1currentActual = ps1.current_actual  # actual current being given out
ps1voltageRead = ps1.voltage_set  # read what you previously set
ps1currentRead = ps1.current_set  # read what you previously set
ps1deviceStatus = ps1.status

# Acquiring initial readings from PS2
ps2voltageActual = ps2.voltage_actual  # actual voltage being given out
ps2currentActual = ps2.current_actual  # actual current being given out
ps2voltageRead = ps2.voltage_set  # read what you previously set
 def setUp(self):
     self.device = KoradSerial('/dev/tty.usbmodemfd121', True)
     self.overrideSkippedTests = False
class KoradSerialTest(TestCase):
    def setUp(self):
        self.device = KoradSerial('/dev/tty.usbmodemfd121', True)
        self.overrideSkippedTests = False

    def _pause(self, delay=1):
        """ Give the power supply time to digest the commands.

        :param delay: How long to pause. The default 1 second is overkill.
        """
        sleep(delay)

    def test_beep(self):
        """ Test the BEEP command.

        According to what I've read on the Internet, and confirmed by my trials, is that BEEP0 doesn't work.

        Thus this test is useless.

        :return:
        """
        if not self.overrideSkippedTests:
            return

        self.device.beep.off()
        status = self.device.status
        self.assertEqual(OnOffState.off, status.beep)

        self._pause()

        self.device.beep.on()
        status = self.device.status
        self.assertEqual(OnOffState.on, status.beep)

    def test_channel1(self):
        """ Test Channel 1's functionality.

        This test assumes a small load (perhaps 100 ohm) is on the power supply so a small amount of current is drawn.
        """
        channel = self.device.channels[0]

        # Turn off output and ensure that it's reading zeroes.
        self.device.output.off()
        self._pause()
        self.assertEqual(0, channel.output_voltage)
        self.assertEqual(0, channel.output_current)

        # Set the current and voltage and ensure it's reporting back correctly.
        channel.voltage = 12.34
        channel.current = 1.234
        self.assertAlmostEqual(12.34, channel.voltage, 2)
        self.assertAlmostEqual(1.234, channel.current, 3)

        # Set a different current and voltage to ensure that we're not reading old data.
        channel.voltage = 3.30
        channel.current = 0.123
        self.assertAlmostEqual(3.30, channel.voltage, 2)
        self.assertAlmostEqual(0.123, channel.current, 3)

        # Turn on the output and ensure that current is flowing across the small load.
        self.device.output.on()
        self._pause()
        self.assertAlmostEqual(3.30, channel.output_voltage, 2)
        self.assertLess(0, channel.output_current)

        self.device.output.off()

    def test_lock(self):
        """ Test the lock state.

        Ha! Just kidding. This is a stub.

        It appears that there is no command to alter the lock state.
        While connected to a serial line and processing commands, the power supply is in a lock state.
        """
        if not self.overrideSkippedTests:
            return

        pass

    def test_memory(self):
        """  Ensure that memory store/recall works.

        A two-step process is required to set a memory.
        *   First, one must choose the memory number with a `recall()` command.
        *   Second, one must set the desired voltage and current limit.
        *   Third, one must save the memory with a `save()` command.

        Recalling a memory setting simply requires calling the `recall()` command.

        This goes through the test twice with different values to ensure what is read isn't old data.
        """
        channel = self.device.channels[0]
        m1 = self.device.memories[0]
        m2 = self.device.memories[1]
        m3 = self.device.memories[2]
        m4 = self.device.memories[3]

        # Pass one with the first set  of values.

        m1.recall()
        channel.voltage = 1.00
        channel.current = 0.100
        m1.save()

        m2.recall()
        channel.voltage = 2.00
        channel.current = 0.200
        m2.save()

        m3.recall()
        channel.voltage = 3.00
        channel.current = 0.300
        m3.save()

        m4.recall()
        channel.voltage = 4.00
        channel.current = 0.400
        m4.save()

        m1.recall()
        self.assertAlmostEqual(1.00, channel.voltage, 2)
        self.assertAlmostEqual(0.100, channel.current, 3)

        m2.recall()
        self.assertAlmostEqual(2.00, channel.voltage, 2)
        self.assertAlmostEqual(0.200, channel.current, 3)

        m3.recall()
        self.assertAlmostEqual(3.00, channel.voltage, 2)
        self.assertAlmostEqual(0.300, channel.current, 3)

        m4.recall()
        self.assertAlmostEqual(4.00, channel.voltage, 2)
        self.assertAlmostEqual(0.400, channel.current, 3)

        # Pass two with different values.

        m1.recall()
        channel.voltage = 5.00
        channel.current = 0.500
        m1.save()

        m2.recall()
        channel.voltage = 10.00
        channel.current = 1.000
        m2.save()

        m3.recall()
        channel.voltage = 15.00
        channel.current = 1.500
        m3.save()

        m4.recall()
        channel.voltage = 20.00
        channel.current = 2.000
        m4.save()

        m1.recall()
        self.assertAlmostEqual(5.00, channel.voltage, 2)
        self.assertAlmostEqual(0.500, channel.current, 3)

        m2.recall()
        self.assertAlmostEqual(10.00, channel.voltage, 2)
        self.assertAlmostEqual(1.000, channel.current, 3)

        m3.recall()
        self.assertAlmostEqual(15.00, channel.voltage, 2)
        self.assertAlmostEqual(1.500, channel.current, 3)

        m4.recall()
        self.assertAlmostEqual(20.00, channel.voltage, 2)
        self.assertAlmostEqual(2.000, channel.current, 3)

    def test_model(self):
        """ Test the IDN command.

        Read the model number from the device.
        """
        model = self.device.model
        self.assertTrue(model.startswith("KORAD"))

    def test_ocp(self):
        """ Test Over Current Protection

        There's no way to get feedback on these, so simply ensure that no exceptions are thrown.
        """
        self.device.over_current_protection.on()
        self._pause()
        self.device.over_current_protection.off()

    def test_ovp(self):
        """ Test Over Voltage Protection

        There's no way to get feedback on these, so simply ensure that no exceptions are thrown.
        """
        self.device.over_voltage_protection.on()
        self._pause()
        self.device.over_voltage_protection.off()

    def test_output(self):
        """ Ensure the device is reporting the output on/off state correctly.
        """
        self.device.output.on()
        status = self.device.status
        self.assertEqual(OnOffState.on, status.output)

        self._pause()

        self.device.output.off()
        status = self.device.status
        self.assertEqual(OnOffState.off, status.output)

    def test_track(self):
        """ Test the TRACK commands.

        **NOTE:** The tests here are hypothetical.
        I don't have a multi-channel power supply to actually test this against.
        """
        if not self.overrideSkippedTests:
            return

        self.device.track(Tracking.parallel)
        status = self.device.status
        self.assertEqual(Tracking.parallel, status.tracking)

        self._pause()

        self.device.track(Tracking.series)
        status = self.device.status
        self.assertEqual(Tracking.series, status.tracking)

        self._pause()

        self.device.track(Tracking.independent)
        status = self.device.status
        self.assertEqual(Tracking.independent, status.tracking)
示例#10
0
import serial
from time import sleep
from koradserial import KoradSerial
from koradserial import OnOffState
from koradserial import Tracking

mydevice = KoradSerial("COM3", False)
channel = mydevice.channels[0]

channel.voltage = 12

dev_status = mydevice.status
print(dev_status)
mydevice.output.on()
dev_status = mydevice.status
print(dev_status)
load = {}

# for i in range(50, 150, 5):
#     channel.voltage = i/10
#     sleep(0.01)
#     #load.append(channel.output_current)
#     load["{} volt".format(i/10)] = "{} Amp".format(channel.output_current)
#
# for i in range(150, 45, -5):
#     channel.voltage = i / 10
#     sleep(0.01)
#     #load.append(channel.output_current)
#     load["{} volt".format(i)] = "{} Amp".format(channel.output_current)

#mydevice.output.off()
示例#11
0
def enablePowerSupply(device, powerOn=True):
    with KoradSerial(device) as ps:
        ps.output.on() if powerOn == True else ps.output.off()
    with KoradSerial('/dev/ttyACM0') as ps:
        print("V: {}V".format(ps.channels[0].output_voltage))
        print("I: {}A".format(ps.channels[0].output_current))
示例#12
0
 def setUp(self):
     self.ps = KoradSerial(serial_port)
     self.ps.output = OnOffState('off')
示例#13
0
class KoradSerialTest(TestCase):
    def setUp(self):
        self.ps = KoradSerial(serial_port)
        self.ps.output = OnOffState('off')

    def tearDown(self):
        self.ps.close()

    def test_modelstring(self):
        model = self.ps.model
        self.assertTrue(
            model.startswith('KORAD') or model.startswith('VELLEMAN'))

    def test_statusclass(self):
        status = self.ps.status

        self.assertIsInstance(status.mode, OutputMode)
        self.assertIsInstance(status.beep, OnOffState)
        self.assertIsInstance(status.ocp, OnOffState)
        self.assertIsInstance(status.ovp, OnOffState)
        self.assertIsInstance(status.output, OnOffState)

    def test_ocp(self):
        self.ps.ocp = OnOffState('on')
        self.assertEqual(self.ps.ocp.name, 'on')
        self.ps.ocp = 'off'
        self.assertEqual(self.ps.ocp.name, 'off')

    def test_ovp(self):
        self.ps.ovp = OnOffState('on')
        self.assertEqual(self.ps.ovp.name, 'on')
        self.ps.ovp = 'off'
        self.assertEqual(self.ps.ovp.name, 'off')

    def test_output(self):
        self.ps.output = OnOffState('off')
        self.assertEqual(self.ps.output.name, 'off')
        self.ps.output = 'on'
        self.assertEqual(self.ps.output.name, 'on')

    def test_voltage(self):
        self.ps.output = OnOffState('off')
        voltage = self.ps.voltage_set
        self.ps.voltage = 1

        self.assertEqual(self.ps.voltage_actual, 0)
        self.assertEqual(self.ps.voltage_set, 1)

        self.ps.voltage = voltage

    def test_current(self):
        self.ps.output = OnOffState('off')
        current = self.ps.current_set
        self.ps.current = 1

        self.assertEqual(self.ps.current_actual, 0)
        self.assertEqual(self.ps.current_set, 1)

        self.ps.current = current

    def test_memory(self):
        # remember saved values
        self.ps.recall_from_memory(1)
        c1, v1 = self.ps.current_set, self.ps.voltage_set
        self.ps.recall_from_memory(2)
        c2, v2 = self.ps.current_set, self.ps.voltage_set

        self.ps.current = 2.0
        self.ps.voltage = 5.0
        self.ps.save_to_memory(1)

        self.ps.current = 0.5
        self.ps.voltage = 3.3
        self.ps.save_to_memory(2)

        self.ps.recall_from_memory(1)
        self.assertEqual(self.ps.current_set, 2.0)
        self.assertEqual(self.ps.voltage_set, 5.0)

        self.ps.recall_from_memory(2)
        self.assertEqual(self.ps.current_set, 0.5)
        self.assertEqual(self.ps.voltage_set, 3.3)

        self.ps.current = 1.5
        self.ps.voltage = 8.0
        self.ps.save_to_memory(1)

        self.ps.current = 0.2
        self.ps.voltage = 15.0
        self.ps.save_to_memory(2)

        self.ps.recall_from_memory(1)
        self.assertEqual(self.ps.current_set, 1.5)
        self.assertEqual(self.ps.voltage_set, 8.0)

        self.ps.recall_from_memory(2)
        self.assertEqual(self.ps.current_set, 0.2)
        self.assertEqual(self.ps.voltage_set, 15.0)

        # set backed up values
        self.ps.current, self.ps.voltage = c2, v2
        self.ps.save_to_memory(2)
        self.ps.current, self.ps.voltage = c1, v1
        self.ps.save_to_memory(1)
示例#14
0
import serial
from time import sleep
from koradserial import KoradSerial
from koradserial import OnOffState
from koradserial import Tracking

mydevice = KoradSerial("COM3", 1)
channel = mydevice.channels[0]
channel.voltage = 5
channel.current = 2
mydevice.output.off()
#power_state = mydevice.status
print(OnOffState.on.value)

load = channel.output_current
print(load)

# #wait = input("press to continue" )
# wait = 'r'
# while wait == 'r':
#     wait = input("press to continue: ")
#     load = channel.output_current
#     print(load)

wait = input("press to continue: ")
mydevice.output.off()
mydevice.close()

# ser = serial.Serial('COM3')
# print(ser.name)
# #ser.write(b'VSET1:6.34')
示例#15
0
 def setUp(self):
     self.device = KoradSerial('/dev/tty.usbmodemfd121', True)
     self.overrideSkippedTests = False
示例#16
0
from unittest import TestCase, main
# from click.testing import CliRunner
import Tkinter
from Tkinter import *
import tkMessageBox
import datetime
import time

from koradserial import KoradSerial, OnOffState, OutputMode
# from koradcli import korad

# Definition of serial ports for 2 power supplies
ps1serialPort = 'COM4'  # COMM PORT 1
ps2serialPort = 'COM5'  # COMM PORT 2

ps1 = KoradSerial(ps1serialPort)  # handle def
ps2 = KoradSerial(ps2serialPort)  # handle def

# Setting the electrical parameters and power source configuration
ps1.current = 5.0  #set current
ps1.voltage = 1.4  #set voltage
ps1.ovp = 'off'
ps1.ocp = 'on'
ps1.cv = 'on'

ps2.current = 5.0  #set current
ps2.voltage = 1.4  #set voltage
ps2.ovp = 'off'
ps2.ocp = 'off'
ps2.cv = 'on'
示例#17
0
from koradserial import KoradSerial
import time
import sys
if len(sys.argv) != 3:
    print("Usage: app.py serial_port output file")
    sys.exit(-1)
with KoradSerial(sys.argv[1]) as power_supply:
    with open(sys.argv[2], 'w') as f:
        f.write("time,voltage,current\n")
        while True:
            f.write("{0},{1},{2}\n".format(
                time.time(), power_supply.channels[0].output_voltage,
                power_supply.channels[0].output_current))
            time.sleep(1)
示例#18
0
def printPowerSupplyInfo(device):
    with KoradSerial(device) as ps:
        print("Model: {}".format(ps.model))
        print("Status: {}".format(ps.status))