From 36f2d7dab1e65507841067073dd66d72b2dc663c Mon Sep 17 00:00:00 2001
From: Jan Breuer <jan.breuer@jaybee.cz>
Date: 周二, 04 12月 2012 17:24:30 +0800
Subject: [PATCH] Correct type refactoryng in README

---
 test-parser.c |  109 +++++++++++++++++++++++++++++-------------------------
 1 files changed, 59 insertions(+), 50 deletions(-)

diff --git a/test-parser.c b/test-parser.c
index e52ad26..66ca530 100644
--- a/test-parser.c
+++ b/test-parser.c
@@ -38,32 +38,31 @@
 #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"
 
-int DMM_MeasureVoltageDcQ(scpi_context_t * context) {
-    double param1, param2;
-    fprintf(stderr, "meas:volt:dc "); // debug command name
-    
-    // read first parameter
-    if (SCPI_ParamDouble(context, &param1, false)) {
-        fprintf(stderr, "P1=%lf ", param1);
-    }
-    
-    // read second paraeter
-    if (SCPI_ParamDouble(context, &param2, false)) {
-        fprintf(stderr, "P2=%lf ", param2);
+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   
+
+    // read first parameter if present
+    if (SCPI_ParamNumber(context, &param1, false)) {
+        SCPI_NumberToStr(context, &param1, bf, 15);
+        fprintf(stderr, "\tP1=%s\r\n", bf);
     }
 
-    fprintf(stderr, "\r\n");
+    // read second paraeter if present
+    if (SCPI_ParamNumber(context, &param2, false)) {
+        SCPI_NumberToStr(context, &param2, bf, 15);
+        fprintf(stderr, "\tP2=%s\r\n", bf);
+    }
+
     SCPI_ResultDouble(context, 0);
-    return 0;
+    
+    return SCPI_RES_OK;
 }
 
 scpi_command_t scpi_commands[] = {
-    /* Required IEEE488.2 Common Commands (see SCPI Standard V1999.0 ch4.1.1) */
+    /* IEEE Mandated Commands (SCPI std V1999.0 4.1.1) */
     { .pattern = "*CLS", .callback = SCPI_CoreCls,},
     { .pattern = "*ESE", .callback = SCPI_CoreEse,},
     { .pattern = "*ESE?", .callback = SCPI_CoreEseQ,},
@@ -78,9 +77,10 @@
     { .pattern = "*TST?", .callback = SCPI_CoreTstQ,},
     { .pattern = "*WAI", .callback = SCPI_CoreWai,},
 
-    /* Required SCPI commands (see SCPI Standard V1999.0 ch 4.2.1) */
+    /* 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,},
@@ -111,14 +111,14 @@
     SCPI_CMD_LIST_END
 };
 
-size_t SCPI_Write(scpi_context_t * context, const char * data, size_t len) {
+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) {
+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;
 }
@@ -139,7 +139,7 @@
     //    .data = (char[SCPI_BUFFER_LENGTH]){},
 };
 
-scpi_context_t scpi_context;
+scpi_t scpi_context;
 
 /*
  * 
@@ -148,37 +148,46 @@
     (void) argc;
     (void) argv;
     int result;
-    
-    //printf("%.*s %s\r\n",  3, "asdadasdasdasdas", "b");
-    
+
     SCPI_Init(&scpi_context, scpi_commands, &scpi_buffer, &scpi_interface);
 
-    // // interactive demo
-    //  char smbuffer[10];
-    //  while(1) {
-    //          fgets(smbuffer, 10, stdin);
-    //          SCPI_Input(&scpi_context, smbuffer, strlen(smbuffer));      
-    //  }
-       
-    result = SCPI_Input(&scpi_context, "*CLS\r\n", 6);
-    result = SCPI_Input(&scpi_context, "*RST\r\n", 6);
-    result = SCPI_Input(&scpi_context, "MEAS:volt:DC? 12,50;*OPC\r\n", 26);
-    result = SCPI_Input(&scpi_context, "*IDN?\r\n", 7);
-    result = SCPI_Input(&scpi_context, "SYST:VERS?", 10);
-    result = SCPI_Input(&scpi_context, "\r\n*ID", 5);
-    result = SCPI_Input(&scpi_context, "N?", 2);
-    result = SCPI_Input(&scpi_context, NULL, 0); // emulate command timeout
+#define TEST_SCPI_INPUT(cmd)    result = SCPI_Input(&scpi_context, cmd, strlen(cmd))
 
-    result = SCPI_Input(&scpi_context, "*ESE\r\n", 6);
-    result = SCPI_Input(&scpi_context, "*ESE 0x20\r\n", 11);
+    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
 
-    result = SCPI_Input(&scpi_context, "IDN?\r\n", 6); // cause error -113, undefined header
+    TEST_SCPI_INPUT("*ESE\r\n"); // cause error -109, missing parameter
+    TEST_SCPI_INPUT("*ESE 0x20\r\n");
 
-    result = SCPI_Input(&scpi_context, "SYST:ERR?\r\n", 11);
-    result = SCPI_Input(&scpi_context, "SYST:ERR?\r\n", 11);
-    result = SCPI_Input(&scpi_context, "*STB?\r\n", 6);
-    result = SCPI_Input(&scpi_context, "*ESR?\r\n", 6);
-    result = SCPI_Input(&scpi_context, "*STB?\r\n", 6);
+    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