def test_toggle_eload_false(self, mock_pyvisa): # given state = False py_instrument = mock_pyvisa.ResourceManager.return_value.open_resource.return_value instrument = Bk8600() py_instrument.reset_mock() # when instrument.toggle_eload(state) # then py_instrument.write.assert_has_calls([call(Bk8600.INPUT_OFF_CMD)])
def test_constructor(self, mock_pyvisa): # given resource_id = "USB0::65535" resource_manager = mock_pyvisa.ResourceManager.return_value instrument = resource_manager.open_resource.return_value # when Bk8600(resource_id) # then instrument.write.assert_called_with(Bk8600.RESET_COMMAND) instrument.query.assert_called_with(Bk8600.SELF_ID_QUERY) resource_manager.open_resource.assert_called_with(resource_id)
def test_measure_current(self, mock_pyvisa): # given current = 30 py_instrument = mock_pyvisa.ResourceManager.return_value.open_resource.return_value instrument = Bk8600() py_instrument.reset_mock() py_instrument.query.return_value = current # when c = instrument.measure_current() # then py_instrument.query.assert_called_with(Bk8600.DC_CURRENT_QUERY) assert c == current
def test_measure_voltage(self, mock_pyvisa): # given voltage = 30 py_instrument = mock_pyvisa.ResourceManager.return_value.open_resource.return_value instrument = Bk8600() py_instrument.reset_mock() py_instrument.query.return_value = voltage # when v = instrument.measure_voltage() # then py_instrument.query.assert_called_with(Bk8600.DC_VOLTAGE_QUERY) assert v == voltage
def test_set_current(self, mock_pyvisa): # given py_instrument = mock_pyvisa.ResourceManager.return_value.open_resource.return_value current_a = 1 instrument = Bk8600() py_instrument.reset_mock() # when instrument.set_current_level(current_a) # then py_instrument.write.assert_has_calls([ call("{} {}".format(Bk8600.CURRENT_LEVEL_COMMAND, current_a)), call(Bk8600.INPUT_ON_CMD) ]) py_instrument.query.assert_called_with("*OPC?")
import pyvisa import time from src.equipments.bk8600 import Bk8600 TIME = 2 #initialize instrument inst = Bk8600() # To Set E-Load in Amps Current = input("Enter E-Load Current") inst.set_current(Current) Operation = "OFF" #initialize instrument while (Operation == "OFF"): Operation = input("Enter ON to turn on Output") if Operation == "ON": inst._set_input_on() print("Input On") time.sleep(10) while Operation != "End": Operation = input("Enter:\n" + "M to meausre voltage and current\n" + "OFF to turn output off\n" + "End to close testing") if Operation == "M": try: while True: print("current is: %d", inst.measure_current()) print("voltage is: %d", inst.measure_voltage()) time.sleep(2) except KeyboardInterrupt: