From 100e86891d03181d5a77639b903e799e97ffb187 Mon Sep 17 00:00:00 2001
From: Jan Breuer <jan.breuer@jaybee.cz>
Date: 周三, 26 12月 2012 20:47:08 +0800
Subject: [PATCH] Add output flush callback

---
 libscpi/inc/scpi/types.h |    1 +
 libscpi/src/parser.c     |   18 +++++++++++++++++-
 README.md                |   22 +++++++++++++---------
 3 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/README.md b/README.md
index 4044866..0c3b6dc 100644
--- a/README.md
+++ b/README.md
@@ -45,16 +45,20 @@
 
 Source codes are devided into few files to provide better portability to other systems.
 
-- *scpi_parser.c* - provides the core parser library
-- *scpi_error.c* - provides basic error handling (error queue of the instrument)
-- *scpi_ieee488.c* - provides basic implementation of IEEE488.2 mandatory commands
-- *scpi_minimal.c* - provides basic implementation of SCPI mandatory commands
-- *scpi_utils.c* - provides string handling routines and conversion routines
-- *scpi_units.c* - provides handling of special numners (DEF, MIN, MAX, ...) and units
-- *scpi_fifo.c* - provides basic implementation of error queue FIFO
-- *scpi_debug.c* - provides debug functions
+- *libscpi/parser.c* - provides the core parser library
+- *libscpi/error.c* - provides basic error handling (error queue of the instrument)
+- *libscpi/ieee488.c* - provides basic implementation of IEEE488.2 mandatory commands
+- *libscpi/minimal.c* - provides basic implementation of SCPI mandatory commands
+- *libscpi/utils.c* - provides string handling routines and conversion routines
+- *libscpi/units.c* - provides handling of special numners (DEF, MIN, MAX, ...) and units
+- *libscpi/fifo.c* - provides basic implementation of error queue FIFO
+- *libscpi/debug.c* - provides debug functions
 
-- *test-parser.c* - is the basic non-interactive demo of the parser
+- *examples/test-parser* - is the basic non-interactive demo of the parser
+- *examples/test-interactive* - is the basic interactive demo of the parser
+- *examples/test-tcp* - is the basic interactive tcp server (port 5025)
+- *examples/common* - common examples commands
+
 
 Implementation to your instrument
 -------------
diff --git a/libscpi/inc/scpi/types.h b/libscpi/inc/scpi/types.h
index 7e96a4e..2fb743f 100644
--- a/libscpi/inc/scpi/types.h
+++ b/libscpi/inc/scpi/types.h
@@ -102,6 +102,7 @@
     struct _scpi_interface_t {
         scpi_error_callback_t error;
         scpi_write_t write;
+        scpi_command_callback_t flush;
         scpi_command_callback_t reset;
         scpi_command_callback_t test;
         scpi_command_callback_t srq;
diff --git a/libscpi/src/parser.c b/libscpi/src/parser.c
index adf7e90..b5a5a9b 100644
--- a/libscpi/src/parser.c
+++ b/libscpi/src/parser.c
@@ -245,6 +245,19 @@
 }
 
 /**
+ * Flush data to SCPI output
+ * @param context
+ * @return
+ */
+static inline int flushData(scpi_t * context) {
+    if (context && context->interface && context->interface->flush) {
+        return context->interface->flush(context);
+    } else {
+        return SCPI_RES_OK;
+    }
+}
+
+/**
  * Write result delimiter to output
  * @param context
  * @return number of bytes written
@@ -263,8 +276,11 @@
  * @return pocet zapsanych znaku
  */
 static inline size_t writeNewLine(scpi_t * context) {
+    size_t len;
     if (context->output_count > 0) {
-        return writeData(context, "\r\n", 2);
+        len = writeData(context, "\r\n", 2);
+        flushData(context);
+        return len;
     } else {
         return 0;
     }

--
Gitblit v1.9.1