File was renamed from test-parser.c |
| | |
| | | */ |
| | | |
| | | /** |
| | | * @file main.c |
| | | * @file scpi-def.c |
| | | * @date Thu Nov 15 10:58:45 UTC 2012 |
| | | * |
| | | * @brief SCPI parser test |
| | |
| | | #include <stdlib.h> |
| | | #include <string.h> |
| | | #include "scpi/scpi.h" |
| | | #include "scpi-def.h" |
| | | |
| | | scpi_result_t DMM_MeasureVoltageDcQ(scpi_t * context) { |
| | | scpi_number_t param1, param2; |
| | |
| | | SCPI_CMD_LIST_END |
| | | }; |
| | | |
| | | static size_t SCPI_Write(scpi_t * context, const char * data, size_t len) { |
| | | (void) context; |
| | | return fwrite(data, 1, len, stdout); |
| | | } |
| | | |
| | | static int SCPI_Error(scpi_t * context, int_fast16_t err) { |
| | | (void) context; |
| | | |
| | | fprintf(stderr, "**ERROR: %d, \"%s\"\r\n", (int32_t) err, SCPI_ErrorTranslate(err)); |
| | | return 0; |
| | | } |
| | | |
| | | static scpi_result_t SCPI_Srq(scpi_t * context) { |
| | | scpi_reg_val_t stb = SCPI_RegGet(context, SCPI_REG_STB); |
| | | fprintf(stderr, "**SRQ: 0x%X (%d)\r\n", stb, stb); |
| | | return SCPI_RES_OK; |
| | | } |
| | | |
| | | |
| | | static scpi_interface_t scpi_interface = { |
| | | .write = SCPI_Write, |
| | | .error = SCPI_Error, |
| | | .reset = NULL, |
| | | .test = NULL, |
| | | .reset = SCPI_Reset, |
| | | .test = SCPI_Test, |
| | | .srq = SCPI_Srq, |
| | | }; |
| | | |
| | |
| | | .units = scpi_units_def, |
| | | .special_numbers = scpi_special_numbers_def, |
| | | }; |
| | | |
| | | /* |
| | | * |
| | | */ |
| | | int main(int argc, char** argv) { |
| | | (void) argc; |
| | | (void) argv; |
| | | int result; |
| | | |
| | | SCPI_Init(&scpi_context); |
| | | |
| | | #define TEST_SCPI_INPUT(cmd) result = SCPI_Input(&scpi_context, cmd, strlen(cmd)) |
| | | |
| | | TEST_SCPI_INPUT("*CLS\r\n"); |
| | | TEST_SCPI_INPUT("*RST\r\n"); |
| | | TEST_SCPI_INPUT("MEAS:volt:DC? 12,50;*OPC\r\n"); |
| | | TEST_SCPI_INPUT("*IDN?\r\n"); |
| | | TEST_SCPI_INPUT("SYST:VERS?"); |
| | | TEST_SCPI_INPUT("\r\n*ID"); |
| | | TEST_SCPI_INPUT("N?"); |
| | | TEST_SCPI_INPUT(""); // emulate command timeout |
| | | |
| | | TEST_SCPI_INPUT("*ESE\r\n"); // cause error -109, missing parameter |
| | | TEST_SCPI_INPUT("*ESE 0x20\r\n"); |
| | | |
| | | TEST_SCPI_INPUT("*SRE 0xFF\r\n"); |
| | | |
| | | TEST_SCPI_INPUT("IDN?\r\n"); // cause error -113, undefined header |
| | | |
| | | TEST_SCPI_INPUT("SYST:ERR?\r\n"); |
| | | TEST_SCPI_INPUT("SYST:ERR?\r\n"); |
| | | TEST_SCPI_INPUT("*STB?\r\n"); |
| | | TEST_SCPI_INPUT("*ESR?\r\n"); |
| | | TEST_SCPI_INPUT("*STB?\r\n"); |
| | | |
| | | TEST_SCPI_INPUT("meas:volt:dc? 0.01 V, Default\r\n"); |
| | | TEST_SCPI_INPUT("meas:volt:dc?\r\n"); |
| | | TEST_SCPI_INPUT("meas:volt:dc? def, 0.00001\r\n"); |
| | | TEST_SCPI_INPUT("meas:volt:dc? 0.00001\r\n"); |
| | | |
| | | |
| | | //printf("%.*s %s\r\n", 3, "asdadasdasdasdas", "b"); |
| | | // interactive demo |
| | | //char smbuffer[10]; |
| | | //while (1) { |
| | | // fgets(smbuffer, 10, stdin); |
| | | // SCPI_Input(&scpi_context, smbuffer, strlen(smbuffer)); |
| | | //} |
| | | |
| | | |
| | | return (EXIT_SUCCESS); |
| | | } |
| | | |