navFormReceiveField (Function)

Top  Previous  Next

Architecture:

NX32 / NX32L

Device support:

MX2 turbo/encore/warp, AX9 turbo, NX-200, NX-400, NX-900

Firmware version:

4.70 / 1.30.00

Nav. API level:

12


This function will read the ID and type of a field on a received form.

Note that the received form is only valid after a "Form received" event is raised; the event will not be removed until the navFormReceiveDone function is called.

 

This can be used to determine the available fields on the received form.

 

Input:

index : INT (1..30 , default 1)

Index of the field to get information about. The maximum index for the specific form can be read in navFormReceive.count.

 

Output:

id : DINT

The unique id of the field.

 

type : SINT

The type of field:

1

- Text field.

2

- Number field.

3

- Selection field with single selection.

4

- Selection field with multiple selections.

5

- Date

6

- Time

7

- Stop

 

 

Returns: INT

0

- Success.

-1

- Navigation interface is not open.

-3

- No received form could be found.

-7

- The field could not be found.

 

Declaration:

FUNCTION navFormReceiveField : INT;
VAR_INPUT
  index     : INT := 1;
  id         : ACCESS DINT;
  type       : ACCESS SINT;
END_VAR;

 

Example:

//-----------------------------------------------------------------------------
// form.vpl, created 2018-11-28 14:45
// Shows how to use navFormReceiveField to iterate through the received fields.
//-----------------------------------------------------------------------------
INCLUDE rtcu.inc
 
//  Input variables that can be configured via the configuration dialog (These are global)
VAR_INPUT
 
END_VAR;
 
//  Output variables that can be configured via the configuration dialog (These are global)
VAR_OUTPUT
 
END_VAR;
 
//  These are the global variables of the program
VAR
  msgSts         : navMessageStatusReceive;
  msgAck         : navMessageReplyReceive;  
  msgRec         : navMessageReceiveX;
  etaRec         : navETAReceive;
  userStatus     : navUserStatusReceive;
  stopRcv        : navStopReceive;
  userID         : navUserIDReceiveX;
  gpiRcv         : navGPIProgressReceive;
  formReceive    : navFormReceive;
  speedAlert     : navSpeedLimitAlert;
  clock          : clockLinsecToTime;
END_VAR;
 
// Definition of the field IDs
#DEFINE ID_NAME     1
#DEFINE ID_AGE       2
#DEFINE ID_OPTIONS   3
#DEFINE ID_DATE     4
#DEFINE ID_TIME     5
#DEFINE ID_STOP     6
 
// Option IDs
#DEFINE ID_OPT_1     1
#DEFINE ID_OPT_2     2
 
FUNCTION TimeString : STRING;
VAR_INPUT
  linsec : DINT;
END_VAR;
  clock(linsec := linsec);
  TimeString := strFormat(format := "\1.\2.\3, ", v1 := clock.day, v2 := clock.month, v3 := clock.year);
  TimeString := TimeString + strFormat(format := "\1:\2:\3", v1 := clock.hour, v2 := clock.minute, v3 := clock.second);
END_FUNCTION;
 
 
FUNCTION ReadGPIProgress;
  gpiRcv();
  IF gpiRcv.ready THEN
    DebugMsg(message := "*** progress received ***");
    DebugFmt(message := "-status=  \1", v1 := gpiRcv.status);
    DebugFmt(message := "-progress=\1", v1 := gpiRcv.progress);
    DebugFmt(message := "-type=    \1", v1 := gpiRcv.type);
    DebugFmt(message := "-error=   \1", v1 := gpiRcv.error);
  END_IF;
END_FUNCTION;
 
FUNCTION createForm:INT;
VAR
  rc: INT;
