Using Enhanced Input/Output Functionality

This exercise demonstrates how to display information to and capture input from a test operator using the INPUTBOX, PRINT_FORMAT and MESSAGEBOX XJEase functions. It will build on the completed tutorial project; this starting project is installed as a zip file: CompletedTutorial4.zip.

  • Extract the zip file CompletedTutorial4.zip to a new, empty directory of your choice.
  • Navigate to the Board Test directory.
  • Open the XJDemo Board.xjd project from the extracted files, using XJDeveloper.

XJEase functions can be written in Test Device Files or Circuit Code Files. The functions you will use in this exercise will be added to a new Circuit Code File that you will add to the project.

  • Click the Circuit Code Files screen button under the Setup header.
  • Click the Add... button at the top of the Navigator area and click New..., then enter the name SerialNo.
  • Click Save to create the Circuit Code File.

The new Circuit Code File has been generated with an empty function to which you can add your own test code. This function can then be added to your XJRunner Test List.

For this exercise you are not going to use this function; however it will not cause any problems so it can just be left in the file.


INPUTBOX

In XJEase the INPUTBOX function displays a pop-up dialog that is used to get text input from the operator. The function you are going to create will get the input from the user and validate that the value entered is six characters long. When a valid value is entered it will then be written into the I2C EEPROM (U5) on the XJDemo board.

The INPUTBOX function can be used as an expression or a statement. In this exercise it will be called as a statement, which allows a second value to be returned to indicate whether the operator pressed the Cancel button.

  • Copy the code below and paste it into SerialNo.xje.
GLOBAL NEW_SERIAL_NUMBER()(INT result)
  STRING serialNo;
  INT i, data, cancelled, retry;

  DO
  WHILE TRUE
    INPUTBOX("Please enter board serial number (6 characters)", "Serial Number", "")(serialNo, cancelled);
    IF cancelled THEN
      EXIT;
    END;
    IF WIDTHOF(serialNo) != 6 THEN // check String is 6 characters long
      retry := MESSAGEBOX("Invalid Serial Number", "Board Serial Number", MB_ICON_ERROR, MB_BUTTONS_RETRY_CANCEL);
      IF retry = MB_BUTTON_CANCEL THEN
        EXIT;
      END;
    ELSE
      BREAK;
    END;
  END;

  FOR i := 0 TO 5
    CALL("U5", "WriteMemory")(i, 1, ASC(serialNo[i]))(result);
  END;

  SERIAL_NUMBER := serialNo;
  result := RESULT_PASS;
END;
  • Click the Save button in the Circuit Code Files section of the screen.

N.B. Remember that you can get full help on any XJEase keyword by highlighting it in the XJEase code editor and pressing F1 to open the relevant help page.

Before you can run the NEW_SERIAL_NUMBER function it first needs to be added to the XJRunner Test List.

  • Click the XJRunner Setup screen button under the Run and Deploy header.
  • Click Add Group... at the bottom of the XJRunner Tests section.
  • Set the Name of the test to Enter Board Serial Number.
  • Click the Add Global Function button.
  • From the Available Global Functions dialog select NEW_SERIAL_NUMBER then click OK.
  • Click OK in the New Test Group dialog to confirm the creation of the test.
  • Click the Save button on the main XJDeveloper toolbar.

The test is now ready to run.

  • Click the Run Tests screen button under the Run and Deploy header.
  • Select just the Enter Board Serial Number group from the test list.
  • Next click the Run button.
  • Enter a serial number then click the OK button.

If you enter a six character serial number it will be accepted and written into the EEPROM. If you enter a serial number of a different length you will be prompted to retry. If you click Cancel at any point testing will EXIT.


PRINT_FORMAT

You are now going to create a function which reads the serial number out of the EEPROM and prints it to the screen using the PRINT_FORMAT function.

PRINT_FORMAT is very similar to the simple PRINT function. There is one extra STRING argument which allows you to define the font, size and colour that should be used when displaying the text.

  • Click the Circuit Code Files screen button under the Setup header.
  • SerialNo.xje should still be open.
  • Copy the code below and paste it at the bottom of SerialNo.xje.
