That was NOT the correct solution.
OK.
Here you go:
Initializing SD card...
initialization done.
my_buffer:
:MEASURE:PRINT
This is the function from the library:
scpi_execute_command(struct scpi_parser_context* ctx, char* command_string, size_t length)
The whole code:
#include <scpiparser.h>
#include <Arduino.h>
#include <SPI.h>
#include "SdFat.h"
SdFat SD;
struct scpi_parser_context ctx;
scpi_error_t identify(struct scpi_parser_context* context, struct scpi_token* command);
scpi_error_t print_value(struct scpi_parser_context* context, struct scpi_token* command);
scpi_error_t print1_value(struct scpi_parser_context* context, struct scpi_token* command);
File NewFile;
void setup()
{
struct scpi_command* measure;
struct scpi_command* value;
/* First, initialise the parser. */
scpi_init(&ctx);
/*
* After initialising the parser, we set up the command tree. Ours is
*
* *IDN? -> identify
* :MEASure
* :PRInt -> print_value
* :VALue
* :PRInt1? -> print1_value
*/
scpi_register_command(ctx.command_tree, SCPI_CL_SAMELEVEL, "*IDN?", 5, "*IDN?", 5, identify); //Initialise SameLevel function of Identify
measure = scpi_register_command(ctx.command_tree, SCPI_CL_CHILD, "MEASURE", 7, "MEAS", 4, NULL); // Command tree first child with main header name
value = scpi_register_command(ctx.command_tree, SCPI_CL_CHILD, "VALUE", 5, "VAL", 3, NULL);
scpi_register_command(measure, SCPI_CL_CHILD, "PRINT", 5, "PRI", 3, print_value); // Command tree subchild to the first child
scpi_register_command(value, SCPI_CL_CHILD, "PRINT1?", 7, "PRI1?", 5, print1_value); // Command tree subchild to the first child
pinMode(15, OUTPUT);
Serial.begin(9600);
Serial.println("Type any character to start");
while (Serial.read() <= 0) {}
Serial.print("Initializing SD card...");
Serial.println();
pinMode(SDCARD_SS_PIN, OUTPUT);
if (!SD.begin(SDCARD_SS_PIN)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
NewFile = SD.open("commands.txt"); // open existing file
if (NewFile) {
String line= NewFile.readStringUntil('\n'); //Read from the SD card
Serial.print("Line read from the sd card is :"); Serial.print(line); Serial.println("");
int llength = line.length();
Serial.println(llength);
char my_buffer[256];
line.toCharArray(my_buffer,llength);
Serial.println("my_buffer:");
Serial.println(my_buffer);
/*for(int b=0; b < strlen(my_buffer); b++)
{
Serial.print(b);
Serial.print(") ");
Serial.println(my_buffer[b]);
}
Serial.println("=============");*/
if(llength > 0)
{
scpi_execute_command(&ctx, my_buffer,llength); // function call for execution of command
}
}
}
void loop()
{
}
/*
* Respond to *IDN?
*/
scpi_error_t identify(struct scpi_parser_context* context, struct scpi_token* command)
{
scpi_free_tokens(command);
Serial.println("MKR ZERO");
return SCPI_SUCCESS;
}
/*
* Respond to the command :MEASURE:PRINT
*/
scpi_error_t print_value(struct scpi_parser_context* context, struct scpi_token* command)
{
scpi_free_tokens(command);
Serial.println("Level 1 reached");
return SCPI_SUCCESS;
}
/*
* Respond to the command :VALUE:PRINT1?
*/
scpi_error_t print1_value(struct scpi_parser_context* context, struct scpi_token* command)
{
scpi_free_tokens(command);
Serial.println("Level 2 reached");
return SCPI_SUCCESS;
}