Search code examples
testcasecaplcanoe

How can I access value table entries of signals in CAPL?


I'm building CAPL test cases, and when the test passes, I want to output a signal (Status P) description based on current value . a table in signal:

Value Description
0*0 OFF
0*1 INIT
0*2 IDEAL
0*3 ACTIVE
0*4 Error

i have tried this

if(Failure  == 0)
  {
    snprintf (msg, 200, "%s","");
    snprintf (buffer, 200, "%s", "It has NO ERROR, It is in ");
    strncat (msg, buffer,40);
    snprintf (buffer, 200, "%d", $Status_P);
    testStepPass("",msg); 

it is not printing values or description. could you please help me?


Solution

  • You can get the description for a signal value by using the CAPL function getSignalDescriptionForValue.

    Usage is as follows:

    char buffer[50];
    long retVal;
    
    retVal = getSignalDescriptionForValue(Node::Message::Signal, <raw signal value>, buffer, elcount(buffer));
    

    Node::Message::Signal has to be the signal itself, i.e. the thing you get, when you drag&drop the signal from the Symbols pane into your code in the CAPL Browser.

    <raw signal value> has to be the raw value (not the physical value) of the signal, in your case most likely $Signal_P.raw unless there is an ambiguity in the signal name.

    buffer will contain the description retVal can be used for error checking