END_VAR;
  // Begin constructing the form.
  rc := navFormCreate(id := 7, title:="Form", version := 1);
  DebugFmt(message := "Form create=\1", v1 := rc);
 
  // Add fields to the form:
  rc := navFormAddText(id := ID_NAME, title:="Name", desc:="Your name",
                      placeholder := "<Name>", required := TRUE);
  DebugFmt(message := "Add text=\1", v1 := rc);
 
  rc := navFormAddNumber(id:=ID_AGE, title:="Age", desc:="Your age", placeholder:="<years>",
                      min_val:=0, max_val := 120, max_length := 3);
  DebugFmt(message := "Add number=\1", v1 := rc);
 
  rc := navFormAddSelect(id := ID_OPTIONS, title:="Options", desc:="Select the options", multi:=TRUE);
  DebugFmt(message := "Add select=\1", v1 := rc);
 
  rc := navFormAddOption(id:=ID_OPT_1, select_id:=ID_OPTIONS, title:="Option 1");
  DebugFmt(message := "Add option=\1", v1 := rc);
 
  rc := navFormAddOption(id:=ID_OPT_2, select_id:=ID_OPTIONS, title:="Option 2");
  DebugFmt(message := "Add option=\1", v1 := rc);
 
  rc := navFormAddDate(id:=ID_DATE, title:="Date");
  DebugFmt(message := "Add date=\1", v1 := rc);
 
  rc := navFormAddTime(id:=ID_TIME, title:="Time");
  DebugFmt(message := "Add time=\1", v1 := rc);
 
  rc := navFormAddStop(id:=ID_STOP, title:="Stop", desc:="Select the stop");
  DebugFmt(message := "Add stop=\1", v1 := rc);
 
 
  // Upload the form to the navitagion device
  rc := navFormupload();
  DebugFmt(message := "Upload=\1", v1 := rc);
             
END_FUNCTION;
 
 
FUNCTION FormSubmit;
VAR
  rc    : INT;
  i,o   : INT;
  str   : STRING;
  n     : DINT;
  linsec: DINT := 0;
  id    : DINT;
  stop  : INT;
  type  : SINT;
END_VAR;
  formReceive();
  IF(formReceive.ready) THEN
      DebugMsg(message := "*** form received ***");
      DebugFmt(message := "-ID=      \4", v4 := formReceive.id);
      DebugFmt(message := "-sub id=  \4", v4 := formReceive.submit_id);
      DebugFmt(message := "-version= \4", v4 := formReceive.version);
      DebugFmt(message := "-time=    "+TimeString( linsec := formReceive.time));
       
    IF(formReceive.id <> 7) THEN
          DebugFmt(message:="Unknown form ID \4", v4:=formReceive.id);
          rc := navFormReceiveDone();
          DebugFmt(message:="navFormReceiveDone: \1", v1:=rc);
          RETURN;
    END_IF;
       
    IF(formReceive.version <> 1) THEN
          DebugFmt(message:="Unknown form version \4", v4:=formReceive.version);
          rc := navFormReceiveDone();
          DebugFmt(message:="navFormReceiveDone: \1", v1:=rc);
          RETURN;
    END_IF;
     
     
    FOR i := 1 TO formReceive.count DO
        rc := navFormReceiveField(index := i, id := id, type :=type );
        DebugFmt(message:="navFormReceiveField(\2): \1, id \4, type \3",
        v1:=rc, v2:=i, v3:=type, v4:=id);
       
        CASE INT(id) OF
        ID_NAME:
          rc := navFormReceiveReadText(id := ID_NAME, text := str);      
          DebugFmt(message:="Read text: \1", v1:=rc);
          IF rc = 0 THEN
              DebugFmt(message:=" Name: "+str);
          END_IF;
        ID_AGE:
          rc := navFormReceiveReadNumber(id := ID_AGE, number := n);
          DebugFmt(message:="Read number: \1", v1:=rc);
          IF rc = 0 THEN
              DebugFmt(message:=" Age: \4", v4 := n);
          END_IF;
        ID_OPTIONS:
          FOR o := 1 TO 30 DO
              rc := navFormReceiveReadSelect(id := ID_OPTIONS, index:=o, option:=n);
              DebugFmt(message:="Read option \1: \2", v1:=o, v2:=rc);
              IF rc < 0 THEN
                EXIT;
              END_IF;
              IF n = ID_OPT_1 THEN
                DebugMsg(message:=" Option 1 selected");
              END_IF;
              IF n = ID_OPT_2 THEN
                DebugMsg(message:=" Option 2 selected");
              END_IF;
          END_FOR;
        ID_DATE:
          rc := navFormReceiveReadDateTime(id := ID_DATE, linsec := n);
          DebugFmt(message:="Read date: \1", v1:=rc);
          IF rc = 0 THEN
              DebugFmt(message:=" Date: \4", v4 := n);
              linsec := linsec + n;
          END_IF;
        ID_TIME:            
          rc := navFormReceiveReadDateTime(id := ID_TIME, linsec := n);
          DebugFmt(message:="Read time: \1", v1:=rc);
          IF rc = 0 THEN
              DebugFmt(message:=" Time: \4", v4 := n);
              linsec := linsec + n;
          END_IF;
        ID_STOP:      
          rc := navFormReceiveReadStop(id := ID_STOP, stop := stop);
          DebugFmt(message:="Read stop: \1", v1:=rc);
          IF rc = 0 THEN
              DebugFmt(message:=" Stop: \1", v1 := stop);
          END_IF;
        END_CASE;
    END_FOR;
    // Done with the form      
    rc := navFormReceiveDone();
    DebugFmt(message:="navFormReceiveDone: \1", v1:=rc);
  END_IF;
