From f0f8202f77a42f470f767692b22f0ad0254c038f Mon Sep 17 00:00:00 2001 From: Jan Breuer <jan.breuer@jaybee.cz> Date: 周二, 04 12月 2012 19:01:50 +0800 Subject: [PATCH] Update README - describe parameters and results handling --- test-parser.c | 59 ++++++++++++++++++++++++++++++++++++----------------------- 1 files changed, 36 insertions(+), 23 deletions(-) diff --git a/test-parser.c b/test-parser.c index 2bc38dc..6cc8b6c 100644 --- a/test-parser.c +++ b/test-parser.c @@ -38,14 +38,8 @@ #include <stdlib.h> #include <string.h> #include "scpi/scpi.h" -#include "scpi/scpi_ieee488.h" -#include "scpi/scpi_error.h" -#include "scpi/scpi_constants.h" -#include "scpi/scpi_minimal.h" -#include "scpi/scpi_utils.h" -#include "scpi/scpi_units.h" -int DMM_MeasureVoltageDcQ(scpi_context_t * context) { +scpi_result_t DMM_MeasureVoltageDcQ(scpi_t * context) { scpi_number_t param1, param2; char bf[15]; fprintf(stderr, "meas:volt:dc\r\n"); // debug command name @@ -63,10 +57,11 @@ } SCPI_ResultDouble(context, 0); - return 0; + + return SCPI_RES_OK; } -scpi_command_t scpi_commands[] = { +static const scpi_command_t scpi_commands[] = { /* IEEE Mandated Commands (SCPI std V1999.0 4.1.1) */ { .pattern = "*CLS", .callback = SCPI_CoreCls,}, { .pattern = "*ESE", .callback = SCPI_CoreEse,}, @@ -85,6 +80,7 @@ /* Required SCPI commands (SCPI std V1999.0 4.2.1) */ {.pattern = "SYSTem:ERRor?", .callback = SCPI_SystemErrorNextQ,}, {.pattern = "SYSTem:ERRor:NEXT?", .callback = SCPI_SystemErrorNextQ,}, + {.pattern = "SYSTem:ERRor:COUNt?", .callback = SCPI_SystemErrorCountQ,}, {.pattern = "SYSTem:VERSion?", .callback = SCPI_SystemVersionQ,}, //{.pattern = "STATus:OPERation?", .callback = scpi_stub_callback,}, @@ -115,35 +111,50 @@ SCPI_CMD_LIST_END }; -size_t SCPI_Write(scpi_context_t * context, const char * data, size_t len) { +static size_t SCPI_Write(scpi_t * context, const char * data, size_t len) { (void) context; return fwrite(data, 1, len, stdout); } -int SCPI_Error(scpi_context_t * context, int_fast16_t err) { +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; } -scpi_interface_t scpi_interface = { +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, + .srq = SCPI_Srq, }; -#define SCPI_BUFFER_LENGTH 256 -char buffer[SCPI_BUFFER_LENGTH]; +#define SCPI_INPUT_BUFFER_LENGTH 256 +static char scpi_input_buffer[SCPI_INPUT_BUFFER_LENGTH]; -scpi_buffer_t scpi_buffer = { - .length = SCPI_BUFFER_LENGTH, - .data = buffer, - // .data = (char[SCPI_BUFFER_LENGTH]){}, +static scpi_reg_val_t scpi_regs[SCPI_REG_COUNT]; + + +scpi_t scpi_context = { + .cmdlist = scpi_commands, + .buffer = { + .length = SCPI_INPUT_BUFFER_LENGTH, + .data = scpi_input_buffer, + }, + .interface = &scpi_interface, + .registers = scpi_regs, + .units = scpi_units_def, + .special_numbers = scpi_special_numbers_def, }; - -scpi_context_t scpi_context; /* * @@ -153,7 +164,7 @@ (void) argv; int result; - SCPI_Init(&scpi_context, scpi_commands, &scpi_buffer, &scpi_interface); + SCPI_Init(&scpi_context); #define TEST_SCPI_INPUT(cmd) result = SCPI_Input(&scpi_context, cmd, strlen(cmd)) @@ -169,6 +180,8 @@ 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"); @@ -187,8 +200,8 @@ // interactive demo //char smbuffer[10]; //while (1) { - // fgets(smbuffer, 10, stdin); - // SCPI_Input(&scpi_context, smbuffer, strlen(smbuffer)); + // fgets(smbuffer, 10, stdin); + // SCPI_Input(&scpi_context, smbuffer, strlen(smbuffer)); //} -- Gitblit v1.9.1