Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce SCPI_HelpQ with descriptions #135

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
28b17f7
output block data with delimiter
MisterHW Feb 1, 2022
8ed2623
fix typos
MisterHW Feb 2, 2022
bc4f1d5
introduce SCPI_HelpQ
MisterHW Feb 3, 2022
315f20d
introduce help search
MisterHW Feb 7, 2022
159fe83
drop C++20 keyword
MisterHW Feb 7, 2022
d099d9a
rename to USE_HELP_FILTER
MisterHW Feb 7, 2022
aa660db
fix expression
MisterHW Feb 7, 2022
1460793
add full command descriptions to examples common def, set desc. defau…
MisterHW Jan 6, 2023
7d0c83d
clean-up
MisterHW Jan 7, 2023
c394eb9
propagate MODE to Makefile for cross-compiling
MisterHW Jan 7, 2023
1e1b594
provide more elaborate description depending on USE_HELP_FILTER
MisterHW Jan 14, 2023
f7c4cc4
Merge branch 'j123b567:master' into scpi_helpq_enhancement
MisterHW Jan 16, 2023
b3668be
Merge branch 'j123b567:master' into scpi_helpq_enhancement
MisterHW Jan 17, 2023
36ddafe
strncasestr, strncasestrn_s, pp_xstr clean-up and formatting
MisterHW Jan 17, 2023
9c66dcd
fix C89 issue (FALSE, for syntax)
MisterHW Jan 17, 2023
0e7c828
remove strcasestr
MisterHW Jan 17, 2023
5dfac2b
strncasecmp -> SCPIDEFINE_strncasecmp
MisterHW Jan 17, 2023
5153e03
C style comments
MisterHW Jan 17, 2023
8aa90a7
split off HELP? into help.h/.c
MisterHW Jan 17, 2023
31a3e44
add help.c, help.h to Makefile
MisterHW Jan 17, 2023
d8a5d24
redo delete SCPI_HelpQ
MisterHW Jan 17, 2023
63f5e88
Revert "propagate MODE to Makefile for cross-compiling"
MisterHW Jan 17, 2023
d803ffe
simply SCPI_CMD_LIST_END definition
MisterHW Jan 17, 2023
a44b9aa
add missing ,
MisterHW Jan 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add full command descriptions to examples common def, set desc. defau…
…lt disabled

* Properly integrate command descriptions into examples. Preliminary descriptions added after consulting scpi-99 standard, as well as looking at the DMM and TEST handler source. Command paramater types hinted as <param> where appropriate. Return values or ranges given at the end of each description in round brackets.
* Default changed to USE_COMMAND_DESCRIPTIONS 0 to avoid unexpected impact on code side. Set to 1 to use.
* scpi_command_t defintion helper macros moves to types.h
  • Loading branch information
MisterHW committed Jan 6, 2023
commit 1460793f75ba66721718b604ac2d5f4baa308a2a
134 changes: 62 additions & 72 deletions examples/common/scpi-def.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,85 +353,75 @@ static scpi_result_t My_CoreTstQ(scpi_t * context) {
return SCPI_RES_OK;
}

#if USE_COMMAND_DESCRIPTIONS
#define SCPI_CMD_DESC(S) .description=(S),
#else
#define SCPI_CMD_DESC(S)
#endif

#if USE_COMMAND_TAGS
#define SCPI_CMD_TAG(T) .tag=(T),
#else
#define SCPI_CMD_TAG(T)
#endif
#define pp_xstr(s) pp_str(s)
#define pp_str(s) #s
#define SCPI_ERROR_QUEUE_SIZE_STR pp_xstr(SCPI_ERROR_QUEUE_SIZE)