GLOBAL ReadSerialNo()(INT result)
  CONST STRING INFO_STYLE := "font=Comic Sans MS,size=170%, colour=Blue";
  CONST STRING ALERT_STYLE := "font=Courier New,size=120%, colour=Fuchsia";
  INT i,data;

  PRINT_FORMAT(INFO_STYLE, "Board Serial Number: ");
  FOR i := 0 TO 5
    CALL("U5", "ReadMemory")(i, 1)(data, result);
    PRINT_FORMAT(ALERT_STYLE, CHAR(data));
  END;
  PRINT("\n");
END;
  • Click the Save button in the Circuit Code Files section of the screen.

This function also needs to be added to the XJRunner Test List.

  • Click the XJRunner Setup screen button under the Run and Deploy header.
  • Click Add Group... at the bottom of the XJRunner Tests section.
  • Set the Name of the test to Read the Board Serial Number.
  • Click the Add Global Function button.
  • From the Available Global Functions dialog select ReadSerialNo then click OK.
  • Click OK in the New Test Group dialog to confirm the creation of the test.
  • Click the Save button on the main XJDeveloper toolbar.

The test is now ready to run.

  • Click the Run Tests screen button under the Run and Deploy header.
  • Select just the Enter Board Serial Number and Read the Board Serial Number groups from the test list.
  • Next click the Run button.

MESSAGEBOX and MESSAGEBOX_ASYNC

There are two types of message box that can be displayed from XJEase: the standard MESSAGEBOX will stop code from being executed until the test operator clicks on one of the buttons. MESSAGEBOX_ASYNC will display a message box but XJEase execution will continue to run. The button that is clicked can be captured later using GETKEY.

The function you will create demonstrates how both types of message box can be used.

  • Click the Circuit Code Files screen button under the Setup header.
  • SerialNo.xje should still be open.
  • Copy the code below and paste it at the bottom of SerialNo.xje.
GLOBAL MessageBoxDemo()(INT result)
  CONST STRING ALERT_STYLE := "font=Courier New, size=1000%, colour=Blue";
  INT mbButton, count := 0;

  mbButton := MESSAGEBOX("Do you want to continue?", "MESSAGEBOX Demo", MB_ICON_QUESTION, MB_BUTTONS_YES_NO);
  IF mbButton = MB_BUTTON_YES THEN
    PRINT("Test Continuing\n");
  ELSE
    PRINT("Test Stopping\n");
    result := RESULT_FAIL;
    RETURN;
  END;

  MESSAGEBOX_ASYNC("Is the display counting?", "MESSAGEBOX_ASYNC Demo", MB_ICON_QUESTION, MB_BUTTONS_YES_NO);

  DO
    SLEEP(100);
    PRINT("\r");
    PRINT_FORMAT(ALERT_STYLE, count);
    mbButton := GETKEY();
    IF count < 999 THEN
      count := count + 1;
    ELSE
      count := 0;
    END;
  WHILE mbButton = 0
  END;

  IF mbButton = MB_BUTTON_YES THEN
    result := RESULT_PASS;
  ELSE
    result := RESULT_FAIL;
  END;
END;
  • Click the Save button in the Circuit Code Files section of the screen.

With this function added to SerialNo.xje, the final step before it can be run is to add it to the XJRunner Tests list.

  • Click the XJRunner Setup screen button under the Run and Deploy header.
  • Click Add Group... at the bottom of the XJRunner Tests section.
  • Set the Name of the test to MessageBox Demonstration.
  • Click the Add Global Function button.
  • From the Available Global Functions dialog select MessageBoxDemo then click OK.
  • Click OK in the New Test Group dialog.
  • Click the Save button on the main XJDeveloper toolbar.

The test is now ready to run.

  • Click the Run Tests screen button under the Run and Deploy header.
  • Select just the MessageBox Demonstration group from the test list.
  • Next click the Run button.

You can see with a standard MESSAGEBOX that the code stops until the user clicks one of the buttons. The code then checks which for those buttons was clicked and either continues or exits . The MESSAGEBOX_ASYNC displays the message pop-up but allows the code continue running. In this case the code enters a loop, executing instructions until the user clicks a button.

See Also