Comments (6)
Have a look at https://github.com/j123b567/scpi-parser/blob/master/libscpi/src/parser.c#L653.
How SCPI_ParamInt
works is, you copy your parameter to a variable (see https://github.com/j123b567/scpi-parser/blob/master/examples/common/scpi-def.c#L100 for an example), it just returns TRUE (Success) or FALSE (otherwise) if the parameter wasn't an Integer value.
The function SCPI_ParamInt will return
TRUE if successful and
FALSE in case the Datatype doesn't match or there was a parameter with a suffix (one should handle this with SCPI_ParamNumber
).
You have to check the integer value afterwards yourself (for example if it is in the correct range or whatever).
Thats why there is an
if (!SCPI_ParamInt( context, ¶m, FALSE)) {
param = 23; //some default value in case there wasn't a parameter given;
}
//handle param
You can figure out the error by using the Error Subsystem.
Update: If there wasn't a parameter entered, SCPI_ERROR_MISSING_PARAMETER
gets pushed to the Error Subsystem (https://github.com/j123b567/scpi-parser/blob/master/libscpi/src/parser.c#L470)
from scpi-parser.
@koeart I think that @mvladic has different problem and he is right that there is no souch direct functin for it. There are some solutions more or less ugly.
- split parameter handling into two functions
SCPI_Parameter()
andSCPI_ParamToInt()
. Result ofSCPI_Parameter()
tells you, if parameter was here or not. You can later check the type of the parameter. If the function returnsFALSE
and parameter type isSCPI_TOKEN_PROGRAM_MNEMONIC
, this means missing parameter. If type isSCPI_TOKEN_UNKNOWN
, error occured. IfSCPI_ParamIsNumber()
then it is safe to convert it to integer. - Before and after calling
SCPI_ParamInt()
, you can readoutSCPI_ErrorCount()
. If the number changes, it meas, there was an error. - Do some magic in
error()
callback and set some global variable to detect this.
I don't want to break current API so there are some solution for the future:
- introduce something like
errorno
. There will be last error of theSCPI_ParamXYZ()
function or 0. - introduce API function
SCPI_ParamIsInvalid()
so you can check parameter fromSCPI_Parameter()
without relaying on some parser internals.
What do you think?
from scpi-parser.
I like errorno
solution more because I don't need to split parameter handling into two functions (SCPI_Parameter()
and SCPI_ParamToInt()
). In that case I will do the following:
if (!SCPI_ParamToInt(context, ...)) {
if (errorno) {
return SCPI_RES_ERR;
}
// not a real error, i.e. optional parameter is missing, continue
}
You could also add SCPI_ParamIsInvalid()
, it looks like an useful function.
from scpi-parser.
Sounds good. I will extend context
with errno
and implement SCPI_ParamIsInvalid()
.
This is almost mechanical but large change so it will take some time to implement this. I would like to add also unit tests for this to be sure it is correct. So please be patient.
from scpi-parser.
Thanks! In the meantime I will use one of the workarounds that you proposed.
from scpi-parser.
It was easier than I thought. The functionality was already there.
You can use
if (!SCPI_ParamToInt(context, ...)) {
if (SCPI_ParamErrorOccurred(context)) {
return SCPI_RES_ERR;
}
// not a real error, i.e. optional parameter is missing, continue
}
from scpi-parser.
Related Issues (20)
- C++ compilation error due to NULL being a long int HOT 1
- ip set HOT 1
- check if osThreadCreate() successful HOT 8
- Possible to have multiple, independent scpi session? HOT 4
- Example of Optional keywords/Related API HOT 1
- introducing a help command HOT 5
- problem talking with sigrok HOT 5
- USE_FULL ERROR LIST report "Unknow Error" for all XE errors HOT 2
- Termination for SCPI commands HOT 3
- arm cross-compilation requires additional flags HOT 2
- Compile error when compiling with C++17 HOT 1
- vxi11.h missing ??
- Port to Arduino
- scpi-parser support on windows? HOT 1
- Documentation out of date?
- How the MAV bit is setting in Status register. HOT 1
- Handle errors from the read/write method HOT 11
- [Feature request] Add support to handle numerical values in choice list
- TEST_Chanlst upper limit fails HOT 1
- Parsing decimal values HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scpi-parser.