From 4c11ea0639b923a171e72a47b8006734ba184b3e Mon Sep 17 00:00:00 2001 From: nancy.liao <huihui.liao@greentest.com.cn> Date: 周二, 15 4月 2025 18:47:46 +0800 Subject: [PATCH] 同步修改前的原SCPI库 --- examples/common/scpi-def.h | 2 examples/common-cxx/scpi-def.h | 12 libscpi/inc/scpi/units.h | 1 libscpi/src/parser.c | 91 ++++- libscpi/src/utils_private.h | 4 libscpi/src/error.c | 8 libscpi/src/scpi-def.c | 424 ++++++++++++++++++++++++ libscpi/src/test-interactive.cpp | 111 ++++++ CMakeLists.txt | 33 + examples/common/scpi-def.c | 1 libscpi/src/lexer.c | 19 + /dev/null | 141 -------- libscpi/inc/scpi/types.h | 19 + libscpi/src/fifo_private.h | 4 libscpi/src/ieee488.c | 17 libscpi/inc/scpi/ieee488.h | 2 libscpi/src/units.c | 11 examples/test-tcp/main.c | 2 libscpi/inc/scpi/scpi-def.h | 65 +++ examples/test-interactive-cxx/main.cpp | 3 libscpi/inc/scpi/parser.h | 10 libscpi/src/utils.c | 7 examples/common-cxx/scpi-def.cpp | 20 23 files changed, 806 insertions(+), 201 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0826c6e..6b54d66 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,8 +3,16 @@ file(GLOB_RECURSE SRC_FILES libscpi/inc/*.h - libscpi/src/*.c + libscpi/src/*.c + libscpi/src/*.h + libscpi/src/*.cpp ) + + + +find_package(QT NAMES Qt6 Qt5 REQUIRED) +find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core) +set_source_files_properties(" libscpi/src/test-interactive.cpp" PROPERTIES HEADER_FILE_ONLY TRUE) add_library(scpi_static STATIC ${SRC_FILES}) @@ -12,6 +20,14 @@ PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/libscpi/inc>" ) + +target_link_libraries(scpi_static PRIVATE Qt::Core) + +# if(MSVC) +# target_compile_options(scpi_static PRIVATE /TP) +# endif() + +project(scpi_static LANGUAGES CXX) # add_library(scpi SHARED ${SRC_FILES}) @@ -26,19 +42,4 @@ file(GLOB_RECURSE TEST_FILES libscpi/test/*.c ) -foreach(test_file IN LISTS TEST_FILES) - cmake_path(GET test_file FILENAME test_name) - add_executable(${test_name} ${test_file}) - - target_link_libraries(${test_name} - PRIVATE - scpi_static - unofficial::cunit::cunit - ) - - add_test( - NAME "${test_name}" - COMMAND ${test_name} - ) -endforeach() diff --git a/examples/common-cxx/scpi-def.cpp b/examples/common-cxx/scpi-def.cpp index abbc80a..c2fd351 100644 --- a/examples/common-cxx/scpi-def.cpp +++ b/examples/common-cxx/scpi-def.cpp @@ -338,6 +338,12 @@ return SCPI_RES_OK; } +scpi_result_t SCPI_NanCy(scpi_t * context) +{ + fprintf(stdout, "SCPI_NanCy: SCPI_NanCy\r\n"); + return SCPI_RES_OK; +} + /** * Reimplement IEEE488.2 *TST? * @@ -352,7 +358,10 @@ return SCPI_RES_OK; } - +/* + scpi_commands鎻愪緵浜嗘墍鏈夌殑scpi鍛戒护浠ュ強鍛戒护鐨勫洖璋冨嚱鏁板拰澶勭悊 + 鍚庣画濡傛灉闇�瑕佹坊鍔犺嚜瀹氫箟鐨勬寚浠ら泦鍒欏湪姝ゅ娣诲姞 +*/ const scpi_command_t scpi_commands[] = { /* IEEE Mandated Commands (SCPI std V1999.0 4.1.1) */ {"*CLS", SCPI_CoreCls, 0}, @@ -368,20 +377,15 @@ {"*STB?", SCPI_CoreStbQ, 0}, {"*TST?", My_CoreTstQ, 0}, {"*WAI", SCPI_CoreWai, 0}, + //鐢ㄦ潵娴嬭瘯 + {"*NanCy", SCPI_NanCy, 0}, /* Required SCPI commands (SCPI std V1999.0 4.2.1) */ {"SYSTem:ERRor[:NEXT]?", SCPI_SystemErrorNextQ, 0}, {"SYSTem:ERRor:COUNt?", SCPI_SystemErrorCountQ, 0}, {"SYSTem:VERSion?", SCPI_SystemVersionQ, 0}, - //{"STATus:OPERation?", scpi_stub_callback, 0}, - //{"STATus:OPERation:EVENt?", scpi_stub_callback, 0}, - //{"STATus:OPERation:CONDition?", scpi_stub_callback, 0}, - //{"STATus:OPERation:ENABle", scpi_stub_callback, 0}, - //{"STATus:OPERation:ENABle?", scpi_stub_callback, 0}, - {"STATus:QUEStionable[:EVENt]?", SCPI_StatusQuestionableEventQ, 0}, - //{"STATus:QUEStionable:CONDition?", scpi_stub_callback, 0}, {"STATus:QUEStionable:ENABle", SCPI_StatusQuestionableEnable, 0}, {"STATus:QUEStionable:ENABle?", SCPI_StatusQuestionableEnableQ, 0}, diff --git a/examples/common-cxx/scpi-def.h b/examples/common-cxx/scpi-def.h index 9354b35..8ce5c0c 100644 --- a/examples/common-cxx/scpi-def.h +++ b/examples/common-cxx/scpi-def.h @@ -32,6 +32,18 @@ #include "scpi/scpi.h" + +/* + SCPI_IDN1 + SCPI_IDN2 + SCPI_IDN3 + SCPI_IDN4 + 杩欏嚑涓弬鏁版槸鐢ㄦ潵娉ㄥ唽鏃惰〃绀轰俊鎭� + 瀵瑰簲*IDN? 鏌ヨ鍛戒护鐨勮繑鍥炲唴瀹癸紙璁惧鏍囪瘑鏌ヨ鍛戒护锛� + 鍏蜂綋鍐呭涓猴紙鍒堕�犲晢,鍨嬪彿,搴忓垪鍙�,鍥轰欢鐗堟湰锛� + 濡傛灉浣跨敤CPP鐗堟湰鐨勮瘽浣跨敤scpi-def.h 鍜宻cpi-def.cpp + 杩欎釜鎻愪緵浜咰PP鐗堟湰鐨勬敮鎸侊紝.c鐨勭増鏈负鏃ф爣鍑嗙増鐗堟湰 +*/ #define SCPI_INPUT_BUFFER_LENGTH 256 #define SCPI_ERROR_QUEUE_SIZE 17 #define SCPI_IDN1 "MANUFACTURE" diff --git a/examples/common/scpi-def.c b/examples/common/scpi-def.c index 5021621..d46c067 100644 --- a/examples/common/scpi-def.c +++ b/examples/common/scpi-def.c @@ -407,7 +407,6 @@ {.pattern = "TEST:TEXT", .callback = TEST_Text,}, {.pattern = "TEST:ARBitrary?", .callback = TEST_ArbQ,}, {.pattern = "TEST:CHANnellist", .callback = TEST_Chanlst,}, - SCPI_CMD_LIST_END }; diff --git a/examples/common/scpi-def.h b/examples/common/scpi-def.h index 9e89f95..471c9a9 100644 --- a/examples/common/scpi-def.h +++ b/examples/common/scpi-def.h @@ -36,6 +36,8 @@ #define SCPI_INPUT_BUFFER_LENGTH 256 #define SCPI_ERROR_QUEUE_SIZE 17 + + #define SCPI_IDN1 "MANUFACTURE" #define SCPI_IDN2 "INSTR2013" #define SCPI_IDN3 NULL diff --git a/examples/test-CVI_w_GUI/.gitignore b/examples/test-CVI_w_GUI/.gitignore deleted file mode 100644 index df1fbf8..0000000 --- a/examples/test-CVI_w_GUI/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -cvibuild.TestLibSCPI_GUI -*.cdb -*.cws diff --git a/examples/test-CVI_w_GUI/TestLibSCPI_GUI.prj b/examples/test-CVI_w_GUI/TestLibSCPI_GUI.prj deleted file mode 100644 index dcfa994..0000000 --- a/examples/test-CVI_w_GUI/TestLibSCPI_GUI.prj +++ /dev/null @@ -1,676 +0,0 @@ -[Project Header] -Version = 1201 -Pathname = "/c/git/Lutzscpi-parser/examples/test-CVI_w_GUI/TestLibSCPI_GUI.prj" -CVI Dir = "/c/program files (x86)/national instruments/cvi2012" -CVI Shared Dir = "/C/Program Files (x86)/National Instruments/Shared/CVI" -CVI Pub Local Dir = "/C/ProgramData/National Instruments/CVI2012" -CVI Pub Global Dir = "/C/ProgramData/National Instruments/CVI" -IVI Standard Root Dir = "/C/Program Files (x86)/IVI Foundation/IVI" -VXIplug&play Framework Dir = "/C/Program Files (x86)/IVI Foundation/VISA/winnt" -IVI Standard Root 64-bit Dir = "/C/Program Files/IVI Foundation/IVI" -VXIplug&play Framework 64-bit Dir = "/C/Program Files/IVI Foundation/VISA/win64" -Number of Files = 26 -Target Type = "Executable" -Flags = 2064 -Copied From Locked InstrDrv Directory = False -Copied from VXIPNP Directory = False -Locked InstrDrv Name = "" -Don't Display Deploy InstrDrv Dialog = False - -[File 0001] -File Type = "CSource" -Res Id = 1 -Path Is Rel = True -Path Rel To = "Project" -Path Rel Path = "main.c" -Path = "/c/git/Lutzscpi-parser/examples/test-CVI_w_GUI/main.c" -Exclude = False -Compile Into Object File = False -Project Flags = 0 -Folder = "Source Files" -Folder Id = 0 - -[File 0002] -File Type = "CSource" -Res Id = 2 -Path Is Rel = True -Path Rel To = "Project" -Path Rel Path = "../common/scpi-def.c" -Path = "/c/git/Lutzscpi-parser/examples/common/scpi-def.c" -Exclude = False -Compile Into Object File = False -Project Flags = 0 -Folder = "Source Files" -Folder Id = 0 - -[File 0003] -File Type = "Include" -Res Id = 3 -Path Is Rel = True -Path Rel To = "Project" -Path Rel Path = "../../libscpi/inc/scpi/config.h" -Path = "/c/git/Lutzscpi-parser/libscpi/inc/scpi/config.h" -Exclude = False -Project Flags = 0 -Folder = "Include Files" -Folder Id = 1 - -[File 0004] -File Type = "Include" -Res Id = 4 -Path Is Rel = True -Path Rel To = "Project" -Path Rel Path = "../../libscpi/inc/scpi/constants.h" -Path = "/c/git/Lutzscpi-parser/libscpi/inc/scpi/constants.h" -Exclude = False -Project Flags = 0 -Folder = "Include Files" -Folder Id = 1 - -[File 0005] -File Type = "Include" -Res Id = 5 -Path Is Rel = True -Path Rel To = "Project" -Path Rel Path = "../../libscpi/inc/scpi/error.h" -Path = "/c/git/Lutzscpi-parser/libscpi/inc/scpi/error.h" -Exclude = False -Project Flags = 0 -Folder = "Include Files" -Folder Id = 1 - -[File 0006] -File Type = "Include" -Res Id = 6 -Path Is Rel = True -Path Rel To = "Project" -Path Rel Path = "../../libscpi/inc/scpi/ieee488.h" -Path = "/c/git/Lutzscpi-parser/libscpi/inc/scpi/ieee488.h" -Exclude = False -Project Flags = 0 -Folder = "Include Files" -Folder Id = 1 - -[File 0007] -File Type = "Include" -Res Id = 7 -Path Is Rel = True -Path Rel To = "Project" -Path Rel Path = "../../libscpi/inc/scpi/minimal.h" -Path = "/c/git/Lutzscpi-parser/libscpi/inc/scpi/minimal.h" -Exclude = False -Project Flags = 0 -Folder = "Include Files" -Folder Id = 1 - -[File 0008] -File Type = "Include" -Res Id = 8 -Path Is Rel = True -Path Rel To = "Project" -Path Rel Path = "../../libscpi/inc/scpi/scpi.h" -Path = "/c/git/Lutzscpi-parser/libscpi/inc/scpi/scpi.h" -Exclude = False -Project Flags = 0 -Folder = "Include Files" -Folder Id = 1 - -[File 0009] -File Type = "Include" -Res Id = 9 -Path Is Rel = True -Path Rel To = "Project" -Path Rel Path = "scpi_user_config.h" -Path = "/c/git/Lutzscpi-parser/examples/test-CVI_w_GUI/scpi_user_config.h" -Exclude = False -Project Flags = 0 -Folder = "Include Files" -Folder Id = 1 - -[File 0010] -File Type = "Include" -Res Id = 10 -Path Is Rel = True -Path Rel To = "Project" -Path Rel Path = "TestLibscpi.h" -Path = "/c/git/Lutzscpi-parser/examples/test-CVI_w_GUI/TestLibscpi.h" -Exclude = False -Project Flags = 0 -Folder = "Include Files" -Folder Id = 1 - -[File 0011] -File Type = "Include" -Res Id = 11 -Path Is Rel = True -Path Rel To = "Project" -Path Rel Path = "../../libscpi/inc/scpi/units.h" -Path = "/c/git/Lutzscpi-parser/libscpi/inc/scpi/units.h" -Exclude = False -Project Flags = 0 -Folder = "Include Files" -Folder Id = 1 - -[File 0012] -File Type = "Include" -Res Id = 12 -Path Is Rel = True -Path Rel To = "Project" -Path Rel Path = "../../libscpi/inc/scpi/utils.h" -Path = "/c/git/Lutzscpi-parser/libscpi/inc/scpi/utils.h" -Exclude = False -Project Flags = 0 -Folder = "Include Files" -Folder Id = 1 - -[File 0013] -File Type = "User Interface Resource" -Res Id = 13 -Path Is Rel = True -Path Rel To = "Project" -Path Rel Path = "TestLibscpi.uir" -Path = "/c/git/Lutzscpi-parser/examples/test-CVI_w_GUI/TestLibscpi.uir" -Exclude = False -Project Flags = 0 -Folder = "User Interface Files" -Folder Id = 2 - -[File 0014] -File Type = "CSource" -Res Id = 14 -Path Is Rel = True -Path Rel To = "Project" -Path Rel Path = "../../libscpi/src/error.c" -Path = "/c/git/Lutzscpi-parser/libscpi/src/error.c" -Exclude = False -Compile Into Object File = False -Project Flags = 0 -Folder = "libscpi" -Folder Id = 3 - -[File 0015] -File Type = "CSource" -Res Id = 15 -Path Is Rel = True -Path Rel To = "Project" -Path Rel Path = "../../libscpi/src/fifo.c" -Path = "/c/git/Lutzscpi-parser/libscpi/src/fifo.c" -Exclude = False -Compile Into Object File = False -Project Flags = 0 -Folder = "libscpi" -Folder Id = 3 - -[File 0016] -File Type = "Include" -Res Id = 16 -Path Is Rel = True -Path Rel To = "Project" -Path Rel Path = "../../libscpi/src/fifo_private.h" -Path = "/c/git/Lutzscpi-parser/libscpi/src/fifo_private.h" -Exclude = False -Project Flags = 0 -Folder = "libscpi" -Folder Id = 3 - -[File 0017] -File Type = "CSource" -Res Id = 17 -Path Is Rel = True -Path Rel To = "Project" -Path Rel Path = "../../libscpi/src/ieee488.c" -Path = "/c/git/Lutzscpi-parser/libscpi/src/ieee488.c" -Exclude = False -Compile Into Object File = False -Project Flags = 0 -Folder = "libscpi" -Folder Id = 3 - -[File 0018] -File Type = "CSource" -Res Id = 18 -Path Is Rel = True -Path Rel To = "Project" -Path Rel Path = "../../libscpi/src/lexer.c" -Path = "/c/git/Lutzscpi-parser/libscpi/src/lexer.c" -Exclude = False -Compile Into Object File = False -Project Flags = 0 -Folder = "libscpi" -Folder Id = 3 - -[File 0019] -File Type = "Include" -Res Id = 19 -Path Is Rel = True -Path Rel To = "Project" -Path Rel Path = "../../libscpi/src/lexer_private.h" -Path = "/c/git/Lutzscpi-parser/libscpi/src/lexer_private.h" -Exclude = False -Project Flags = 0 -Folder = "libscpi" -Folder Id = 3 - -[File 0020] -File Type = "CSource" -Res Id = 20 -Path Is Rel = True -Path Rel To = "Project" -Path Rel Path = "../../libscpi/src/minimal.c" -Path = "/c/git/Lutzscpi-parser/libscpi/src/minimal.c" -Exclude = False -Compile Into Object File = False -Project Flags = 0 -Folder = "libscpi" -Folder Id = 3 - -[File 0021] -File Type = "CSource" -Res Id = 21 -Path Is Rel = True -Path Rel To = "Project" -Path Rel Path = "../../libscpi/src/parser.c" -Path = "/c/git/Lutzscpi-parser/libscpi/src/parser.c" -Exclude = False -Compile Into Object File = False -Project Flags = 0 -Folder = "libscpi" -Folder Id = 3 - -[File 0022] -File Type = "Include" -Res Id = 22 -Path Is Rel = True -Path Rel To = "Project" -Path Rel Path = "../../libscpi/src/parser_private.h" -Path = "/c/git/Lutzscpi-parser/libscpi/src/parser_private.h" -Exclude = False -Project Flags = 0 -Folder = "libscpi" -Folder Id = 3 - -[File 0023] -File Type = "CSource" -Res Id = 23 -Path Is Rel = True -Path Rel To = "Project" -Path Rel Path = "../../libscpi/src/units.c" -Path = "/c/git/Lutzscpi-parser/libscpi/src/units.c" -Exclude = False -Compile Into Object File = False -Project Flags = 0 -Folder = "libscpi" -Folder Id = 3 - -[File 0024] -File Type = "CSource" -Res Id = 24 -Path Is Rel = True -Path Rel To = "Project" -Path Rel Path = "../../libscpi/src/utils.c" -Path = "/c/git/Lutzscpi-parser/libscpi/src/utils.c" -Exclude = False -Compile Into Object File = False -Project Flags = 0 -Folder = "libscpi" -Folder Id = 3 - -[File 0025] -File Type = "Include" -Res Id = 25 -Path Is Rel = True -Path Rel To = "Project" -Path Rel Path = "../../libscpi/src/utils_private.h" -Path = "/c/git/Lutzscpi-parser/libscpi/src/utils_private.h" -Exclude = False -Project Flags = 0 -Folder = "libscpi" -Folder Id = 3 - -[File 0026] -File Type = "Include" -Res Id = 26 -Path Is Rel = True -Path Rel To = "Project" -Path Rel Path = "../../libscpi/inc/scpi/parser.h" -Path = "/c/git/Lutzscpi-parser/libscpi/inc/scpi/parser.h" -Exclude = False -Project Flags = 0 -Folder = "Not In A Folder" - -[Folders] -Instrument Files Folder Not Added Yet = True -Library Files Folder Not Added Yet = True -Folder 0 = "Source Files" -Folder 1 = "Include Files" -Folder 2 = "User Interface Files" -Folder 3 = "libscpi" - -[Custom Build Configs] -Num Custom Build Configs = 0 - -[Default Build Config Debug] -Config Name = "Debug" -Is 64-Bit = False -Is Release = False -Default Calling Convention = "cdecl" -Uninitialized Locals Compile Warning = "Conservative" -Require Prototypes = True -Require Return Values = True -Enable Pointer Mismatch Warning = False -Enable Unreachable Code Warning = False -Enable Unreferenced Identifiers Warning = False -Enable Assignment In Conditional Warning = False -Enable C99 Extensions = True -Stack Size = 250000 -Image Base Address = 4194304 -Image Base Address x64 = 4194304 -Compiler Defines = "/DWIN32_LEAN_AND_MEAN /DSCPI_USER_CONFIG" -Sign = False -Sign Store = "" -Sign Certificate = "" -Sign Timestamp URL = "" -Sign URL = "" -Manifest Embed = False -Icon File Is Rel = False -Icon File = "" -Application Title = "" -DLL Import Library Choice = "Gen Lib For Current Mode" -Use IVI Subdirectories for Import Libraries = False -Use VXIPNP Subdirectories for Import Libraries = False -Use Dflt Import Lib Base Name = True -Where to Copy DLL = "Do not copy" -Custom Directory to Copy DLL Is Rel = False -Custom Directory to Copy DLL = "" -Generate Source Documentation = "None" -Runtime Support = "Full Runtime Support" -Runtime Binding = "Shared" -Embed Project .UIRs = False -Generate Map File = False -Create Console Application = False -Using LoadExternalModule = False -DLL Exports = "Include File Symbols" -Register ActiveX Server = False -Numeric File Version = "1,0,0,0" -Numeric Prod Version = "1,0,0,0" -Comments = "" -Comments Ex = "" -Company Name = "Thorlabs" -Company Name Ex = "%company" -File Description = "TestLibSCPI_GUI (Debug x86)" -File Description Ex = "%application (%rel_dbg %arch)" -File Version = "1.0" -File Version Ex = "%f1.%f2" -Internal Name = "TestLibSCPI_GUI" -Internal Name Ex = "%basename" -Legal Copyright = "Copyright � Thorlabs 2015" -Legal Copyright Ex = "Copyright � %company %Y" -Legal Trademarks = "" -Legal Trademarks Ex = "" -Original Filename = "TestLibSCPI_GUI.exe" -Original Filename Ex = "%filename" -Private Build = "" -Private Build Ex = "" -Product Name = "Thorlabs TestLibSCPI_GUI" -Product Name Ex = "%company %application" -Product Version = "1.0" -Product Version Ex = "%p1.%p2" -Special Build = "" -Special Build Ex = "" -Add Type Lib To DLL = False -Include Type Lib Help Links = False -TLB Help Style = "HLP" -Type Lib FP File Is Rel = False -Type Lib FP File = "" - -[Default Build Config Release] -Config Name = "Release" -Is 64-Bit = False -Is Release = True -Default Calling Convention = "cdecl" -Uninitialized Locals Compile Warning = "Conservative" -Require Prototypes = True -Require Return Values = True -Enable Pointer Mismatch Warning = False -Enable Unreachable Code Warning = False -Enable Unreferenced Identifiers Warning = False -Enable Assignment In Conditional Warning = False -Enable C99 Extensions = True -Stack Size = 250000 -Image Base Address = 4194304 -Image Base Address x64 = 4194304 -Compiler Defines = "/DWIN32_LEAN_AND_MEAN /DSCPI_USER_CONFIG" -Sign = False -Sign Store = "" -Sign Certificate = "" -Sign Timestamp URL = "" -Sign URL = "" -Manifest Embed = False -Icon File Is Rel = False -Icon File = "" -Application Title = "" -DLL Import Library Choice = "Gen Lib For Current Mode" -Use IVI Subdirectories for Import Libraries = False -Use VXIPNP Subdirectories for Import Libraries = False -Use Dflt Import Lib Base Name = True -Where to Copy DLL = "Do not copy" -Custom Directory to Copy DLL Is Rel = False -Custom Directory to Copy DLL = "" -Generate Source Documentation = "None" -Runtime Support = "Full Runtime Support" -Runtime Binding = "Shared" -Embed Project .UIRs = False -Generate Map File = False -Create Console Application = False -Using LoadExternalModule = False -DLL Exports = "Include File Symbols" -Register ActiveX Server = False -Add Type Lib To DLL = False -Include Type Lib Help Links = False -TLB Help Style = "HLP" -Type Lib FP File Is Rel = False -Type Lib FP File = "" - -[Default Build Config Debug64] -Config Name = "Debug64" -Is 64-Bit = True -Is Release = False -Default Calling Convention = "cdecl" -Uninitialized Locals Compile Warning = "Conservative" -Require Prototypes = True -Require Return Values = True -Enable Pointer Mismatch Warning = False -Enable Unreachable Code Warning = False -Enable Unreferenced Identifiers Warning = False -Enable Assignment In Conditional Warning = False -Enable C99 Extensions = True -Stack Size = 250000 -Image Base Address = 4194304 -Image Base Address x64 = 4194304 -Compiler Defines = "/DWIN32_LEAN_AND_MEAN /DSCPI_USER_CONFIG" -Sign = False -Sign Store = "" -Sign Certificate = "" -Sign Timestamp URL = "" -Sign URL = "" -Manifest Embed = False -Icon File Is Rel = False -Icon File = "" -Application Title = "" -DLL Import Library Choice = "Gen Lib For Current Mode" -Use IVI Subdirectories for Import Libraries = False -Use VXIPNP Subdirectories for Import Libraries = False -Use Dflt Import Lib Base Name = True -Where to Copy DLL = "Do not copy" -Custom Directory to Copy DLL Is Rel = False -Custom Directory to Copy DLL = "" -Generate Source Documentation = "None" -Runtime Support = "Full Runtime Support" -Runtime Binding = "Shared" -Embed Project .UIRs = False -Generate Map File = False -Create Console Application = False -Using LoadExternalModule = False -DLL Exports = "Include File Symbols" -Register ActiveX Server = False -Add Type Lib To DLL = False -Include Type Lib Help Links = False -TLB Help Style = "HLP" -Type Lib FP File Is Rel = False -Type Lib FP File = "" - -[Default Build Config Release64] -Config Name = "Release64" -Is 64-Bit = True -Is Release = True -Default Calling Convention = "cdecl" -Uninitialized Locals Compile Warning = "Conservative" -Require Prototypes = True -Require Return Values = True -Enable Pointer Mismatch Warning = False -Enable Unreachable Code Warning = False -Enable Unreferenced Identifiers Warning = False -Enable Assignment In Conditional Warning = False -Enable C99 Extensions = True -Stack Size = 250000 -Image Base Address = 4194304 -Image Base Address x64 = 4194304 -Compiler Defines = "/DWIN32_LEAN_AND_MEAN /DSCPI_USER_CONFIG" -Sign = False -Sign Store = "" -Sign Certificate = "" -Sign Timestamp URL = "" -Sign URL = "" -Manifest Embed = False -Icon File Is Rel = False -Icon File = "" -Application Title = "" -DLL Import Library Choice = "Gen Lib For Current Mode" -Use IVI Subdirectories for Import Libraries = False -Use VXIPNP Subdirectories for Import Libraries = False -Use Dflt Import Lib Base Name = True -Where to Copy DLL = "Do not copy" -Custom Directory to Copy DLL Is Rel = False -Custom Directory to Copy DLL = "" -Generate Source Documentation = "None" -Runtime Support = "Full Runtime Support" -Runtime Binding = "Shared" -Embed Project .UIRs = False -Generate Map File = False -Create Console Application = False -Using LoadExternalModule = False -DLL Exports = "Include File Symbols" -Register ActiveX Server = False -Add Type Lib To DLL = False -Include Type Lib Help Links = False -TLB Help Style = "HLP" -Type Lib FP File Is Rel = False -Type Lib FP File = "" - -[Compiler Options] -Default Calling Convention = "cdecl" -Require Prototypes = True -Require Return Values = True -Enable Pointer Mismatch Warning = False -Enable Unreachable Code Warning = False -Enable Unreferenced Identifiers Warning = False -Enable Assignment In Conditional Warning = False -O Option Compatible With 5.0 = False -Enable C99 Extensions = True -Uninitialized Locals Compile Warning = "Conservative" -Precompile Prefix Header = False -Prefix Header File = "" - -[Run Options] -Stack Size = 250000 -Image Base Address = 4194304 -Image Base Address x64 = 4194304 - -[Compiler Defines] -Compiler Defines = "/DWIN32_LEAN_AND_MEAN /DSCPI_USER_CONFIG" - -[Include Paths] -Include Path 1 Is Rel = True -Include Path 1 Rel To = "Project" -Include Path 1 Rel Path = "../../libscpi/inc" -Include Path 1 = "/c/git/Lutzscpi-parser/libscpi/inc" - -[Create Executable] -Executable File_Debug Is Rel = True -Executable File_Debug Rel To = "Project" -Executable File_Debug Rel Path = "TestLibSCPI_GUI.exe" -Executable File_Debug = "/c/git/Lutzscpi-parser/examples/test-CVI_w_GUI/TestLibSCPI_GUI.exe" -Executable File_Release Is Rel = True -Executable File_Release Rel To = "Project" -Executable File_Release Rel Path = "TestLibSCPI_GUI.exe" -Executable File_Release = "/c/git/Lutzscpi-parser/examples/test-CVI_w_GUI/TestLibSCPI_GUI.exe" -Executable File_Debug64 Is Rel = True -Executable File_Debug64 Rel To = "Project" -Executable File_Debug64 Rel Path = "TestLibSCPI_GUI.exe" -Executable File_Debug64 = "/c/git/Lutzscpi-parser/examples/test-CVI_w_GUI/TestLibSCPI_GUI.exe" -Executable File_Release64 Is Rel = True -Executable File_Release64 Rel To = "Project" -Executable File_Release64 Rel Path = "TestLibSCPI_GUI.exe" -Executable File_Release64 = "/c/git/Lutzscpi-parser/examples/test-CVI_w_GUI/TestLibSCPI_GUI.exe" -Icon File Is Rel = False -Icon File = "" -Application Title = "" -DLL Exports = "Include File Symbols" -DLL Import Library Choice = "Gen Lib For Current Mode" -Use IVI Subdirectories for Import Libraries = False -Use VXIPNP Subdirectories for Import Libraries = False -Use Dflt Import Lib Base Name = True -Where to Copy DLL = "Do not copy" -Custom Directory to Copy DLL Is Rel = False -Custom Directory to Copy DLL = "" -Generate Source Documentation = "None" -Add Type Lib To DLL = False -Include Type Lib Help Links = False -TLB Help Style = "HLP" -Type Lib FP File Is Rel = False -Type Lib FP File = "" -Type Lib Guid = "" -Runtime Support = "Full Runtime Support" -Instrument Driver Support Only = False -Embed Project .UIRs = False -Generate Map File = False - -[External Compiler Support] -UIR Callbacks File Option = 0 -Using LoadExternalModule = False -Create Project Symbols File = True -UIR Callbacks Obj File Is Rel = False -UIR Callbacks Obj File = "" -Project Symbols H File Is Rel = False -Project Symbols H File = "" -Project Symbols Obj File Is Rel = False -Project Symbols Obj File = "" - -[ActiveX Server Options] -Specification File Is Rel = False -Specification File = "" -Source File Is Rel = False -Source File = "" -Include File Is Rel = False -Include File = "" -IDL File Is Rel = False -IDL File = "" -Register ActiveX Server = False - -[Signing Info] -Sign = False -Sign Debug Build = False -Store = "" -Certificate = "" -Timestamp URL = "" -URL = "" - -[Manifest Info] -Embed = False - -[tpcSection] -tpcEnabled = 0 -tpcOverrideEnvironment = 0 -tpcEnabled x64 = 0 -tpcOverrideEnvironment x64 = 0 - diff --git a/examples/test-CVI_w_GUI/TestLibscpi.uir b/examples/test-CVI_w_GUI/TestLibscpi.uir deleted file mode 100644 index c2bb105..0000000 --- a/examples/test-CVI_w_GUI/TestLibscpi.uir +++ /dev/null Binary files differ diff --git a/examples/test-interactive-cxx/Makefile b/examples/test-interactive-cxx/Makefile deleted file mode 100644 index 49ed93c..0000000 --- a/examples/test-interactive-cxx/Makefile +++ /dev/null @@ -1,22 +0,0 @@ - -PROG = test - -SRCS = main.cpp ../common-cxx/scpi-def.cpp -CPPFLAGS += -I ../../libscpi/inc/ -CXXFLAGS += -Wextra -LDFLAGS += -lm ../../libscpi/dist/libscpi.a -Wl,--as-needed - -.PHONY: clean all - -all: $(PROG) - -OBJS = $(SRCS:.cpp=.o) - -%.o: %.cpp - $(CXX) -c $(CXXFLAGS) $(CPPFLAGS) -o $@ $< - -$(PROG): $(OBJS) - $(CXX) -o $@ $(OBJS) $(CXXFLAGS) $(LDFLAGS) - -clean: - $(RM) $(PROG) $(OBJS) diff --git a/examples/test-interactive-cxx/main.cpp b/examples/test-interactive-cxx/main.cpp index de6e43e..7722911 100644 --- a/examples/test-interactive-cxx/main.cpp +++ b/examples/test-interactive-cxx/main.cpp @@ -34,6 +34,9 @@ * * */ + +//#include "../common-cxx/scpi-def.h" + //杩欎釜鐗堟湰娴嬭瘯鐢ㄤ緥鎻愪緵浜咰PP鐗堟湰鐨凷ICP搴� 鍏朵粬鐨勪负C鐗堟湰鐨勫簱 #include <iostream> #include "scpi/scpi.h" #include "../common-cxx/scpi-def.h" diff --git a/examples/test-interactive/Makefile b/examples/test-interactive/Makefile deleted file mode 100644 index dcfa0b1..0000000 --- a/examples/test-interactive/Makefile +++ /dev/null @@ -1,21 +0,0 @@ - -PROG = test - -SRCS = main.c ../common/scpi-def.c -CFLAGS += -Wextra -Wmissing-prototypes -Wimplicit -I ../../libscpi/inc/ -LDFLAGS += -lm ../../libscpi/dist/libscpi.a -Wl,--as-needed - -.PHONY: clean all - -all: $(PROG) - -OBJS = $(SRCS:.c=.o) - -.c.o: - $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $< - -$(PROG): $(OBJS) - $(CC) -o $@ $(OBJS) $(CFLAGS) $(LDFLAGS) - -clean: - $(RM) $(PROG) $(OBJS) diff --git a/examples/test-parser/Makefile b/examples/test-parser/Makefile deleted file mode 100644 index dcfa0b1..0000000 --- a/examples/test-parser/Makefile +++ /dev/null @@ -1,21 +0,0 @@ - -PROG = test - -SRCS = main.c ../common/scpi-def.c -CFLAGS += -Wextra -Wmissing-prototypes -Wimplicit -I ../../libscpi/inc/ -LDFLAGS += -lm ../../libscpi/dist/libscpi.a -Wl,--as-needed - -.PHONY: clean all - -all: $(PROG) - -OBJS = $(SRCS:.c=.o) - -.c.o: - $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $< - -$(PROG): $(OBJS) - $(CC) -o $@ $(OBJS) $(CFLAGS) $(LDFLAGS) - -clean: - $(RM) $(PROG) $(OBJS) diff --git a/examples/test-tcp-srq/Makefile b/examples/test-tcp-srq/Makefile deleted file mode 100644 index dcfa0b1..0000000 --- a/examples/test-tcp-srq/Makefile +++ /dev/null @@ -1,21 +0,0 @@ - -PROG = test - -SRCS = main.c ../common/scpi-def.c -CFLAGS += -Wextra -Wmissing-prototypes -Wimplicit -I ../../libscpi/inc/ -LDFLAGS += -lm ../../libscpi/dist/libscpi.a -Wl,--as-needed - -.PHONY: clean all - -all: $(PROG) - -OBJS = $(SRCS:.c=.o) - -.c.o: - $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $< - -$(PROG): $(OBJS) - $(CC) -o $@ $(OBJS) $(CFLAGS) $(LDFLAGS) - -clean: - $(RM) $(PROG) $(OBJS) diff --git a/examples/test-tcp/Makefile b/examples/test-tcp/Makefile deleted file mode 100644 index dcfa0b1..0000000 --- a/examples/test-tcp/Makefile +++ /dev/null @@ -1,21 +0,0 @@ - -PROG = test - -SRCS = main.c ../common/scpi-def.c -CFLAGS += -Wextra -Wmissing-prototypes -Wimplicit -I ../../libscpi/inc/ -LDFLAGS += -lm ../../libscpi/dist/libscpi.a -Wl,--as-needed - -.PHONY: clean all - -all: $(PROG) - -OBJS = $(SRCS:.c=.o) - -.c.o: - $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $< - -$(PROG): $(OBJS) - $(CC) -o $@ $(OBJS) $(CFLAGS) $(LDFLAGS) - -clean: - $(RM) $(PROG) $(OBJS) diff --git a/examples/test-tcp/main.c b/examples/test-tcp/main.c index 814dbf5..436a4b9 100644 --- a/examples/test-tcp/main.c +++ b/examples/test-tcp/main.c @@ -179,6 +179,8 @@ /* * */ + + //缃戠粶閫氫俊閮ㄥ垎鍙互涓嶄娇鐢ㄦ爣鍑咰鐨剆ocket閫氫俊锛屽彲浠ラ噰鐢–++鎴栬�匭t鐨勭綉缁滃簱杩涜浼犺緭 int main(int argc, char** argv) { (void) argc; (void) argv; diff --git a/examples/test-vxi11/Makefile b/examples/test-vxi11/Makefile deleted file mode 100644 index 41e0277..0000000 --- a/examples/test-vxi11/Makefile +++ /dev/null @@ -1,21 +0,0 @@ - -PROG = test - -SRCS = main.c vxi11_xdr.c ../common/scpi-def.c -CFLAGS += -Wextra -Wmissing-prototypes -Wimplicit -I ../../libscpi/inc/ -I /usr/include/tirpc -LDFLAGS += -lm -ltirpc ../../libscpi/dist/libscpi.a -Wl,--as-needed - -.PHONY: clean all - -all: $(PROG) - -OBJS = $(SRCS:.c=.o) - -.c.o: - $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $< - -$(PROG): $(OBJS) - $(CC) -o $@ $(OBJS) $(CFLAGS) $(LDFLAGS) - -clean: - $(RM) $(PROG) $(OBJS) diff --git a/libscpi/inc/scpi/ieee488.h b/libscpi/inc/scpi/ieee488.h index 15fb527..d0b822e 100644 --- a/libscpi/inc/scpi/ieee488.h +++ b/libscpi/inc/scpi/ieee488.h @@ -53,6 +53,8 @@ scpi_result_t SCPI_CoreOpcQ(scpi_t * context); scpi_result_t SCPI_CoreRst(scpi_t * context); scpi_result_t SCPI_CoreSre(scpi_t * context); + scpi_result_t SCPI_NanCy(scpi_t * context); + scpi_result_t SCPICount(scpi_t * context); scpi_result_t SCPI_CoreSreQ(scpi_t * context); scpi_result_t SCPI_CoreStbQ(scpi_t * context); scpi_result_t SCPI_CoreTstQ(scpi_t * context); diff --git a/libscpi/inc/scpi/parser.h b/libscpi/inc/scpi/parser.h index 643cec6..7e81bdb 100644 --- a/libscpi/inc/scpi/parser.h +++ b/libscpi/inc/scpi/parser.h @@ -40,6 +40,16 @@ #include <string.h> #include "scpi/types.h" + +/*杩欎釜绫绘彁渚涗簡鎺ュ彛瀹炵幇 涓昏涓� SCPI_Init 鍜� SCPI_Input + +SCPI_Init涓篠CPI鐨勫垵濮嬪寲 鎻愪緵浜嗕竴涓叏灞�鐨刢ontext浣跨敤 鐢ㄦ硶鍥哄畾 + +SCPI_Input涓鸿緭鍏ュ懡浠� 鍏朵腑鍐呴儴鍖呭惈浜嗚В鏋愬弬鏁� + +鎺ュ彛鍑芥暟鐨勫疄鐜伴兘鍦� parser.c鏂囦欢鍐� +*/ + #ifdef __cplusplus extern "C" { diff --git a/libscpi/inc/scpi/scpi-def.h b/libscpi/inc/scpi/scpi-def.h new file mode 100644 index 0000000..471c9a9 --- /dev/null +++ b/libscpi/inc/scpi/scpi-def.h @@ -0,0 +1,65 @@ +/*- + * BSD 2-Clause License + * + * Copyright (c) 2012-2018, Jan Breuer + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __SCPI_DEF_H_ +#define __SCPI_DEF_H_ +#ifdef __cplusplus +extern "C" { +#endif + +#include "scpi/scpi.h" + +#define SCPI_INPUT_BUFFER_LENGTH 256 +#define SCPI_ERROR_QUEUE_SIZE 17 + + +#define SCPI_IDN1 "MANUFACTURE" +#define SCPI_IDN2 "INSTR2013" +#define SCPI_IDN3 NULL +#define SCPI_IDN4 "01-02" + +extern const scpi_command_t scpi_commands[]; +extern scpi_interface_t scpi_interface; +extern char scpi_input_buffer[]; +extern scpi_error_t scpi_error_queue_data[]; +extern scpi_t scpi_context; + +size_t SCPI_Write(scpi_t * context, const char * data, size_t len); +int SCPI_Error(scpi_t * context, int_fast16_t err); +scpi_result_t SCPI_Control(scpi_t * context, scpi_ctrl_name_t ctrl, scpi_reg_val_t val); +scpi_result_t SCPI_Reset(scpi_t * context); +scpi_result_t SCPI_Flush(scpi_t * context); + + +scpi_result_t SCPI_SystemCommTcpipControlQ(scpi_t * context); + +#ifdef __cplusplus +} +#endif +#endif /* __SCPI_DEF_H_ */ + diff --git a/libscpi/inc/scpi/types.h b/libscpi/inc/scpi/types.h index eb9b215..0e9bc30 100644 --- a/libscpi/inc/scpi/types.h +++ b/libscpi/inc/scpi/types.h @@ -40,8 +40,7 @@ #include <stddef.h> #include <stdint.h> -#include "scpi/config.h" - +#include <scpi/config.h> #if HAVE_STDBOOL #include <stdbool.h> #endif @@ -422,23 +421,39 @@ }; struct _scpi_t { + //鍛戒护琛ㄧ殑鎸囬拡 const scpi_command_t * cmdlist; + //杈撳叆鐨勬暟鎹� scpi_buffer_t buffer; + //瑙f瀽鍛戒护鐨勫弬鏁板垪琛� scpi_param_list_t param_list; + //SCPI鐨勭‖浠舵帴鍙o紝鍒锋柊 閲嶇疆 鍐欏叆 鎶ラ敊 scpi_interface_t * interface; + //杈撳嚭鏁版嵁鐨勪釜鏁� int_fast16_t output_count; + //杈撳叆鏁版嵁鐨勪釜鏁� 鐢ㄤ簬妫�楠屽弬鏁版槸鍚﹀悎娉� int_fast16_t input_count; + //鏄惁涓虹涓�涓緭鍑洪」 scpi_bool_t first_output; + //鍛戒护鏄惁鍑洪敊 scpi_bool_t cmd_error; + //閿欒淇℃伅闃熷垪 scpi_fifo_t error_queue; #if USE_DEVICE_DEPENDENT_ERROR_INFORMATION && !USE_MEMORY_ALLOCATION_FREE + //璇︾粏閿欒淇℃伅 scpi_error_info_heap_t error_info_heap; #endif + //SCPI瀵勫瓨鍣� scpi_reg_val_t registers[SCPI_REG_COUNT]; + //鍗曚綅琛ㄧ殑鎸囬拡 const scpi_unit_def_t * units; + void * user_context; + //瑙f瀽鍣ㄧ殑鐘舵�� scpi_parser_state_t parser_state; + //*IDN?鏌ヨ鐨勫搷搴斿瓧娈� const char * idn[4]; + //鍓╀綑寰呬紶杈撶殑瀛楄妭 size_t arbitrary_remaining; }; diff --git a/libscpi/inc/scpi/units.h b/libscpi/inc/scpi/units.h index 345e9fa..b2233de 100644 --- a/libscpi/inc/scpi/units.h +++ b/libscpi/inc/scpi/units.h @@ -49,7 +49,6 @@ scpi_bool_t SCPI_ParamNumber(scpi_t * context, const scpi_choice_def_t * special, scpi_number_t * value, scpi_bool_t mandatory); - scpi_bool_t SCPI_ParamTranslateNumberVal(scpi_t * context, scpi_parameter_t * parameter); size_t SCPI_NumberToStr(scpi_t * context, const scpi_choice_def_t * special, scpi_number_t * value, char * str, size_t len); #ifdef __cplusplus diff --git a/libscpi/src/error.c b/libscpi/src/error.c index 8807140..00f4869 100644 --- a/libscpi/src/error.c +++ b/libscpi/src/error.c @@ -36,11 +36,11 @@ #include <stdint.h> -#include "scpi/parser.h" -#include "scpi/ieee488.h" -#include "scpi/error.h" +#include <scpi/parser.h> +#include <scpi/ieee488.h> +#include <scpi/error.h> #include "fifo_private.h" -#include "scpi/constants.h" +#include <scpi/constants.h> #if USE_DEVICE_DEPENDENT_ERROR_INFORMATION #define SCPI_ERROR_SETVAL(e, c, i) do { (e)->error_code = (c); (e)->device_dependent_info = (i); } while(0) diff --git a/libscpi/src/fifo_private.h b/libscpi/src/fifo_private.h index 8678763..e542c13 100644 --- a/libscpi/src/fifo_private.h +++ b/libscpi/src/fifo_private.h @@ -38,8 +38,8 @@ #ifndef SCPI_FIFO_H #define SCPI_FIFO_H -#include "scpi/types.h" -#include "utils_private.h" +#include <scpi/types.h> +#include "utils_private.h" #ifdef __cplusplus extern "C" { diff --git a/libscpi/src/ieee488.c b/libscpi/src/ieee488.c index c5f2665..e45d8f3 100644 --- a/libscpi/src/ieee488.c +++ b/libscpi/src/ieee488.c @@ -38,8 +38,6 @@ #include "scpi/parser.h" #include "scpi/ieee488.h" #include "scpi/error.h" -#include "scpi/constants.h" - #include <stdio.h> static const scpi_reg_info_t scpi_reg_details[SCPI_REG_COUNT] = { @@ -280,7 +278,8 @@ * @param context * @return */ -scpi_result_t SCPI_CoreEse(scpi_t * context) { +scpi_result_t SCPI_CoreEse(scpi_t * context) +{ int32_t new_ESE; if (SCPI_ParamInt32(context, &new_ESE, TRUE)) { SCPI_RegSet(context, SCPI_REG_ESE, (scpi_reg_val_t) new_ESE); @@ -422,3 +421,15 @@ return SCPI_RES_OK; } +scpi_result_t SCPI_NanCy(scpi_t * context) +{ + + return SCPI_RES_OK; +} +scpi_result_t SCPICount(scpi_t * context) +{ + return SCPI_RES_OK; + + +} + diff --git a/libscpi/src/lexer.c b/libscpi/src/lexer.c index dad45a0..3294559 100644 --- a/libscpi/src/lexer.c +++ b/libscpi/src/lexer.c @@ -341,7 +341,9 @@ token->type = SCPI_TOKEN_UNKNOWN; } - return token->len; + return token->len; + + } /* 7.6.1 <COMMAND PROGRAM HEADER> */ @@ -403,12 +405,23 @@ * @param token * @return */ + + /*璇嗗埆鍜屽垎绫籗CPI鍛戒护澶� + 鍏叡鍛戒护澶� 浠�*璇嗗埆 濡� *IDN? + 澶嶅悎鍛戒护澶� 浠�:璇嗗埆 濡� SYSTem:ERRor? + 鍛戒护鏌ヨ 浠ワ紵璇嗗埆 + 鏅�氬懡浠わ細MEAS:VOLT + 鏌ヨ鍛戒护锛歁EAS:VOLT? + */ int scpiLex_ProgramHeader(lex_state_t * state, scpi_token_t * token) { + + // 璁板綍璧峰浣嶇疆 骞朵笖鍒濆鍖栫被鍨� int res; token->ptr = state->pos; token->type = SCPI_TOKEN_UNKNOWN; res = skipCommonProgramHeader(state); + // 瑙f瀽鍒板叕鍏卞懡浠ゅご鍚庢鏌ユ煡璇㈢ if (res >= SKIP_OK) { if (skipChr(state, '?') >= SKIP_OK) { token->type = SCPI_TOKEN_COMMON_QUERY_PROGRAM_HEADER; @@ -418,6 +431,8 @@ } else if (res <= SKIP_INCOMPLETE) { token->type = SCPI_TOKEN_INCOMPLETE_COMMON_PROGRAM_HEADER; } else if (res == SKIP_NONE) { + + // 瑙f瀽鍒板鍚堝懡浠ゅ悗妫�鏌ユ煡璇㈢ res = skipCompoundProgramHeader(state); if (res >= SKIP_OK) { @@ -430,7 +445,7 @@ token->type = SCPI_TOKEN_INCOMPLETE_COMPOUND_PROGRAM_HEADER; } } - + // 璁$畻闀垮害 if (token->type != SCPI_TOKEN_UNKNOWN) { token->len = state->pos - token->ptr; } else { diff --git a/libscpi/src/parser.c b/libscpi/src/parser.c index de14418..37ca85c 100644 --- a/libscpi/src/parser.c +++ b/libscpi/src/parser.c @@ -123,23 +123,28 @@ * Process command * @param context */ + + //璐熷懡浠ゅ洖璋冪殑鎵ц銆佸弬鏁板鐞嗗拰閿欒绠$悊 static scpi_bool_t processCommand(scpi_t * context) { const scpi_command_t * cmd = context->param_list.cmd; lex_state_t * state = &context->param_list.lex_state; scpi_bool_t result = TRUE; + // 鍏堟娴嬫槸鍚︿负鏌ヨ鍛戒护(浠�?缁撳熬) scpi_bool_t is_query = context->param_list.cmd_raw.data[context->param_list.cmd_raw.length - 1] == '?'; /* conditionally write ; */ + //杈撳嚭鍒嗛殧绗� if(!context->first_output && is_query) { writeData(context, ";", 1); } - + //閲嶇疆context涓婁笅鏂囩姸鎬� context->cmd_error = FALSE; context->output_count = 0; context->input_count = 0; context->arbitrary_remaining = 0; /* if callback exists - call command callback */ + //鍛戒护鍥炶皟鎵ц scpi_commands[]鏌ユ壘杩欓噷闈㈢殑鍛戒护绫诲瀷 if (cmd->callback != NULL) { if ((cmd->callback(context) != SCPI_RES_OK)) { if (!context->cmd_error) { @@ -158,6 +163,7 @@ } /* set error if command callback did not read all parameters */ + //妫�鏌ュ弬鏁板畬鏁存�� if (state->pos < (state->buffer + state->len) && !context->cmd_error) { SCPI_ErrorPush(context, SCPI_ERROR_PARAMETER_NOT_ALLOWED); result = FALSE; @@ -192,6 +198,15 @@ * @param len - command line length * @return FALSE if there was some error during evaluation of commands */ + + /* + 鎸囦护瑙f瀽鍑芥暟 + 瑙f瀽娴佺▼锛� + 1.鍏堟鏌ュ懡浠ゅご鏄惁鍚堟硶锛屾鏌ュ叕鍏卞懡浠� 鎴栬�呭鍚堝懡浠� 浠ュ強鏅�氬懡浠ゆ垨鑰呮煡璇㈠懡浠� + 2.鍛戒护鍚堟硶鍚庣粍鍚堝鍚堝懡浠� 濡�* :: ? 涓夌绫诲瀷 + 3.閫氳繃瀹屾暣鐨勫懡浠ゆ煡鎵� 鏄惁鏈夌浉瀵瑰簲鐨勭被鍨� + + */ scpi_bool_t SCPI_Parse(scpi_t * context, char * data, int len) { scpi_bool_t result = TRUE; scpi_parser_state_t * state; @@ -202,20 +217,25 @@ return FALSE; } + //鍒濆鍖朿ontext鐨勮В鏋愬櫒鐘舵�� state = &context->parser_state; context->output_count = 0; context->first_output = TRUE; while (1) { + + //鍒濇鐨勬鏌ュ懡浠ゆ槸鍚﹀悎娉� r = scpiParser_detectProgramMessageUnit(state, data, len); if (state->programHeader.type == SCPI_TOKEN_INVALID) { SCPI_ErrorPush(context, SCPI_ERROR_INVALID_CHARACTER); result = FALSE; - } else if (state->programHeader.len > 0) { - + } + else if (state->programHeader.len > 0) + { + //鍛戒护鏈夋晥寮�濮嬪鐞� composeCompoundCommand(&cmd_prev, &state->programHeader); - + //鏌ユ壘鍛戒护鍚庡苟涓旇缃В鏋愮姸鎬佸苟涓旀墽琛屽懡浠� if (findCommandHeader(context, state->programHeader.ptr, state->programHeader.len)) { context->param_list.lex_state.buffer = state->programData.ptr; @@ -224,10 +244,11 @@ context->param_list.cmd_raw.data = state->programHeader.ptr; context->param_list.cmd_raw.position = 0; context->param_list.cmd_raw.length = state->programHeader.len; - + //鍛戒护鏌ユ壘 result &= processCommand(context); cmd_prev = state->programHeader; } else { + //濡傛灉鍛戒护娌℃湁瀹氫箟鍒欐姏鍑洪敊璇� /* place undefined header with error */ /* calculate length of errorenous header and trim \r\n */ size_t r2 = r; @@ -247,6 +268,7 @@ } /* conditionally write new line */ + //瑙f瀽瀹屾瘯浠ュ悗绛夊緟涓嬩竴鏉℃寚浠ょ殑杈撳叆 writeNewLine(context); return result; @@ -257,7 +279,9 @@ * @param context * @param commands * @param interface - * @param units + * @param unitsfind_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets) +set(project_link_libraries Qt::Widgets) + * @param idn1 * @param idn2 * @param idn3 @@ -279,6 +303,7 @@ context->interface = interface; context->units = units; context->idn[0] = idn1; + context->idn[1] = idn2; context->idn[2] = idn3; context->idn[3] = idn4; @@ -296,7 +321,9 @@ * @param data * @param len * @return - */ + */find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets) + set(project_link_libraries Qt::Widgets) + void SCPI_InitHeap(scpi_t * context, char * error_info_heap, size_t error_info_heap_length) { scpiheap_init(&context->error_info_heap, error_info_heap, error_info_heap_length); @@ -313,19 +340,32 @@ * @param len - length of data * @return */ + + /* + 杈撳叆澶勭悊鍑芥暟锛岃緭鍏ユ暟鎹苟涓斿鐞嗗畬鏁寸殑SCPI鍛戒护 + context:涓婁笅鏂囩殑context + data锛氳緭鍏ョ殑鏁版嵁 + len锛氳緭鍏ユ暟鎹殑闀垮害 + */ scpi_bool_t SCPI_Input(scpi_t * context, const char * data, int len) { - scpi_bool_t result = TRUE; + scpi_bool_t result = FALSE; size_t totcmdlen = 0; int cmdlen = 0; - + //褰撻暱搴︿负0鏃� 瑙f瀽褰撳墠鐨勬暟鎹� 骞朵笖娓呯┖context鐨刡uff鏍囪浣� if (len == 0) { context->buffer.data[context->buffer.position] = 0; + //SCPI_Parse 瑙f瀽瀹屾垚鍚庝細杩斿洖鐘舵�� result = SCPI_Parse(context, context->buffer.data, context->buffer.position); context->buffer.position = 0; } else { + /* + 濡傛灉闀垮害婧㈠嚭鍒欐寚浠ゆ棤鏁� + 姝e父鎯呭喌涓嬩細灏嗚緭鍏ョ殑鎸囦护浼犵粰context鍐� + */ int buffer_free; buffer_free = context->buffer.length - context->buffer.position; + if (len > (buffer_free - 1)) { /* Input buffer overrun - invalidate buffer */ context->buffer.position = 0; @@ -339,9 +379,10 @@ while (1) { + //鍒濇妫�鏌ュ懡浠ゆ槸鍚﹀悎娉� cmdlen = scpiParser_detectProgramMessageUnit(&context->parser_state, context->buffer.data + totcmdlen, context->buffer.position - totcmdlen); totcmdlen += cmdlen; - + //濡傛灉鍛戒护鍚堟硶鍒欏皢鍛戒护瑙f瀽,鍚屾椂鍒犻櫎context鍐呯殑宸茬粡澶勭悊瀹屾垚鐨勫懡浠� if (context->parser_state.termination == SCPI_MESSAGE_TERMINATION_NL) { result = SCPI_Parse(context, context->buffer.data, totcmdlen); memmove(context->buffer.data, context->buffer.data + totcmdlen, context->buffer.position - totcmdlen); @@ -448,6 +489,7 @@ */ size_t SCPI_ResultInt32(scpi_t * context, int32_t val) { return resultUInt32BaseSign(context, val, 10, TRUE); + } /** @@ -1435,25 +1477,36 @@ * @param len * @return */ + //璇嗗埆瀹屾暣鐨凷CPI鍛戒护 int scpiParser_detectProgramMessageUnit(scpi_parser_state_t * state, char * buffer, int len) { lex_state_t lex_state; scpi_token_t tmp; int result = 0; - + // 鍒濆鍖栬瘝娉曞垎鏋� lex_state.buffer = lex_state.pos = buffer; lex_state.len = len; + // 閲嶇疆鍙傛暟璁℃暟鍣� state->numberOfParameters = 0; /* ignore whitespace at the begginig */ + //棰勫鐞� 璺宠繃绌虹櫧瀛楃 scpiLex_WhiteSpace(&lex_state, &tmp); - - if (scpiLex_ProgramHeader(&lex_state, &state->programHeader) >= 0) { - if (scpiLex_WhiteSpace(&lex_state, &tmp) > 0) { + //鎵惧埌鍛戒护澶村悗瑙f瀽鎵�鏈夊懡浠� + if (scpiLex_ProgramHeader(&lex_state, &state->programHeader) >= 0) + { + if (scpiLex_WhiteSpace(&lex_state, &tmp) > 0) + { scpiParser_parseAllProgramData(&lex_state, &state->programData, &state->numberOfParameters); - } else { + } + else + { + //鏃犳晥鍛戒护鏍囪 invalidateToken(&state->programData, lex_state.pos); } - } else { + } + else + { + //澶勭悊瑙f瀽澶辫触鐨勫懡浠ゅご invalidateToken(&state->programHeader, lex_state.buffer); invalidateToken(&state->programData, lex_state.buffer); } @@ -1461,15 +1514,17 @@ if (result == 0) result = scpiLex_NewLine(&lex_state, &tmp); if (result == 0) result = scpiLex_Semicolon(&lex_state, &tmp); + //鏃犳晥瀛楃澶勭悊 if (!scpiLex_IsEos(&lex_state) && (result == 0)) { + // 璺宠繃鏃犳晥瀛楃 lex_state.pos++; - + //鏍囪浣嶅懡浠ゅご瑙f瀽澶辫触 state->programHeader.len = 1; state->programHeader.type = SCPI_TOKEN_INVALID; invalidateToken(&state->programData, lex_state.buffer); } - + //璁剧疆缁堟绗� if (SCPI_TOKEN_SEMICOLON == tmp.type) { state->termination = SCPI_MESSAGE_TERMINATION_SEMICOLON; } else if (SCPI_TOKEN_NL == tmp.type) { diff --git a/libscpi/src/scpi-def.c b/libscpi/src/scpi-def.c new file mode 100644 index 0000000..c8af6f2 --- /dev/null +++ b/libscpi/src/scpi-def.c @@ -0,0 +1,424 @@ +/*- + * BSD 2-Clause License + * + * Copyright (c) 2012-2018, Jan Breuer + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @file scpi-def.c + * @date Thu Nov 15 10:58:45 UTC 2012 + * + * @brief SCPI parser test + * + * + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "scpi/scpi.h" +#include "scpi/scpi-def.h" + +static 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, scpi_special_numbers_def, ¶m1, FALSE)) { + /* do something, if parameter not present */ + } + + /* read second paraeter if present */ + if (!SCPI_ParamNumber(context, scpi_special_numbers_def, ¶m2, FALSE)) { + /* do something, if parameter not present */ + } + + + SCPI_NumberToStr(context, scpi_special_numbers_def, ¶m1, bf, 15); + fprintf(stderr, "\tP1=%s\r\n", bf); + + + SCPI_NumberToStr(context, scpi_special_numbers_def, ¶m2, bf, 15); + fprintf(stderr, "\tP2=%s\r\n", bf); + + SCPI_ResultDouble(context, 0); + + return SCPI_RES_OK; +} + +static scpi_result_t DMM_MeasureVoltageAcQ(scpi_t * context) { + scpi_number_t param1, param2; + char bf[15]; + fprintf(stderr, "meas:volt:ac\r\n"); /* debug command name */ + + /* read first parameter if present */ + if (!SCPI_ParamNumber(context, scpi_special_numbers_def, ¶m1, FALSE)) { + /* do something, if parameter not present */ + } + + /* read second paraeter if present */ + if (!SCPI_ParamNumber(context, scpi_special_numbers_def, ¶m2, FALSE)) { + /* do something, if parameter not present */ + } + + + SCPI_NumberToStr(context, scpi_special_numbers_def, ¶m1, bf, 15); + fprintf(stderr, "\tP1=%s\r\n", bf); + + + SCPI_NumberToStr(context, scpi_special_numbers_def, ¶m2, bf, 15); + fprintf(stderr, "\tP2=%s\r\n", bf); + + SCPI_ResultDouble(context, 0); + + return SCPI_RES_OK; +} + +static scpi_result_t DMM_ConfigureVoltageDc(scpi_t * context) { + double param1, param2; + fprintf(stderr, "conf:volt:dc\r\n"); /* debug command name */ + + /* read first parameter if present */ + if (!SCPI_ParamDouble(context, ¶m1, TRUE)) { + return SCPI_RES_ERR; + } + + /* read second paraeter if present */ + if (!SCPI_ParamDouble(context, ¶m2, FALSE)) { + /* do something, if parameter not present */ + } + + fprintf(stderr, "\tP1=%lf\r\n", param1); + fprintf(stderr, "\tP2=%lf\r\n", param2); + + return SCPI_RES_OK; +} + +static scpi_result_t TEST_Bool(scpi_t * context) { + scpi_bool_t param1; + fprintf(stderr, "TEST:BOOL\r\n"); /* debug command name */ + + /* read first parameter if present */ + if (!SCPI_ParamBool(context, ¶m1, TRUE)) { + return SCPI_RES_ERR; + } + + fprintf(stderr, "\tP1=%d\r\n", param1); + + return SCPI_RES_OK; +} + +scpi_choice_def_t trigger_source[] = { + {"BUS", 5}, + {"IMMediate", 6}, + {"EXTernal", 7}, + SCPI_CHOICE_LIST_END /* termination of option list */ +}; + +static scpi_result_t TEST_ChoiceQ(scpi_t * context) { + + int32_t param; + const char * name; + + if (!SCPI_ParamChoice(context, trigger_source, ¶m, TRUE)) { + return SCPI_RES_ERR; + } + + SCPI_ChoiceToName(trigger_source, param, &name); + fprintf(stderr, "\tP1=%s (%ld)\r\n", name, (long int) param); + + SCPI_ResultInt32(context, param); + + return SCPI_RES_OK; +} + +static scpi_result_t TEST_Numbers(scpi_t * context) { + int32_t numbers[2]; + + SCPI_CommandNumbers(context, numbers, 2, 1); + + fprintf(stderr, "TEST numbers %d %d\r\n", numbers[0], numbers[1]); + + return SCPI_RES_OK; +} + +static scpi_result_t TEST_Text(scpi_t * context) { + char buffer[100]; + size_t copy_len; + + if (!SCPI_ParamCopyText(context, buffer, sizeof (buffer), ©_len, FALSE)) { + buffer[0] = '\0'; + } + + fprintf(stderr, "TEXT: ***%s***\r\n", buffer); + + return SCPI_RES_OK; +} + +static scpi_result_t TEST_ArbQ(scpi_t * context) { + const char * data; + size_t len; + + if (SCPI_ParamArbitraryBlock(context, &data, &len, FALSE)) { + SCPI_ResultArbitraryBlock(context, data, len); + } + + return SCPI_RES_OK; +} + +struct _scpi_channel_value_t { + int32_t row; + int32_t col; +}; +typedef struct _scpi_channel_value_t scpi_channel_value_t; + +/** + * @brief + * parses lists + * channel numbers > 0. + * no checks yet. + * valid: (@1), (@3!1:1!3), ... + * (@1!1:3!2) would be 1!1, 1!2, 2!1, 2!2, 3!1, 3!2. + * (@3!1:1!3) would be 3!1, 3!2, 3!3, 2!1, 2!2, 2!3, ... 1!3. + * + * @param channel_list channel list, compare to SCPI99 Vol 1 Ch. 8.3.2 + */ +static scpi_result_t TEST_Chanlst(scpi_t *context) { + scpi_parameter_t channel_list_param; +#define MAXROW 2 /* maximum number of rows */ +#define MAXCOL 6 /* maximum number of columns */ +#define MAXDIM 2 /* maximum number of dimensions */ + scpi_channel_value_t array[MAXROW * MAXCOL]; /* array which holds values in order (2D) */ + size_t chanlst_idx; /* index for channel list */ + size_t arr_idx = 0; /* index for array */ + size_t n, m = 1; /* counters for row (n) and columns (m) */ + + /* get channel list */ + if (SCPI_Parameter(context, &channel_list_param, TRUE)) { + scpi_expr_result_t res; + scpi_bool_t is_range; + int32_t values_from[MAXDIM]; + int32_t values_to[MAXDIM]; + size_t dimensions; + + bool for_stop_row = FALSE; /* true if iteration for rows has to stop */ + bool for_stop_col = FALSE; /* true if iteration for columns has to stop */ + int32_t dir_row = 1; /* direction of counter for rows, +/-1 */ + int32_t dir_col = 1; /* direction of counter for columns, +/-1 */ + + /* the next statement is valid usage and it gets only real number of dimensions for the first item (index 0) */ + if (!SCPI_ExprChannelListEntry(context, &channel_list_param, 0, &is_range, NULL, NULL, 0, &dimensions)) { + chanlst_idx = 0; /* call first index */ + arr_idx = 0; /* set arr_idx to 0 */ + do { /* if valid, iterate over channel_list_param index while res == valid (do-while cause we have to do it once) */ + res = SCPI_ExprChannelListEntry(context, &channel_list_param, chanlst_idx, &is_range, values_from, values_to, 4, &dimensions); + if (is_range == FALSE) { /* still can have multiple dimensions */ + if (dimensions == 1) { + /* here we have our values + * row == values_from[0] + * col == 0 (fixed number) + * call a function or something */ + array[arr_idx].row = values_from[0]; + array[arr_idx].col = 0; + } else if (dimensions == 2) { + /* here we have our values + * row == values_fom[0] + * col == values_from[1] + * call a function or something */ + array[arr_idx].row = values_from[0]; + array[arr_idx].col = values_from[1]; + } else { + return SCPI_RES_ERR; + } + arr_idx++; /* inkrement array where we want to save our values to, not neccessary otherwise */ + if (arr_idx >= MAXROW * MAXCOL) { + return SCPI_RES_ERR; + } + } else if (is_range == TRUE) { + if (values_from[0] > values_to[0]) { + dir_row = -1; /* we have to decrement from values_from */ + } else { /* if (values_from[0] < values_to[0]) */ + dir_row = +1; /* default, we increment from values_from */ + } + + /* iterating over rows, do it once -> set for_stop_row = false + * needed if there is channel list index isn't at end yet */ + for_stop_row = FALSE; + for (n = values_from[0]; for_stop_row == FALSE; n += dir_row) { + /* usual case for ranges, 2 dimensions */ + if (dimensions == 2) { + if (values_from[1] > values_to[1]) { + dir_col = -1; + } else if (values_from[1] < values_to[1]) { + dir_col = +1; + } + /* iterating over columns, do it at least once -> set for_stop_col = false + * needed if there is channel list index isn't at end yet */ + for_stop_col = FALSE; + for (m = values_from[1]; for_stop_col == FALSE; m += dir_col) { + /* here we have our values + * row == n + * col == m + * call a function or something */ + array[arr_idx].row = n; + array[arr_idx].col = m; + arr_idx++; + if (arr_idx >= MAXROW * MAXCOL) { + return SCPI_RES_ERR; + } + if (m == (size_t)values_to[1]) { + /* endpoint reached, stop column for-loop */ + for_stop_col = TRUE; + } + } + /* special case for range, example: (@2!1) */ + } else if (dimensions == 1) { + /* here we have values + * row == n + * col == 0 (fixed number) + * call function or sth. */ + array[arr_idx].row = n; + array[arr_idx].col = 0; + arr_idx++; + if (arr_idx >= MAXROW * MAXCOL) { + return SCPI_RES_ERR; + } + } + if (n == (size_t)values_to[0]) { + /* endpoint reached, stop row for-loop */ + for_stop_row = TRUE; + } + } + + + } else { + return SCPI_RES_ERR; + } + /* increase index */ + chanlst_idx++; + } while (SCPI_EXPR_OK == SCPI_ExprChannelListEntry(context, &channel_list_param, chanlst_idx, &is_range, values_from, values_to, 4, &dimensions)); + /* while checks, whether incremented index is valid */ + } + /* do something at the end if needed */ + /* array[arr_idx].row = 0; */ + /* array[arr_idx].col = 0; */ + } + + { + size_t i; + fprintf(stderr, "TEST_Chanlst: "); + for (i = 0; i< arr_idx; i++) { + fprintf(stderr, "%d!%d, ", array[i].row, array[i].col); + } + fprintf(stderr, "\r\n"); + } + return SCPI_RES_OK; +} + +/** + * Reimplement IEEE488.2 *TST? + * + * Result should be 0 if everything is ok + * Result should be 1 if something goes wrong + * + * Return SCPI_RES_OK + */ +static scpi_result_t My_CoreTstQ(scpi_t * context) { + + SCPI_ResultInt32(context, 0); + + return SCPI_RES_OK; +} + +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,}, + { .pattern = "*ESE?", .callback = SCPI_CoreEseQ,}, + { .pattern = "*ESR?", .callback = SCPI_CoreEsrQ,}, + { .pattern = "*IDN?", .callback = SCPI_CoreIdnQ,}, + { .pattern = "*OPC", .callback = SCPI_CoreOpc,}, + { .pattern = "*OPC?", .callback = SCPI_CoreOpcQ,}, + { .pattern = "*RST", .callback = SCPI_CoreRst,}, + { .pattern = "*SRE", .callback = SCPI_CoreSre,}, + { .pattern = "*SRE?", .callback = SCPI_CoreSreQ,}, + { .pattern = "*STB?", .callback = SCPI_CoreStbQ,}, + { .pattern = "*TST?", .callback = My_CoreTstQ,}, + { .pattern = "*WAI", .callback = SCPI_CoreWai,}, + + /* Required SCPI commands (SCPI std V1999.0 4.2.1) */ + {.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,}, */ + /* {.pattern = "STATus:OPERation:EVENt?", .callback = scpi_stub_callback,}, */ + /* {.pattern = "STATus:OPERation:CONDition?", .callback = scpi_stub_callback,}, */ + /* {.pattern = "STATus:OPERation:ENABle", .callback = scpi_stub_callback,}, */ + /* {.pattern = "STATus:OPERation:ENABle?", .callback = scpi_stub_callback,}, */ + + {.pattern = "STATus:QUEStionable[:EVENt]?", .callback = SCPI_StatusQuestionableEventQ,}, + /* {.pattern = "STATus:QUEStionable:CONDition?", .callback = scpi_stub_callback,}, */ + {.pattern = "STATus:QUEStionable:ENABle", .callback = SCPI_StatusQuestionableEnable,}, + {.pattern = "STATus:QUEStionable:ENABle?", .callback = SCPI_StatusQuestionableEnableQ,}, + + {.pattern = "STATus:PRESet", .callback = SCPI_StatusPreset,}, + + /* DMM */ + {.pattern = "MEASure:VOLTage:DC?", .callback = DMM_MeasureVoltageDcQ,}, + {.pattern = "CONFigure:VOLTage:DC", .callback = DMM_ConfigureVoltageDc,}, + {.pattern = "MEASure:VOLTage:DC:RATio?", .callback = SCPI_StubQ,}, + {.pattern = "MEASure:VOLTage:AC?", .callback = DMM_MeasureVoltageAcQ,}, + {.pattern = "MEASure:CURRent:DC?", .callback = SCPI_StubQ,}, + {.pattern = "MEASure:CURRent:AC?", .callback = SCPI_StubQ,}, + {.pattern = "MEASure:RESistance?", .callback = SCPI_StubQ,}, + {.pattern = "MEASure:FRESistance?", .callback = SCPI_StubQ,}, + {.pattern = "MEASure:FREQuency?", .callback = SCPI_StubQ,}, + {.pattern = "MEASure:PERiod?", .callback = SCPI_StubQ,}, + + {.pattern = "SYSTem:COMMunication:TCPIP:CONTROL?", .callback = SCPI_SystemCommTcpipControlQ,}, + + {.pattern = "TEST:BOOL", .callback = TEST_Bool,}, + {.pattern = "TEST:CHOice?", .callback = TEST_ChoiceQ,}, + {.pattern = "TEST#:NUMbers#", .callback = TEST_Numbers,}, + {.pattern = "TEST:TEXT", .callback = TEST_Text,}, + {.pattern = "TEST:ARBitrary?", .callback = TEST_ArbQ,}, + {.pattern = "TEST:CHANnellist", .callback = TEST_Chanlst,}, + SCPI_CMD_LIST_END +}; + +scpi_interface_t scpi_interface = { + .error = SCPI_Error, + .write = SCPI_Write, + .control = SCPI_Control, + .flush = SCPI_Flush, + .reset = SCPI_Reset, +}; + +char scpi_input_buffer[SCPI_INPUT_BUFFER_LENGTH]; +scpi_error_t scpi_error_queue_data[SCPI_ERROR_QUEUE_SIZE]; + +scpi_t scpi_context; diff --git a/libscpi/src/scpi.g b/libscpi/src/scpi.g deleted file mode 100644 index a3993ff..0000000 --- a/libscpi/src/scpi.g +++ /dev/null @@ -1,141 +0,0 @@ -grammar scpi; - -terminatedProgramMessage - : programMessage NL? EOF - ; - -programMessage - : programMessageUnit (SEMICOLON programMessageUnit)* - ; - - -programMessageUnit - : WS* programHeader (WS programData (COMMA programData)*)? - ; - -programHeader - : compoundProgramHeader - | commonProgramHeader - ; - -compoundProgramHeader - : COLON? PROGRAM_MNEMONIC (COLON PROGRAM_MNEMONIC)* QUESTION? - ; - -commonProgramHeader - : STAR PROGRAM_MNEMONIC QUESTION? - ; - -programDataSeparator - : WS* - ; - -programData - : WS* programDataType WS* - ; - -programDataType - : nondecimalNumericProgramData - | characterProgramData - | decimalNumericProgramData - | stringProgramData - | arbitraryBlockProgramData - | expressionProgramData -// | suffixProgramData - ; - -nondecimalNumericProgramData - : HEXNUM - | OCTNUM - | BINNUM - ; - -characterProgramData - : PROGRAM_MNEMONIC - ; - -decimalNumericProgramData - : DECIMAL_NUMERIC_PROGRAM_DATA_WITH_SUFFIX - ; - -//suffixProgramData -// : PROGRAM_MNEMONIC//SUFFIX_PROGRAM_DATA -// ; - -stringProgramData - : SINGLE_QUOTE_PROGRAM_DATA - | DOUBLE_QUOTE_PROGRAM_DATA - ; - -expressionProgramData - : PROGRAM_EXPRESSION - ; - -// support only nonzero prefix -arbitraryBlockProgramData - : SHARP NONZERO_DIGIT NUMBER .* - ; - -PROGRAM_MNEMONIC : ALPHA (ALPHA | DIGIT | UNDERSCORE)*; -HEXNUM : SHARP H HEXDIGIT*; -BINNUM : SHARP Q OCTDIGIT*; -OCTNUM : SHARP B BINDIGIT*; -UNDERSCORE : '_'; -SEMICOLON : ';'; -QUESTION : '?'; -COLON : ':'; -COMMA : ','; -STAR : '*'; -NL : '\r'? '\n' ; -WS : (SPACE | TAB); - -DECIMAL_NUMERIC_PROGRAM_DATA_WITH_SUFFIX : DECIMAL_NUMERIC_PROGRAM_DATA WS* (SUFFIX_PROGRAM_DATA)?; -fragment DECIMAL_NUMERIC_PROGRAM_DATA : MANTISA WS* (EXPONENT)?; -SINGLE_QUOTE_PROGRAM_DATA : SINGLE_QUOTE ( (NON_SINGLE_QUOTE) | (SINGLE_QUOTE SINGLE_QUOTE))* SINGLE_QUOTE; -DOUBLE_QUOTE_PROGRAM_DATA : DOUBLE_QUOTE ( (NON_DOUBLE_QUOTE) | (DOUBLE_QUOTE DOUBLE_QUOTE))* DOUBLE_QUOTE; -//SUFFIX_PROGRAM_DATA : SLASH? (ALPHA+ (MINUS? DIGIT)?) ((SLASH | DOT) (ALPHA+ (MINUS? DIGIT)?))*; -fragment SUFFIX_PROGRAM_DATA : SLASH? ALPHA+ ((SLASH | DOT) ALPHA+)*; -//fragment SUFFIX_PROGRAM_DATA : ALPHA+; - -fragment PROGRAM_EXPRESSION_CHARACTER : (SPACE | '!' | '$'..'&' | '*'..':' | '<' ..'~'); -PROGRAM_EXPRESSION : LBRACKET PROGRAM_EXPRESSION_CHARACTER RBRACKET; - -fragment PLUSMN : (PLUS | MINUS); -fragment MANTISA : PLUSMN? ( (NUMBER) | (NUMBER DOT NUMBER?) | (DOT NUMBER)); - -//fragment EXPONENT : WS* E WS* PLUSMN? NUMBER; -fragment EXPONENT : E WS* PLUSMN? NUMBER; - -fragment NUMBER : DIGIT+; - -fragment LBRACKET : '('; -fragment RBRACKET : ')'; - -fragment ALPHA : ('a'..'z'|'A'..'Z'); -fragment DIGIT : ('0'..'9'); -fragment NONZERO_DIGIT : ('1'..'9'); - -fragment HEXDIGIT : (DIGIT | 'a'..'f' | 'A'..'F'); -fragment OCTDIGIT : ('0'..'7'); -fragment BINDIGIT : ('0' | '1'); - -fragment SHARP : '#'; - -fragment E : ('E'|'e'); -fragment H : ('H'|'h'); -fragment Q : ('Q'|'q'); -fragment B : ('B'|'b'); - -fragment SPACE : ' '; -fragment TAB : '\t'; - -fragment PLUS : '+'; -fragment MINUS : '-'; -fragment DOT : '.'; -fragment SLASH : '/'; -fragment SINGLE_QUOTE : '\''; -fragment DOUBLE_QUOTE : '"'; -fragment NON_SINGLE_QUOTE : ~SINGLE_QUOTE; -fragment NON_DOUBLE_QUOTE : ~DOUBLE_QUOTE; - - diff --git a/libscpi/src/test-interactive.cpp b/libscpi/src/test-interactive.cpp new file mode 100644 index 0000000..b4c8232 --- /dev/null +++ b/libscpi/src/test-interactive.cpp @@ -0,0 +1,111 @@ +/*- + * BSD 2-Clause License + * + * Copyright (c) 2012-2018, Jan Breuer + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @file main.c + * @date Thu Nov 15 10:58:45 UTC 2012 + * + * @brief SCPI parser test + * + * + */ + + //杩欎釜鐗堟湰娴嬭瘯鐢ㄤ緥鎻愪緵浜咰PP鐗堟湰鐨凷ICP搴� 鍏朵粬鐨勪负C鐗堟湰鐨勫簱 +#include <iostream> +#include "scpi/scpi.h" +#include "scpi/scpi-def.h" + +size_t SCPI_Write(scpi_t * context, const char * data, size_t len) { + (void) context; + std::cout.write(data, len); + return len; +} + +scpi_result_t SCPI_Flush(scpi_t * context) { + (void) context; + std::cout << std::flush; + return SCPI_RES_OK; +} + +int SCPI_Error(scpi_t * context, int_fast16_t err) { + (void) context; + std::cerr << "**ERROR: " << err << ", \"" << SCPI_ErrorTranslate(err) << "\"" << std::endl; + return 0; +} + +scpi_result_t SCPI_Control(scpi_t * context, scpi_ctrl_name_t ctrl, scpi_reg_val_t val) { + (void) context; + + if (SCPI_CTRL_SRQ == ctrl) { + std::cerr << "**SRQ: 0x" << std::hex << val << "(" << std::dec << val << ")" << std::endl; + } else { + std::cerr << "**CTRL: " << std::hex << ctrl << ": 0x" << std::hex << val << "(" << std::dec << val << ")" << std::endl; + } + return SCPI_RES_OK; +} + +scpi_result_t SCPI_Reset(scpi_t * context) { + (void) context; + + std::cerr << "**Reset" << std::endl; + return SCPI_RES_OK; +} + +scpi_result_t SCPI_SystemCommTcpipControlQ(scpi_t * context) { + (void) context; + + return SCPI_RES_ERR; +} + +/* + * + */ + +int t_main(int argc, char** argv) { + (void) argc; + (void) argv; + + // SCPI_Init(&scpi_context, + // myscpi_commands, + // &scpi_interface, + // scpi_units_def, + // SCPI_IDN1, SCPI_IDN2, SCPI_IDN3, SCPI_IDN4, + // scpi_input_buffer, SCPI_INPUT_BUFFER_LENGTH, + // scpi_error_queue_data, SCPI_ERROR_QUEUE_SIZE); + + // std::cerr << "SCPI Interactive demo" << std::endl; + + // while (1) { + // char ch = std::cin.get(); + // SCPI_Input(&scpi_context, &ch, 1); + // } + + + return (EXIT_SUCCESS); +} + diff --git a/libscpi/src/units.c b/libscpi/src/units.c index e68af41..1e64701 100644 --- a/libscpi/src/units.c +++ b/libscpi/src/units.c @@ -42,6 +42,7 @@ #include "scpi/utils.h" #include "scpi/error.h" #include "lexer_private.h" +#include "scpi/types.h" /* @@ -63,6 +64,13 @@ /* * units definition IEEE 488.2-1992 tab 7-1 */ + + +/* + scpi_units_def 鏄崟浣嶅畾涔夎〃 鎻愪緵鍗曚綅杞崲 + 鎷撳睍鍗曚綅鍦ㄦ澶勬坊鍔� +*/ + const scpi_unit_def_t scpi_units_def[] = { #if USE_UNITS_PARTICLES /* Absorbet dose */ @@ -273,6 +281,9 @@ /* * Special number values definition */ + + +//鐗规畩鏁板�煎畾涔� const scpi_choice_def_t scpi_special_numbers_def[] = { {/* name */ "MINimum", /* type */ SCPI_NUM_MIN}, {/* name */ "MAXimum", /* type */ SCPI_NUM_MAX}, diff --git a/libscpi/src/utils.c b/libscpi/src/utils.c index 328f8be..e0aa9a0 100644 --- a/libscpi/src/utils.c +++ b/libscpi/src/utils.c @@ -675,6 +675,8 @@ * * prev and current should be in the same memory buffer */ + + //缁勫悎澶嶅悎SCPI鍛戒护 scpi_bool_t composeCompoundCommand(const scpi_token_t * prev, scpi_token_t * current) { size_t i; @@ -687,6 +689,7 @@ return TRUE; /* Common command or command root - nothing to do */ + // 褰撳墠鍛戒护鏄叕鍏卞懡浠�(*)鎴栨牴鍛戒护(:) if (current->ptr[0] == '*' || current->ptr[0] == ':') return TRUE; @@ -707,6 +710,7 @@ current->ptr -= i; current->len += i; + //澶嶅悎鍛戒护缁勫悎 memmove(current->ptr, prev->ptr, i); return TRUE; } @@ -754,7 +758,8 @@ #if USE_MEMORY_ALLOCATION_FREE && !HAVE_STRNDUP char *OUR_strndup(const char *s, size_t n) { size_t len = SCPIDEFINE_strnlen(s, n); - char * result = malloc(len + 1); + //msvc涓嬮渶瑕佸己杞� + char * result =(char*) malloc(len + 1); if (!result) { return NULL; } diff --git a/libscpi/src/utils_private.h b/libscpi/src/utils_private.h index 6ae1616..165e23c 100644 --- a/libscpi/src/utils_private.h +++ b/libscpi/src/utils_private.h @@ -39,8 +39,8 @@ #define SCPI_UTILS_PRIVATE_H #include <stdint.h> -#include "scpi/config.h" -#include "scpi/types.h" +#include<scpi/config.h> +#include<scpi/types.h> #ifdef __cplusplus extern "C" { -- Gitblit v1.9.1