Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 21 additions & 0 deletions examples/Numeric_suffixes/Numeric_suffixes.ino
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ void setup()
my_instrument.RegisterCommand(F("DIn#?"), &QueryDigital_Input);
my_instrument.RegisterCommand(F("DOut#"), &WriteDigital_Output);
my_instrument.RegisterCommand(F("DOut#?"), &QueryDigital_Output);
my_instrument.RegisterCommand(F("DOut#:DRIve?"), &QueryDrive_Output);

for (int i = 0; i < 6; i++) {
pinMode(DIn[i], INPUT);
Expand Down Expand Up @@ -128,6 +129,26 @@ void QueryDigital_Output(SCPI_C commands, SCPI_P parameters, Stream& interface)
}
}

void QueryDrive_Output(SCPI_C commands, SCPI_P parameters, Stream& interface) {
//DOut<index>?
//Queries the drive strength of DOut[index] pin
//Return values is always FULL, as this is just a demo of a nested numeric
//Examples:
// DO4:DRI? (Queries the strength of DOut[4] pin)
// DOut:DRI6? (This does nothing as DOut[6] does not exists)

//Get the numeric suffix/index (if any) from the commands
commands.Pop(); // remove the DRIve command
String header = String(commands.Last());
header.toUpperCase();
int suffix = -1;
sscanf(header.c_str(),"%*[DOUT]%u", &suffix);

//If the suffix is valid, print the pin's logic value to the interface
if ( (suffix >= 0) && (suffix < 6) ) {
interface.println("FULL");
}
}
void WriteDigital_Output(SCPI_C commands, SCPI_P parameters, Stream& interface) {
//DOut<index> state
//Sets the logic state of DOut[index] pin
Expand Down
4 changes: 4 additions & 0 deletions src/Vrekrer_scpi_parser_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ void SCPI_Parser::RegisterCommand(char* command, SCPI_caller_t caller) {
return;
}
SCPI_Commands command_tokens(command);
if ((tree_length_ + command_tokens.Size()) > SCPI_ARRAY_SYZE) {
setup_errors.branch_overflow = true;
return;
}
for (uint8_t i = 0; i < command_tokens.Size(); i++)
this->AddToken_(command_tokens[i]);
scpi_hash_t code = this->GetCommandCode_(command_tokens);
Expand Down