Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Jun 29, 2021
1 parent 7ece4c2 commit ca92fa1
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 75 deletions.
9 changes: 8 additions & 1 deletion src/eez/function_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,9 @@ void initWaveformParameters(WaveformParameters &waveformParameters) {

waveformParameters.resourceType = g_slots[slotIndex]->getFunctionGeneratorResourceType(subchannelIndex, resourceIndex);
if (waveformParameters.resourceType == FUNCTION_GENERATOR_RESOURCE_TYPE_U_AND_I) {
waveformParameters.resourceType = FUNCTION_GENERATOR_RESOURCE_TYPE_U;
SourceMode mode;
channel_dispatcher::getSourceMode(slotIndex, subchannelIndex, mode, nullptr);
waveformParameters.resourceType = mode == SOURCE_MODE_CURRENT ? FUNCTION_GENERATOR_RESOURCE_TYPE_I : FUNCTION_GENERATOR_RESOURCE_TYPE_U;
}

float minFreq;
Expand Down Expand Up @@ -1514,6 +1516,8 @@ bool setResourceType(int slotIndex, int subchannelIndex, int resourceIndex, Func
}

waveformParameters->resourceType = resourceType;
channel_dispatcher::setSourceMode(slotIndex, subchannelIndex,
resourceType == FUNCTION_GENERATOR_RESOURCE_TYPE_I ? SOURCE_MODE_CURRENT : SOURCE_MODE_VOLTAGE, nullptr);

g_functionGeneratorPage.init();

Expand Down Expand Up @@ -2638,6 +2642,9 @@ void action_function_generator_mode_select_mode() {
int resourceIndex;
AllResources::findResource(waveformParameters.absoluteResourceIndex, slotIndex, subchannelIndex, resourceIndex);

channel_dispatcher::setSourceMode(slotIndex, subchannelIndex,
waveformParameters.resourceType == FUNCTION_GENERATOR_RESOURCE_TYPE_I ? SOURCE_MODE_CURRENT : SOURCE_MODE_VOLTAGE, nullptr);

float minFreq;
float maxFreq;
g_slots[slotIndex]->getFunctionGeneratorFrequencyInfo(subchannelIndex, resourceIndex, minFreq, maxFreq);
Expand Down
4 changes: 4 additions & 0 deletions src/eez/modules/psu/channel_dispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1916,6 +1916,10 @@ void setCurrentTriggerMode(Channel &channel, TriggerMode mode) {
}
}

bool getTriggerMode(int slotIndex, int subchannelIndex, int resourceIndex, TriggerMode &mode, int *err) {
return g_slots[slotIndex]->getFunctionGeneratorResourceTriggerMode(subchannelIndex, resourceIndex, mode, err);
}

bool setTriggerMode(int slotIndex, int subchannelIndex, int resourceIndex, TriggerMode mode, int *err) {
return g_slots[slotIndex]->setFunctionGeneratorResourceTriggerMode(subchannelIndex, resourceIndex, mode, err);
}
Expand Down
1 change: 1 addition & 0 deletions src/eez/modules/psu/channel_dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ void setVoltageTriggerMode(Channel &channel, TriggerMode mode);
TriggerMode getCurrentTriggerMode(Channel &channel);
void setCurrentTriggerMode(Channel &channel, TriggerMode mode);

bool getTriggerMode(int slotIndex, int subchannelIndex, int resourceIndex, TriggerMode &mode, int *err);
bool setTriggerMode(int slotIndex, int subchannelIndex, int resourceIndex, TriggerMode mode, int *err);

bool getTriggerOutputState(Channel &channel);
Expand Down
134 changes: 60 additions & 74 deletions src/eez/modules/psu/scpi/sour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,14 @@ scpi_result_t scpi_cmd_sourceFunctionOn(scpi_t *context) {
return SCPI_RES_ERR;
}

TriggerMode triggerMode;
if (channel_dispatcher::getTriggerMode(slotAndSubchannelIndex.slotIndex, slotAndSubchannelIndex.subchannelIndex, 0, triggerMode, nullptr)) {
if (triggerMode == TRIGGER_MODE_FUNCTION_GENERATOR) {
function_generator::setResourceType(slotAndSubchannelIndex.slotIndex, slotAndSubchannelIndex.subchannelIndex, 0,
mode == SOURCE_MODE_CURRENT ? FUNCTION_GENERATOR_RESOURCE_TYPE_I : FUNCTION_GENERATOR_RESOURCE_TYPE_U, nullptr);
}
}

return SCPI_RES_OK;
}

Expand Down Expand Up @@ -1663,40 +1671,36 @@ scpi_result_t scpi_cmd_sourceVoltageMode(scpi_t *context) {
return SCPI_RES_ERR;
}

int resourceIndex = 0;
int resourceIndex;

