int wiringSetup() { int rc = rp_Init(); if (rc == RP_OK) return 0; printf("%s\n", rp_GetError(rc)); }
/** * Returns Analog Pin value in volts to SCPI context * @param context SCPI context * @return success or failure */ scpi_result_t RP_AnalogPinValueQ(scpi_t * context) { int32_t choice; /* Read first parameter - APIN */ if (!SCPI_ParamChoice(context, scpi_RpApin, &choice, true)) { RP_LOG(LOG_ERR, "*ANALOG:PIN? is missing first parameter.\n"); return SCPI_RES_ERR; } // Convert port into pin id rp_apin_t pin = choice; // Now get the pin value float value; int result = rp_ApinGetValue(pin, &value); if (RP_OK != result){ RP_LOG(LOG_ERR, "*ANALOG:PIN? Failed to get pin value: %s\n", rp_GetError(result)); return SCPI_RES_ERR; } // Return back result SCPI_ResultDouble(context, value); RP_LOG(LOG_INFO, "*ANALOG:PIN? Successfully returned port value.\n"); return SCPI_RES_OK; }
/** * Sets Analog Pin value in volts * @param context SCPI context * @return success or failure */ scpi_result_t RP_AnalogPinValue(scpi_t * context) { int32_t choice; double value; /* Read first parameter - APIN */ if (!SCPI_ParamChoice(context, scpi_RpApin, &choice, true)) { RP_LOG(LOG_ERR, "*ANALOG:PIN is missing first parameter.\n"); return SCPI_RES_ERR; } /* Read second parameter - VALUE */ if (!SCPI_ParamDouble(context, &value, true)) { RP_LOG(LOG_ERR, "*ANALOG:PIN is missing second parameter.\n"); return SCPI_RES_ERR; } // Convert port into pin id rp_apin_t pin = choice; /* Set pin value */ int result = rp_ApinSetValue(pin, (float) value); if (RP_OK != result){ RP_LOG(LOG_ERR, "*ANALOG:PIN Failed to set pin value: %s\n", rp_GetError(result)); return SCPI_RES_ERR; } RP_LOG(LOG_INFO, "*ANALOG:PIN Successfully set port value.\n"); return SCPI_RES_OK; }
scpi_result_t RP_APP_SpecReset(scpi_t *context) { int result = rpApp_SpecReset(); if (RP_OK != result) { syslog(LOG_ERR, "*SPEC:RESET Failed: %s.", rp_GetError(result)); return SCPI_RES_ERR; } syslog(LOG_INFO, "*SPEC:RESET Successfully."); return SCPI_RES_OK; }
scpi_result_t RP_APP_OscSingle(scpi_t *context) { int result = rpApp_OscSingle(); if (RP_OK != result) { syslog(LOG_ERR, "*OSC:SINGLE Failed: %s.", rp_GetError(result)); return SCPI_RES_ERR; } syslog(LOG_INFO, "*OSC:SINGLE Successfully."); return SCPI_RES_OK; }
scpi_result_t RP_APP_SpecRun(scpi_t *context) { syslog(LOG_INFO, "*SPEC:RUN start."); int result = rpApp_SpecRun(NULL); if (RP_OK != result) { syslog(LOG_ERR, "*SPEC:RUN Failed: %s.", rp_GetError(result)); return SCPI_RES_ERR; } syslog(LOG_INFO, "*SPEC:RUN Successfully."); return SCPI_RES_OK; }
scpi_result_t RP_APP_OscRunDigLoop(scpi_t *context){ int result = rp_EnableDigitalLoop(true); if(result != RP_OK){ syslog(LOG_ERR, "*OSC:RUN:DIGLOOP Failed to enable digital loop: %s", rp_GetError(result)); return SCPI_RES_ERR; } syslog(LOG_INFO, "*OSC:RUN:DIGLOOP Successfully enabled Red Pitaya digital loop."); return SCPI_RES_OK; }
scpi_result_t RP_APP_OscRunning(scpi_t *context) { bool running; int result = rpApp_OscIsRunning(&running); if (RP_OK != result) { syslog(LOG_ERR, "*OSC:RUNNING Failed: %s.", rp_GetError(result)); return SCPI_RES_ERR; } SCPI_ResultBool(context, running); syslog(LOG_INFO, "*OSC:RUNNING Successfully."); return SCPI_RES_OK; }
void analogWriteVoltage (int pin, float value) { if(pin<AOUT) { int rc = rp_ApinSetValue(aout[pin], value); if(rc != RP_OK) printf("%s\n", rp_GetError(rc)); } else printf("Pin %d is not analog output\n",pin); }
scpi_result_t RP_APP_OscMeasureRMS(rpApp_osc_source source, scpi_t *context) { float value; int result = rpApp_OscMeasureRootMeanSquare(source, &value); if (RP_OK != result) { syslog(LOG_ERR, "*OSC:MEAS:CH<n>:RMS? Failed to get: %s", rp_GetError(result)); return SCPI_RES_ERR; } SCPI_ResultDouble(context, value); syslog(LOG_INFO, "*OSC:MEAS:CH<n>:RMS? get successfully."); return SCPI_RES_OK; }
void pinMode(int pin, int mode) { if(pin<GPIO) { int rc = rp_DpinSetDirection(gpio[pin], mode); if(rc != RP_OK) printf("%s\n", rp_GetError(rc)); } else printf("Cannot set pin mode for pin %d\n", pin); }
scpi_result_t RP_APP_OscGetViewSize(scpi_t *context) { uint32_t viewSize; int result = rpApp_OscGetViewSize(&viewSize); if (RP_OK != result) { syslog(LOG_ERR, "*OSC:DATA:SIZE? Failed to get: %s", rp_GetError(result)); return SCPI_RES_ERR; } SCPI_ResultUInt(context, viewSize); syslog(LOG_INFO, "*OSC:DATA:SIZE? get successfully."); return SCPI_RES_OK; }
scpi_result_t RP_APP_OscGetTriggerLevel(scpi_t *context) { float value; int result = rpApp_OscGetTriggerLevel(&value); if (RP_OK != result) { syslog(LOG_ERR, "*OSC:TRIG:LEVEL? Failed to get: %s", rp_GetError(result)); return SCPI_RES_ERR; } SCPI_ResultDouble(context, value); syslog(LOG_INFO, "*OSC:TRIG:LEVEL? get successfully."); return SCPI_RES_OK; }
scpi_result_t RP_APP_OscGetTimeScale(scpi_t *context) { float value; int result = rpApp_OscGetTimeScale(&value); if (RP_OK != result) { syslog(LOG_ERR, "*OSC:TIME:SCALE? Failed to get: %s", rp_GetError(result)); return SCPI_RES_ERR; } SCPI_ResultDouble(context, value); syslog(LOG_INFO, "*OSC:TIME:SCALE? get successfully."); return SCPI_RES_OK; }
scpi_result_t RP_AnalogPinReset(scpi_t *context) { int result = rp_ApinReset(); if (RP_OK != result) { RP_LOG(LOG_ERR, "ANALOG:RST Failed to reset Red " "Pitaya analog resources: %s\n" , rp_GetError(result)); return SCPI_RES_ERR; } RP_LOG(LOG_INFO, "*ANALOG:RST Successfully reset analog pin resources.\n"); return SCPI_RES_OK; }
scpi_result_t RP_APP_OscGetViewPart(scpi_t *context) { float pos; int result = rpApp_OscGetViewPart(&pos); if (RP_OK != result) { syslog(LOG_ERR, "*OSC:VIEW:PART? Failed to get: %s", rp_GetError(result)); return SCPI_RES_ERR; } SCPI_ResultDouble(context, pos); syslog(LOG_INFO, "*OSC:VIEW:PART? get successfully."); return SCPI_RES_OK; }
scpi_result_t RP_APP_SpecGetFpgaFreq(scpi_t *context) { float freq; int result = rpApp_SpecGetFpgaFreq(&freq); if (RP_OK != result) { syslog(LOG_ERR, "*SPEC:FPGA:FREQ? Failed to get: %s", rp_GetError(result)); return SCPI_RES_ERR; } SCPI_ResultDouble(context, freq); syslog(LOG_INFO, "*SPEC:FREQ:FREQ? get successfully."); return SCPI_RES_OK; }
scpi_result_t RP_APP_SpecChannel2GetPeak(scpi_t *context) { float power; int result = rpApp_SpecGetPeakPower(1, &power); if (RP_OK != result) { syslog(LOG_ERR, "*SPEC:CH2:PEAK? Failed to get: %s", rp_GetError(result)); return SCPI_RES_ERR; } SCPI_ResultDouble(context, power); syslog(LOG_INFO, "*SPEC:CH2:PEAK? get successfully."); return SCPI_RES_OK; }
void digitalWrite (int pin, int value) { if(pin<GPIO) { pinMode (pin, OUTPUT); int rc = rp_DpinSetState(gpio[pin], value); if(rc != RP_OK) printf("%s\n", rp_GetError(rc)); } else printf("Pin %d is not a GPIO pin\n", pin); }
void analogWrite (int pin, int value) { int scaled_value = value*RP_AWRITE_MAX_VALUE/AWRITE_MAX_VALUE; if(pin<AOUT) { int rc = rp_ApinSetValueRaw(aout[pin], scaled_value); if(rc != RP_OK) printf("%s\n", rp_GetError(rc)); } else printf("Pin %d is not analog output\n",pin); }
scpi_result_t RP_APP_OscGetProbeAtt(rp_channel_t channel, scpi_t *context) { float value; int result = rpApp_OscGetProbeAtt(channel, &value); if (RP_OK != result) { syslog(LOG_ERR, "*OSC:CH<n>:PROBE? Failed to get: %s", rp_GetError(result)); return SCPI_RES_ERR; } SCPI_ResultDouble(context, value); syslog(LOG_INFO, "*OSC:CH<n>:PROBE? get successfully."); return SCPI_RES_OK; }
scpi_result_t RP_APP_OscGetAmplitudeScale(rpApp_osc_source source, scpi_t *context) { double value; int result = rpApp_OscGetAmplitudeScale(source, &value); if (RP_OK != result) { syslog(LOG_ERR, "*OSC:CH<n>:SCALE? Failed to get: %s", rp_GetError(result)); return SCPI_RES_ERR; } SCPI_ResultDouble(context, value); syslog(LOG_INFO, "*OSC:CH<n>:SCALE? get successfully."); return SCPI_RES_OK; }
scpi_result_t RP_ReleaseAll(scpi_t *context){ int result = rp_Release(); if(result != RP_OK){ RP_LOG(LOG_ERR, "*RP:RELEASE Failed to release Red " "Pitaya modules: %s\n", rp_GetError(result)); return SCPI_RES_ERR; } RP_LOG(LOG_INFO, "*RP:RELEASE Successfully released Red Pitaya modules.\n"); return SCPI_RES_OK; }
scpi_result_t RP_InitAll(scpi_t *context){ int result = rp_Init(); if(result != RP_OK){ RP_LOG(LOG_ERR, "*RP:INIT Failed to initialize Red " "Pitaya modules: %s\n", rp_GetError(result)); return SCPI_RES_ERR; } RP_LOG(LOG_INFO, "*RP:INIT Successfully inizitalized Red Pitaya modules.\n"); return SCPI_RES_OK; }
int analogReadRaw (int pin) { if(pin<AIN) { int value; int rc = rp_ApinGetValueRaw(ain[pin], &value); if(rc == RP_OK) return value; printf("%s\n", rp_GetError(rc)); } else printf("Pin %d is not analog input\n",pin); return -1; }
scpi_result_t RP_EnableDigLoop(scpi_t *context){ int result = rp_EnableDigitalLoop(true); if(result != RP_OK){ RP_LOG(LOG_ERR, "*RP:DIG:LOop Failed to initialize Red Pitaya" " digital loop: %s\n", rp_GetError(result)); return SCPI_RES_ERR; } RP_LOG(LOG_INFO, "*RP:DIG:LOop Successfully initialize Red Pitaya" " digital loop.\n"); return SCPI_RES_OK; }
scpi_result_t RP_APP_OscGetViewData(rpApp_osc_source source, scpi_t *context) { uint32_t viewSize; rpApp_OscGetViewSize(&viewSize); float data[viewSize]; int result = rpApp_OscGetViewData(source, data, viewSize); if (RP_OK != result) { syslog(LOG_ERR, "*OSC:CH<n>:DATA? Failed to get: %s", rp_GetError(result)); return SCPI_RES_ERR; } SCPI_ResultBufferFloat(context, data, viewSize); syslog(LOG_INFO, "*OSC:CH<n>:DATA? get successfully."); return SCPI_RES_OK; }
scpi_result_t RP_APP_OscSetProbeAtt(rp_channel_t channel, scpi_t *context) { double value; if (!SCPI_ParamDouble(context, &value, true)) { syslog(LOG_ERR, "*OSC:CH<n>:PROBE is missing first parameter."); return SCPI_RES_ERR; } int result = rpApp_OscSetProbeAtt(channel, (float) value); if (RP_OK != result) { syslog(LOG_ERR, "*OSC:CH<n>:PROBE Failed: %s", rp_GetError(result)); return SCPI_RES_ERR; } syslog(LOG_INFO, "*OSC:CH<n>:PROBE set successfully."); return SCPI_RES_OK; }
scpi_result_t RP_APP_OscSetAmplitudeScale(rpApp_osc_source source, scpi_t *context) { double value; if (!SCPI_ParamDouble(context, &value, true)) { syslog(LOG_ERR, "*OSC:CH<n>:SCALE is missing first parameter."); return SCPI_RES_ERR; } int result = rpApp_OscSetAmplitudeScale(source, (float) value); if (RP_OK != result) { syslog(LOG_ERR, "*OSC:CH<n>:SCALE Failed to set amplitude scale: %s", rp_GetError(result)); return SCPI_RES_ERR; } syslog(LOG_INFO, "*OSC:CH<n>:SCALE set successfully."); return SCPI_RES_OK; }
scpi_result_t RP_APP_OscSetViewSize(scpi_t *context) { uint32_t value; if (!SCPI_ParamUInt(context, &value, true)) { syslog(LOG_ERR, "*OSC:DATA:SIZE is missing first parameter."); return SCPI_RES_ERR; } int result = rpApp_OscSetViewSize(value); if (RP_OK != result) { syslog(LOG_ERR, "*OSC:DATA:SIZE Failed to set: %s", rp_GetError(result)); return SCPI_RES_ERR; } syslog(LOG_INFO, "*OSC:DATA:SIZE set successfully."); return SCPI_RES_OK; }