END_FUNCTION;
 
 
THREAD_BLOCK navMonitor;
VAR
  event : INT := 0;
  rc    : INT;
END_VAR;
 
  WHILE event <> -1 DO
    event := navWaitEvent(timeout := -1);
    DebugFmt(message := "navWaitEvent - event=\1", v1 := event);
    CASE event OF
    1:
        msgAck();  
        IF msgAck.ready THEN  
          DebugMsg(message := "*** message reply received ***");  
          DebugFmt(message := "-msgid=\1", v1 := msgAck.ID);  
          DebugMsg(message := "-time= "+TimeString(linsec:=msgAck.time));
          CASE msgAck.reply OF  
              1: DebugMsg(message := "-reply=[OK]");  
              2: DebugMsg(message := "-reply=[YES]");  
              3: DebugMsg(message := "-reply=[NO]");  
          ELSE  
              DebugFmt(message := "-reply=\1", v1 := msgAck.reply);  
          END_CASE;  
        END_IF;  
    2:
        msgRec();
        IF msgRec.ready THEN  
          DebugMsg(message := "*** message received ***");  
          DebugMsg(message := "-time="+TimeString(linsec:=msgRec.time));
          DebugFmt(message := "-last=\1", v1 := msgRec.id);
          DebugMsg(message := "-text=" + msgRec.message);  
        END_IF;  
 
    3:
        msgSts();  
        IF msgSts.ready THEN  
          DebugMsg(message := "*** message status received ***");  
          DebugFmt(message := "-msgid=\1", v1 := msgSts.ID);  
          CASE msgSts.status OF  
              1: DebugMsg(message := "-status=Unread");  
              2: DebugMsg(message := "-status=Read");  
              3: DebugMsg(message := "-status=Deleted/Not found");  
          ELSE  
              DebugFmt(message := "-status=\1", v1 := msgSts.status);  
          END_CASE;  
        END_IF;  
    4:
        etaRec();  
        IF etaRec.ready THEN
          DebugMsg(message := "*** ETA received ***");
          DebugFmt(message := "-time=     \4", v4 := etaRec.time);
          DebugFmt(message := "-distance= \4", v4 := etaRec.distance);
          DebugFmt(message := "-stop=     \1", v1 := etaRec.id);
          DebugFmt(message := "-latitude= \4", v4 := etaRec.latitude);
          DebugFmt(message := "-longitude=\4", v4 := etaRec.longitude);
        END_IF;
 
    5:
        stopRcv();  
        IF stopRcv.ready THEN  
          DebugMsg(message := "*** stop status received ***");  
          DebugFmt(message := "-stop=\1", v1 := stopRcv.ID);  
          DebugFmt(message := "-index=\1", v1 := stopRcv.index);  
          CASE stopRcv.status OF  
              1: DebugMsg(message := "-state=Active");  
              2: DebugMsg(message := "-state=Done");  
              3: DebugMsg(message := "-state=Unread - inactive");  
              4: DebugMsg(message := "-state=Read - inactive");  
              5: DebugMsg(message := "-state=Deleted/Not found");  
          ELSE  
              DebugFmt(message := "-state=\1", v1 := stopRcv.status);  
          END_CASE;  
        END_IF;  
    6:
        userID();
        IF userID.status > 0 THEN
          DebugMsg(message := "*** user ID received ***");
          DebugFmt(message := "-time=\4: "+TimeString( linsec :=userID.time), v4 := userID.time);
          DebugFmt(message := "-idx= \1", v1 := userID.index);
          DebugMsg(message := "-user=" + userID.user);
          DebugMsg(message := "-pass=" + userID.password);
        END_IF;
        IF userID.status = 2 THEN
          navUserIDAuthenticate(accept := TRUE);
        END_IF;
    7:
        userStatus();
        IF userStatus.ready THEN
          DebugMsg(message := "*** user status received ***");
          DebugFmt(message := "-time=\4: "+TimeString( linsec := userStatus.time), v4 := userStatus.time);
          DebugFmt(message := "-status=\1", v1 := userStatus.status);
        END_IF;
 
    8: DebugMsg(message := "GPI ID: " + navGPIReceiveID());
    9: ReadGPIProgress();
         
    14:
        FormSubmit();
       
    15:
        speedAlert();
        IF speedAlert.ready THEN
          DebugMsg(message := "*** Speed limit alert received ***");
          DebugFmt(message := "-time=       \4: "+TimeString( linsec := speedAlert.time), v4 := speedAlert.time);
          DebugFmt(message := "-type=       \1", v1 := speedAlert.type);
          DebugFmt(message := "-lat=        \4", v4 := speedAlert.latitude);
          DebugFmt(message := "-lon=        \4", v4 := speedAlert.longitude);
          DebugFmt(message := "-speed=      \1", v1 := speedAlert.speed);
          DebugFmt(message := "-speed limit=\1", v1 := speedAlert.speed_limit);
          DebugFmt(message := "-max speed=  \1", v1 := speedAlert.max_speed);
           
        END_IF;
       
    129: DebugMsg(message := "Request for refresh of quick messages");
    130: DebugMsg(message := "Request for refresh of message replies");
    131: DebugMsg(message := "Request for refresh of user status");
    132:  
          DebugMsg(message := "Navigation device present");
          DebugFmt(message:="version = \1", v1:=navVersion ());
          DebugFmt(message:="API     = \1", v1:=navGetAPILevel ());
          // Delete all forms from the navigation device
          navDeleteData(type := 10);
          // Create custom form
          createForm();
                   
    133: DebugMsg(message := "Navigation device not present");
 
    ELSE
        DebugFmt(message := "navWaitEvent - event=\1", v1 := event);
    END_CASE;
  END_WHILE;
END_THREAD_BLOCK;
 
PROGRAM form;
// These are the local variables of the program block
VAR
 
  rc     : INT;
  navMon : navMonitor;
 
END_VAR;
  // The next code will only be executed once after the program starts
 
  rc:= navOpen(port:=1);
  DebugFmt(message:="navOpen = \1", v1:=rc);
 
  // Start monitor thread
  navMon();
 
BEGIN
// Code from this point until END will be executed repeatedly
 
 
END;
 
END_PROGRAM;