From be752f9c9139f8d70d0296c6a9f49003071c8c3c Mon Sep 17 00:00:00 2001 From: Jan Breuer <jan.breuer@jaybee.cz> Date: 周一, 24 12月 2012 23:29:54 +0800 Subject: [PATCH] Reorganize library --- examples/common/scpi-def.c | 79 ++------------------------------------- 1 files changed, 4 insertions(+), 75 deletions(-) diff --git a/test-parser.c b/examples/common/scpi-def.c similarity index 72% rename from test-parser.c rename to examples/common/scpi-def.c index 6cc8b6c..0b9bfbd 100644 --- a/test-parser.c +++ b/examples/common/scpi-def.c @@ -26,7 +26,7 @@ */ /** - * @file main.c + * @file scpi-def.c * @date Thu Nov 15 10:58:45 UTC 2012 * * @brief SCPI parser test @@ -38,6 +38,7 @@ #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; @@ -111,30 +112,11 @@ 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, }; @@ -155,56 +137,3 @@ .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); -} - -- Gitblit v1.9.1