Example #1
0
/**
 * Convert scpi_number_t to string
 * @param context
 * @param value number value
 * @param str target string
 * @param len max length of string
 * @return number of chars written to string
 */
size_t SCPI_NumberToStr(scpi_t * context, const scpi_choice_def_t * special, scpi_number_t * value, char * str, size_t len) {
    const char * type;
    const char * unit;
    size_t result;

    if (!value || !str) {
        return 0;
    }

    if (value->special) {
        if (SCPI_ChoiceToName(special, value->tag, &type)) {
            strncpy(str, type, len);
            return min(strlen(type), len);
        } else {
            str[0] = 0;
            return 0;
        }
    }

    result = SCPI_DoubleToStr(value->value, str, len);

    unit = translateUnitInverse(context->units, value->unit);

    if (unit) {
        strncat(str, " ", len);
        strncat(str, unit, len);
        result += strlen(unit) + 1;
    }

    return result;
}
Example #2
0
static scpi_result_t TEST_ChoiceQ(scpi_t * context) {

    int32_t param;
    const char * name;
    
    if (!SCPI_ParamChoice(context, trigger_source, &param, TRUE)) {
        return SCPI_RES_ERR;
    }
    
    SCPI_ChoiceToName(trigger_source, param, &name);
    printf( "\tP1=%s (%ld)\r\n", name, (long int)param);
    
    SCPI_ResultInt(context, param);

    return SCPI_RES_OK;
}