const scpi_command_t scpi_commands[] = {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please provide alternative definition files for this functionality?

It is a generally useful but unusual extension. I would like to keep examples simple. Users can decide on their own if they would like to use help command or not and it is generally not needed. It will find its way, but I would like to keep the first impression simple.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, somehow divide the existing source (it is just an example anyway) so one part of the commands has help and the other does not so it is clear, that it is not mandatory to use and define help and tag.

Copy link
Contributor Author

@MisterHW MisterHW Jan 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scpi-def.c and scpi-def.cpp are essentially identical. scpi-def.c could be stripped down to illustrate what a version with no help and no command tags could look like. One could additionally introduce

#define NO_CMD_DESC SCPI_CMD_DESC(NULL)

which would help being explicit about the generalized structure. With scpi-def being in common, offering definitions for all possible cases seems a bit excessive to me.

Retrospective Context:
Keep in mind that prior to this PR, the default was

#define USE_COMMAND_TAGS 1

and setting it to 0 would cause a type mismatch, as in scpi-def.c/.cpp there were extra (unconditional) , 0 in the scpi_commands[] items.

The documentation on HELP? might be the best place to elaborate on way to further strip down the definition and explain the implications. This was warrented through the existence of USE_COMMAND_TAGS, and in my opinion is underscored yet again through the introduction of USE_COMMAND_DESCRIPTIONS.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, scpi-def.cpp is identical to the scpi-def.c but all C specific features are removed so it can be compiled by the C++ compiler. Because this is C library, C++ file is just an example without real usage here.

Initially, examples were more about the communication interface and the command interface was the same. In the current perspective, there could be more standalone examples promoting separate features of the library, like enabling/disabling TAGs, and more importantly, introducing HELP? command.

Maybe, there can be a new example based on e.g. test-interactive to show, how HELP? command works and how to define all strings. It can have a completely different structure and its own commands definition.

/* Optional help commmand */
{.pattern = "HELP?", .callback = SCPI_HelpQ, SCPI_CMD_DESC("\t - list supported 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,},

/* Optional help command */
{"HELP?", SCPI_HelpQ, SCPI_CMD_DESC("\t - list supported commands") SCPI_CMD_TAG(0)},

/* IEEE Mandated Commands (SCPI std V1999.0 4.1.1): *CLS *ESE *ESE? *ESR? *IDN? *OPC *OPC? *RST *SRE *SRE? *STB? *TST? *WAI */
{"*CLS", SCPI_CoreCls, SCPI_CMD_DESC("\t - clear all Event Status registers, errors, output queue") SCPI_CMD_TAG(0)},
// -- Standard Event Status Group [EVENT]-[ENABLE]
{"*ESE", SCPI_CoreEse, SCPI_CMD_DESC("<0..255> - set Standard Event Status Enable (event mask)") SCPI_CMD_TAG(0)},
{"*ESE?", SCPI_CoreEseQ, SCPI_CMD_DESC("\t - read ESE (0..255)") SCPI_CMD_TAG(0)},
{"*ESR?", SCPI_CoreEsrQ, SCPI_CMD_DESC("\t - read+clear Standard Event Status register") SCPI_CMD_TAG(0)},
// -- IEEE Mandated Commands (continued ...)
{"*IDN?", SCPI_CoreIdnQ, SCPI_CMD_DESC("\t - read device identifier (multi-line string)") SCPI_CMD_TAG(0)},
{"*OPC", SCPI_CoreOpc, SCPI_CMD_DESC("\t - complete ops preceding Operation Complete Command, set ESR.OPC 1") SCPI_CMD_TAG(0)},
{"*OPC?", SCPI_CoreOpcQ, SCPI_CMD_DESC("\t - read ESR.OPC (0:ongoing ops, 1:done)") SCPI_CMD_TAG(0)},
{"*RST", SCPI_CoreRst, SCPI_CMD_DESC("\t - reset instrument and interface") SCPI_CMD_TAG(0)},
{"*SRE", SCPI_CoreSre, SCPI_CMD_DESC("<0..255> - set Service Request Enable (event mask over STB)") SCPI_CMD_TAG(0)},
{"*SRE?", SCPI_CoreSreQ, SCPI_CMD_DESC("\t - read SRE (0..255)") SCPI_CMD_TAG(0)},
{"*STB?", SCPI_CoreStbQ, SCPI_CMD_DESC("\t - read STatus Byte (0..255)") SCPI_CMD_TAG(0)},
{"*TST?", My_CoreTstQ, SCPI_CMD_DESC("\t - read self-test result (0:no failures)") SCPI_CMD_TAG(0)},
{"*WAI", SCPI_CoreWai, SCPI_CMD_DESC("\t - halt cmd execution until pending operations complete") SCPI_CMD_TAG(0)},

/* Required SCPI commands (SCPI std V1999.0 4.2.1) : SYSTem:ERRor, STATus:OPERation, STATus:QUEStionable and STATus:PRESet */
{"SYSTem:ERRor[:NEXT]?", SCPI_SystemErrorNextQ, SCPI_CMD_DESC("\t - get next error in queue (int error,string)") SCPI_CMD_TAG(0)},
{"SYSTem:ERRor:COUNt?", SCPI_SystemErrorCountQ, SCPI_CMD_DESC("\t - queued error count (0.." SCPI_ERROR_QUEUE_SIZE_STR ")") SCPI_CMD_TAG(0)},
{"SYSTem:VERSion?", SCPI_SystemVersionQ, SCPI_CMD_DESC("\t - query system version (version expr)") SCPI_CMD_TAG(0)},
// -- Operation Status Group [CONDITION]-[EVENT]-[ENABLE]
{"STATus:OPERation:CONDition?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
{"STATus:OPERation[:EVENt]?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
{"STATus:OPERation:ENABle", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
{"STATus:OPERation:ENABle?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
// -- Questionable Status Group [CONDITION]-[EVENT]-[ENABLE]
{"STATus:QUEStionable:CONDition?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented") SCPI_CMD_TAG(0)}, // "\t - read momentary Questionable Condition register (0..65535)"
{"STATus:QUEStionable[:EVENt]?", SCPI_StatusQuestionableEventQ, SCPI_CMD_DESC("\t - read Questionable Event register (0..65535)") SCPI_CMD_TAG(0)},
{"STATus:QUEStionable:ENABle", SCPI_StatusQuestionableEnable, SCPI_CMD_DESC("<0..65535> - set Questionable Enable (event mask)") SCPI_CMD_TAG(0)},
{"STATus:QUEStionable:ENABle?", SCPI_StatusQuestionableEnableQ, SCPI_CMD_DESC("\t - Questionable Status Enable (0..65535)") SCPI_CMD_TAG(0)},
{"STATus:PRESet", SCPI_StatusPreset, SCPI_CMD_DESC("\t - load Status sub-system register defaults") SCPI_CMD_TAG(0)},

/* commands specific to DMM example with TEST sub-system */
{"SYSTem:COMMunication:TCPIP:CONTROL?", SCPI_SystemCommTcpipControlQ, SCPI_CMD_DESC("\t - read TCPIP control port") SCPI_CMD_TAG(0)},
{"CONFigure:VOLTage:DC", DMM_ConfigureVoltageDc, SCPI_CMD_DESC("<float>[,<float>] - test command") SCPI_CMD_TAG(0)},
{"MEASure:VOLTage:DC?", DMM_MeasureVoltageDcQ, SCPI_CMD_DESC("[<float>[,<float>]] - test command (0)") SCPI_CMD_TAG(0)},
{"MEASure:VOLTage:DC:RATio?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
{"MEASure:VOLTage:AC?", DMM_MeasureVoltageAcQ, SCPI_CMD_DESC("[<float>[,<float>]] - test command (0)") SCPI_CMD_TAG(0)},
{"MEASure:CURRent:DC?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
{"MEASure:CURRent:AC?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
{"MEASure:RESistance?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
{"MEASure:FRESistance?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
{"MEASure:FREQuency?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
{"MEASure:PERiod?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
{"TEST:BOOL", TEST_Bool, SCPI_CMD_DESC("<bool> - test command") SCPI_CMD_TAG(0)},
{"TEST:CHOice?", TEST_ChoiceQ, SCPI_CMD_DESC("<choice> - test command (\"BUS\":5,\"IMMediate\":6,\"EXTernal\",7)") SCPI_CMD_TAG(0)},
{"TEST#:NUMbers#", TEST_Numbers, SCPI_CMD_DESC("\t - test command with numbers - default 1") SCPI_CMD_TAG(0)},
{"TEST:TEXT", TEST_Text, SCPI_CMD_DESC("<param>[, ...] - debug print <param> as received") SCPI_CMD_TAG(0)},
{"TEST:ARBitrary?", TEST_ArbQ, SCPI_CMD_DESC("<block data> - receive and return block data (block data)") SCPI_CMD_TAG(0)},
{"TEST:CHANnellist", TEST_Chanlst, SCPI_CMD_DESC("<channel_list> - test channel list parsing") SCPI_CMD_TAG(0)},

SCPI_CMD_LIST_END
};

scpi_interface_t scpi_interface = {
.error = SCPI_Error,
.write = SCPI_Write,
.error = SCPI_Error,
MisterHW marked this conversation as resolved.
Show resolved Hide resolved
.write = SCPI_Write,
.control = SCPI_Control,
.flush = SCPI_Flush,
.reset = SCPI_Reset,
.flush = SCPI_Flush,
.reset = SCPI_Reset,
};

char scpi_input_buffer[SCPI_INPUT_BUFFER_LENGTH];
Expand Down
130 changes: 60 additions & 70 deletions examples/common/scpi-def.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,85 +353,75 @@ static scpi_result_t My_CoreTstQ(scpi_t * context) {
return SCPI_RES_OK;
}

#if USE_COMMAND_DESCRIPTIONS
#define SCPI_CMD_DESC(S) (S),
#else
#define SCPI_CMD_DESC(S)
#endif

#if USE_COMMAND_TAGS
#define SCPI_CMD_TAG(T) (T),
#else
#define SCPI_CMD_TAG(T)
#endif
#define pp_xstr(s) pp_str(s)
#define pp_str(s) #s
#define SCPI_ERROR_QUEUE_SIZE_STR pp_xstr(SCPI_ERROR_QUEUE_SIZE)

const scpi_command_t scpi_commands[] = {
/* Optional help command */
{"HELP?", SCPI_HelpQ, SCPI_CMD_DESC("\t - list supported commands") SCPI_CMD_TAG(0)},

/* IEEE Mandated Commands (SCPI std V1999.0 4.1.1) */
{"*CLS", SCPI_CoreCls, SCPI_CMD_TAG(0)},
{"*ESE", SCPI_CoreEse, SCPI_CMD_TAG(0)},
{"*ESE?", SCPI_CoreEseQ, SCPI_CMD_TAG(0)},
{"*ESR?", SCPI_CoreEsrQ, SCPI_CMD_TAG(0)},
{"*IDN?", SCPI_CoreIdnQ, SCPI_CMD_TAG(0)},
{"*OPC", SCPI_CoreOpc, SCPI_CMD_TAG(0)},
{"*OPC?", SCPI_CoreOpcQ, SCPI_CMD_TAG(0)},
{"*RST", SCPI_CoreRst, SCPI_CMD_TAG(0)},
{"*SRE", SCPI_CoreSre, SCPI_CMD_TAG(0)},
{"*SRE?", SCPI_CoreSreQ, SCPI_CMD_TAG(0)},
{"*STB?", SCPI_CoreStbQ, SCPI_CMD_TAG(0)},
{"*TST?", My_CoreTstQ, SCPI_CMD_TAG(0)},
{"*WAI", SCPI_CoreWai, SCPI_CMD_TAG(0)},

/* Required SCPI commands (SCPI std V1999.0 4.2.1) */
{"SYSTem:ERRor[:NEXT]?", SCPI_SystemErrorNextQ, SCPI_CMD_TAG(0)},
{"SYSTem:ERRor:COUNt?", SCPI_SystemErrorCountQ, SCPI_CMD_TAG(0)},
{"SYSTem:VERSion?", SCPI_SystemVersionQ, SCPI_CMD_TAG(0)},

//{"STATus:OPERation?", scpi_stub_callback, SCPI_CMD_TAG(0)},
//{"STATus:OPERation:EVENt?", scpi_stub_callback, SCPI_CMD_TAG(0)},
//{"STATus:OPERation:CONDition?", scpi_stub_callback, SCPI_CMD_TAG(0)},
//{"STATus:OPERation:ENABle", scpi_stub_callback, SCPI_CMD_TAG(0)},
//{"STATus:OPERation:ENABle?", scpi_stub_callback, SCPI_CMD_TAG(0)},

{"STATus:QUEStionable[:EVENt]?", SCPI_StatusQuestionableEventQ, SCPI_CMD_TAG(0)},
//{"STATus:QUEStionable:CONDition?", scpi_stub_callback, SCPI_CMD_TAG(0)},
{"STATus:QUEStionable:ENABle", SCPI_StatusQuestionableEnable, SCPI_CMD_TAG(0)},
{"STATus:QUEStionable:ENABle?", SCPI_StatusQuestionableEnableQ, SCPI_CMD_TAG(0)},

{"STATus:PRESet", SCPI_StatusPreset, SCPI_CMD_TAG(0)},

/* DMM */
{"MEASure:VOLTage:DC?", DMM_MeasureVoltageDcQ, SCPI_CMD_TAG(0)},
{"CONFigure:VOLTage:DC", DMM_ConfigureVoltageDc, SCPI_CMD_TAG(0)},
{"MEASure:VOLTage:DC:RATio?", SCPI_StubQ, SCPI_CMD_TAG(0)},
{"MEASure:VOLTage:AC?", DMM_MeasureVoltageAcQ, SCPI_CMD_TAG(0)},
{"MEASure:CURRent:DC?", SCPI_StubQ, SCPI_CMD_TAG(0)},
{"MEASure:CURRent:AC?", SCPI_StubQ, SCPI_CMD_TAG(0)},
{"MEASure:RESistance?", SCPI_StubQ, SCPI_CMD_TAG(0)},
{"MEASure:FRESistance?", SCPI_StubQ, SCPI_CMD_TAG(0)},
{"MEASure:FREQuency?", SCPI_StubQ, SCPI_CMD_TAG(0)},
{"MEASure:PERiod?", SCPI_StubQ, SCPI_CMD_TAG(0)},

{"SYSTem:COMMunication:TCPIP:CONTROL?", SCPI_SystemCommTcpipControlQ, SCPI_CMD_TAG(0)},

{"TEST:BOOL", TEST_Bool, SCPI_CMD_TAG(0)},
{"TEST:CHOice?", TEST_ChoiceQ, SCPI_CMD_TAG(0)},
{"TEST#:NUMbers#", TEST_Numbers, SCPI_CMD_TAG(0)},
{"TEST:TEXT", TEST_Text, SCPI_CMD_TAG(0)},
{"TEST:ARBitrary?", TEST_ArbQ, SCPI_CMD_TAG(0)},
{"TEST:CHANnellist", TEST_Chanlst, SCPI_CMD_TAG(0)},


/* IEEE Mandated Commands (SCPI std V1999.0 4.1.1): *CLS *ESE *ESE? *ESR? *IDN? *OPC *OPC? *RST *SRE *SRE? *STB? *TST? *WAI */
{"*CLS", SCPI_CoreCls, SCPI_CMD_DESC("\t - clear all Event Status registers, errors, output queue") SCPI_CMD_TAG(0)},
MisterHW marked this conversation as resolved.
Show resolved Hide resolved
// -- Standard Event Status Group [EVENT]-[ENABLE]
{"*ESE", SCPI_CoreEse, SCPI_CMD_DESC("<0..255> - set Standard Event Status Enable (event mask)") SCPI_CMD_TAG(0)},
{"*ESE?", SCPI_CoreEseQ, SCPI_CMD_DESC("\t - read ESE (0..255)") SCPI_CMD_TAG(0)},
{"*ESR?", SCPI_CoreEsrQ, SCPI_CMD_DESC("\t - read+clear Standard Event Status register") SCPI_CMD_TAG(0)},
// -- IEEE Mandated Commands (continued ...)
{"*IDN?", SCPI_CoreIdnQ, SCPI_CMD_DESC("\t - read device identifier (multi-line string)") SCPI_CMD_TAG(0)},
{"*OPC", SCPI_CoreOpc, SCPI_CMD_DESC("\t - complete ops preceding Operation Complete Command, set ESR.OPC 1") SCPI_CMD_TAG(0)},
{"*OPC?", SCPI_CoreOpcQ, SCPI_CMD_DESC("\t - read ESR.OPC (0:ongoing ops, 1:done)") SCPI_CMD_TAG(0)},
{"*RST", SCPI_CoreRst, SCPI_CMD_DESC("\t - reset instrument and interface") SCPI_CMD_TAG(0)},
{"*SRE", SCPI_CoreSre, SCPI_CMD_DESC("<0..255> - set Service Request Enable (event mask over STB)") SCPI_CMD_TAG(0)},
{"*SRE?", SCPI_CoreSreQ, SCPI_CMD_DESC("\t - read SRE (0..255)") SCPI_CMD_TAG(0)},
{"*STB?", SCPI_CoreStbQ, SCPI_CMD_DESC("\t - read STatus Byte (0..255)") SCPI_CMD_TAG(0)},
{"*TST?", My_CoreTstQ, SCPI_CMD_DESC("\t - read self-test result (0:no failures)") SCPI_CMD_TAG(0)},
{"*WAI", SCPI_CoreWai, SCPI_CMD_DESC("\t - halt cmd execution until pending operations complete") SCPI_CMD_TAG(0)},

/* Required SCPI commands (SCPI std V1999.0 4.2.1) : SYSTem:ERRor, STATus:OPERation, STATus:QUEStionable and STATus:PRESet */
{"SYSTem:ERRor[:NEXT]?", SCPI_SystemErrorNextQ, SCPI_CMD_DESC("\t - get next error in queue (int error,string)") SCPI_CMD_TAG(0)},
{"SYSTem:ERRor:COUNt?", SCPI_SystemErrorCountQ, SCPI_CMD_DESC("\t - queued error count (0.." SCPI_ERROR_QUEUE_SIZE_STR ")") SCPI_CMD_TAG(0)},
{"SYSTem:VERSion?", SCPI_SystemVersionQ, SCPI_CMD_DESC("\t - query system version (version expr)") SCPI_CMD_TAG(0)},
// -- Operation Status Group [CONDITION]-[EVENT]-[ENABLE]
{"STATus:OPERation:CONDition?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
{"STATus:OPERation[:EVENt]?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
{"STATus:OPERation:ENABle", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
{"STATus:OPERation:ENABle?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
// -- Questionable Status Group [CONDITION]-[EVENT]-[ENABLE]
{"STATus:QUEStionable:CONDition?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented") SCPI_CMD_TAG(0)}, // "\t - read momentary Questionable Condition register (0..65535)"
{"STATus:QUEStionable[:EVENt]?", SCPI_StatusQuestionableEventQ, SCPI_CMD_DESC("\t - read Questionable Event register (0..65535)") SCPI_CMD_TAG(0)},
{"STATus:QUEStionable:ENABle", SCPI_StatusQuestionableEnable, SCPI_CMD_DESC("<0..65535> - set Questionable Enable (event mask)") SCPI_CMD_TAG(0)},
{"STATus:QUEStionable:ENABle?", SCPI_StatusQuestionableEnableQ, SCPI_CMD_DESC("\t - Questionable Status Enable (0..65535)") SCPI_CMD_TAG(0)},
{"STATus:PRESet", SCPI_StatusPreset, SCPI_CMD_DESC("\t - load Status sub-system register defaults") SCPI_CMD_TAG(0)},

/* commands specific to DMM example with TEST sub-system */
{"SYSTem:COMMunication:TCPIP:CONTROL?", SCPI_SystemCommTcpipControlQ, SCPI_CMD_DESC("\t - read TCPIP control port") SCPI_CMD_TAG(0)},
{"CONFigure:VOLTage:DC", DMM_ConfigureVoltageDc, SCPI_CMD_DESC("<float>[,<float>] - test command") SCPI_CMD_TAG(0)},
{"MEASure:VOLTage:DC?", DMM_MeasureVoltageDcQ, SCPI_CMD_DESC("[<float>[,<float>]] - test command (0)") SCPI_CMD_TAG(0)},
{"MEASure:VOLTage:DC:RATio?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
{"MEASure:VOLTage:AC?", DMM_MeasureVoltageAcQ, SCPI_CMD_DESC("[<float>[,<float>]] - test command (0)") SCPI_CMD_TAG(0)},
{"MEASure:CURRent:DC?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
{"MEASure:CURRent:AC?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
{"MEASure:RESistance?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
{"MEASure:FRESistance?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
{"MEASure:FREQuency?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
{"MEASure:PERiod?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
{"TEST:BOOL", TEST_Bool, SCPI_CMD_DESC("<bool> - test command") SCPI_CMD_TAG(0)},
{"TEST:CHOice?", TEST_ChoiceQ, SCPI_CMD_DESC("<choice> - test command (\"BUS\":5,\"IMMediate\":6,\"EXTernal\",7)") SCPI_CMD_TAG(0)},
{"TEST#:NUMbers#", TEST_Numbers, SCPI_CMD_DESC("\t - test command with numbers - default 1") SCPI_CMD_TAG(0)},
{"TEST:TEXT", TEST_Text, SCPI_CMD_DESC("<param>[, ...] - debug print <param> as received") SCPI_CMD_TAG(0)},
{"TEST:ARBitrary?", TEST_ArbQ, SCPI_CMD_DESC("<block data> - receive and return block data (block data)") SCPI_CMD_TAG(0)},
{"TEST:CHANnellist", TEST_Chanlst, SCPI_CMD_DESC("<channel_list> - test channel list parsing") SCPI_CMD_TAG(0)},

SCPI_CMD_LIST_END
};

scpi_interface_t scpi_interface = {
/*.error = */ SCPI_Error,
/*.write = */ SCPI_Write,
/*.error = */ SCPI_Error,
MisterHW marked this conversation as resolved.
Show resolved Hide resolved
/*.write = */ SCPI_Write,
/*.control = */ SCPI_Control,
/*.flush = */ SCPI_Flush,
/*.reset = */ SCPI_Reset,
/*.flush = */ SCPI_Flush,
/*.reset = */ SCPI_Reset,
};

char scpi_input_buffer[SCPI_INPUT_BUFFER_LENGTH];
Expand Down
2 changes: 1 addition & 1 deletion libscpi/inc/scpi/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ extern "C" {
#endif

#ifndef USE_COMMAND_DESCRIPTIONS
#define USE_COMMAND_DESCRIPTIONS 1
#define USE_COMMAND_DESCRIPTIONS 0
#endif

#ifndef USE_DEPRECATED_FUNCTIONS
Expand Down
17 changes: 15 additions & 2 deletions libscpi/inc/scpi/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ extern "C" {
typedef struct _scpi_data_parameter_t scpi_data_parameter_t;

typedef scpi_token_t scpi_parameter_t;

MisterHW marked this conversation as resolved.
Show resolved Hide resolved
struct _scpi_command_t {
const char * pattern;
scpi_command_callback_t callback;
Expand All @@ -363,6 +363,20 @@ extern "C" {
#endif /* USE_COMMAND_TAGS */
};

/* Helper macros for _scpi_command_t items. Usage:
_scpi_command_t cmd = {.pattern=":SOME:PATTern", .callback=SCPI_StubQ, SCPI_CMD_DESC("\t - a command") SCPI_CMD_TAG(0)};
*/
#if USE_COMMAND_DESCRIPTIONS
#define SCPI_CMD_DESC(S) (S),
#else
#define SCPI_CMD_DESC(S)
#endif
#if USE_COMMAND_TAGS
#define SCPI_CMD_TAG(T) (T),
#else
#define SCPI_CMD_TAG(T)
#endif

struct _scpi_interface_t {
scpi_error_callback_t error;
scpi_write_t write;
Expand Down Expand Up @@ -405,4 +419,3 @@ extern "C" {
#endif

#endif /* SCPI_TYPES_H */