/** * 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; }
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); }