Channel *channel = Channel::getBySlotIndex(slotAndSubchannelIndex->slotIndex, slotAndSubchannelIndex->subchannelIndex);
if (!channel) {
if (channel) {
resourceIndex = 0;
} else {
if (triggerMode != TRIGGER_MODE_FIXED && triggerMode != TRIGGER_MODE_FUNCTION_GENERATOR) {
SCPI_ErrorPush(context, SCPI_ERROR_PARAMETER_NOT_ALLOWED);
return SCPI_RES_ERR;
}

auto resourceType = g_slots[slotAndSubchannelIndex->slotIndex]->getFunctionGeneratorResourceType(slotAndSubchannelIndex->subchannelIndex, 0);
if (resourceType == FUNCTION_GENERATOR_RESOURCE_TYPE_U_AND_I) {
if (triggerMode == TRIGGER_MODE_FUNCTION_GENERATOR) {
int err;
if (!setResourceType(slotAndSubchannelIndex->slotIndex, slotAndSubchannelIndex->subchannelIndex, 0, FUNCTION_GENERATOR_RESOURCE_TYPE_U, &err)) {
SCPI_ErrorPush(context, err);
return SCPI_RES_ERR;
}
} else {
FunctionGeneratorResourceType resourceType;
int err;
if (!getResourceType(slotAndSubchannelIndex->slotIndex, slotAndSubchannelIndex->subchannelIndex, 0, resourceType, &err)) {
SCPI_ErrorPush(context, err);
return SCPI_RES_ERR;
}

if (resourceType != FUNCTION_GENERATOR_RESOURCE_TYPE_U) {
SCPI_ErrorPush(context, SCPI_ERROR_EXECUTION_ERROR);
return SCPI_RES_ERR;
}
SourceMode mode;
int err;
if (!channel_dispatcher::getSourceMode(slotAndSubchannelIndex->slotIndex, slotAndSubchannelIndex->subchannelIndex, mode, &err)) {
SCPI_ErrorPush(context, err);
return SCPI_RES_ERR;
}

if (mode != SOURCE_MODE_VOLTAGE) {
SCPI_ErrorPush(context, SCPI_ERROR_EXECUTION_ERROR);
return SCPI_RES_ERR;
}
} else if (resourceType != FUNCTION_GENERATOR_RESOURCE_TYPE_U) {
SCPI_ErrorPush(context, SCPI_ERROR_EXECUTION_ERROR);
return SCPI_RES_ERR;
}

resourceIndex = 0;
}

int err;
Expand All @@ -1719,41 +1723,36 @@ scpi_result_t scpi_cmd_sourceVoltageModeQ(scpi_t *context) {

Channel *channel = Channel::getBySlotIndex(slotAndSubchannelIndex->slotIndex, slotAndSubchannelIndex->subchannelIndex);
if (channel) {
resourceIndex = 1;
resourceIndex = 0;
} else {
auto resourceType = g_slots[slotAndSubchannelIndex->slotIndex]->getFunctionGeneratorResourceType(slotAndSubchannelIndex->subchannelIndex, 0);
if (resourceType == FUNCTION_GENERATOR_RESOURCE_TYPE_U_AND_I) {
SourceMode mode;
int err;
if (!channel_dispatcher::getSourceMode(slotAndSubchannelIndex->slotIndex, slotAndSubchannelIndex->subchannelIndex, mode, &err)) {
SCPI_ErrorPush(context, err);
return SCPI_RES_ERR;
}

if (mode != SOURCE_MODE_VOLTAGE) {
SCPI_ErrorPush(context, SCPI_ERROR_EXECUTION_ERROR);
return SCPI_RES_ERR;
}
} else if (resourceType != FUNCTION_GENERATOR_RESOURCE_TYPE_U) {
SCPI_ErrorPush(context, SCPI_ERROR_EXECUTION_ERROR);
return SCPI_RES_ERR;
}

resourceIndex = 0;
resourceIndex = 0;
}

TriggerMode triggerMode;
int err;
if (!g_slots[slotAndSubchannelIndex->slotIndex]->getFunctionGeneratorResourceTriggerMode(slotAndSubchannelIndex->subchannelIndex, resourceIndex, triggerMode, &err)) {
if (!channel_dispatcher::getTriggerMode(slotAndSubchannelIndex->slotIndex, slotAndSubchannelIndex->subchannelIndex, resourceIndex, triggerMode, &err)) {
SCPI_ErrorPush(context, err);
return SCPI_RES_ERR;
}

if (!channel) {
if (triggerMode == TRIGGER_MODE_FUNCTION_GENERATOR) {
FunctionGeneratorResourceType resourceType;
int err;
if (!getResourceType(slotAndSubchannelIndex->slotIndex, slotAndSubchannelIndex->subchannelIndex, 0, resourceType, &err)) {
SCPI_ErrorPush(context, err);
return SCPI_RES_ERR;
}

if (resourceType != FUNCTION_GENERATOR_RESOURCE_TYPE_U) {
SCPI_ErrorPush(context, SCPI_ERROR_EXECUTION_ERROR);
return SCPI_RES_ERR;
}
}
}

resultChoiceName(context, g_triggerModeChoice, triggerMode);

return SCPI_RES_OK;
Expand Down Expand Up @@ -1789,24 +1788,16 @@ scpi_result_t scpi_cmd_sourceCurrentMode(scpi_t *context) {

auto resourceType = g_slots[slotAndSubchannelIndex->slotIndex]->getFunctionGeneratorResourceType(slotAndSubchannelIndex->subchannelIndex, 0);
if (resourceType == FUNCTION_GENERATOR_RESOURCE_TYPE_U_AND_I) {
if (triggerMode == TRIGGER_MODE_FUNCTION_GENERATOR) {
int err;
if (!setResourceType(slotAndSubchannelIndex->slotIndex, slotAndSubchannelIndex->subchannelIndex, 0, FUNCTION_GENERATOR_RESOURCE_TYPE_I, &err)) {
SCPI_ErrorPush(context, err);
return SCPI_RES_ERR;
}
} else {
FunctionGeneratorResourceType resourceType;
int err;
if (!getResourceType(slotAndSubchannelIndex->slotIndex, slotAndSubchannelIndex->subchannelIndex, 0, resourceType, &err)) {
SCPI_ErrorPush(context, err);
return SCPI_RES_ERR;
}

if (resourceType != FUNCTION_GENERATOR_RESOURCE_TYPE_I) {
SCPI_ErrorPush(context, SCPI_ERROR_EXECUTION_ERROR);
return SCPI_RES_ERR;
}
SourceMode mode;
int err;
if (!channel_dispatcher::getSourceMode(slotAndSubchannelIndex->slotIndex, slotAndSubchannelIndex->subchannelIndex, mode, &err)) {
SCPI_ErrorPush(context, err);
return SCPI_RES_ERR;
}

if (mode != SOURCE_MODE_CURRENT) {
SCPI_ErrorPush(context, SCPI_ERROR_EXECUTION_ERROR);
return SCPI_RES_ERR;
}
} else if (resourceType != FUNCTION_GENERATOR_RESOURCE_TYPE_I) {
SCPI_ErrorPush(context, SCPI_ERROR_EXECUTION_ERROR);
Expand Down Expand Up @@ -1840,12 +1831,23 @@ scpi_result_t scpi_cmd_sourceCurrentModeQ(scpi_t *context) {
} else {
auto resourceType = g_slots[slotAndSubchannelIndex->slotIndex]->getFunctionGeneratorResourceType(slotAndSubchannelIndex->subchannelIndex, 0);
if (resourceType == FUNCTION_GENERATOR_RESOURCE_TYPE_U_AND_I) {
SourceMode mode;
int err;
if (!channel_dispatcher::getSourceMode(slotAndSubchannelIndex->slotIndex, slotAndSubchannelIndex->subchannelIndex, mode, &err)) {
SCPI_ErrorPush(context, err);
return SCPI_RES_ERR;
}

if (mode != SOURCE_MODE_CURRENT) {
SCPI_ErrorPush(context, SCPI_ERROR_EXECUTION_ERROR);
return SCPI_RES_ERR;
}
} else if (resourceType != FUNCTION_GENERATOR_RESOURCE_TYPE_I) {
SCPI_ErrorPush(context, SCPI_ERROR_EXECUTION_ERROR);
return SCPI_RES_ERR;
}

resourceIndex = 0;
resourceIndex = 0;
}

TriggerMode triggerMode;
Expand All @@ -1855,22 +1857,6 @@ scpi_result_t scpi_cmd_sourceCurrentModeQ(scpi_t *context) {
return SCPI_RES_ERR;
}

if (!channel) {
if (triggerMode == TRIGGER_MODE_FUNCTION_GENERATOR) {
FunctionGeneratorResourceType resourceType;
int err;
if (!getResourceType(slotAndSubchannelIndex->slotIndex, slotAndSubchannelIndex->subchannelIndex, 0, resourceType, &err)) {
SCPI_ErrorPush(context, err);
return SCPI_RES_ERR;
}

if (resourceType != FUNCTION_GENERATOR_RESOURCE_TYPE_I) {
SCPI_ErrorPush(context, SCPI_ERROR_EXECUTION_ERROR);
return SCPI_RES_ERR;
}
}
}

resultChoiceName(context, g_triggerModeChoice, triggerMode);

return SCPI_RES_OK;
Expand Down

0 comments on commit ca92fa1

Please sign in to comment.