Skip to main content

Code Editor

1. Open the Code Editor

  • Click the Memu > Tools > Code Editor to open the Code Editor. alt text
  • ETStudio provides some examples about the C mini program, you can open them via the Example button in the Code Editor page.

2. Create or Open an exiting C mini Program Project

2.1 Create/Open a new project

From the Code Editor page, click the File > Open Folder... to open the folder selector dialog. And then choise the folder where the C mini Program Project is located or you want to save it to. alt text

2.2 Create a new file(*.c or *.cpp)

  1. Create a main code file
    • alt text
    • From the Code Editor page, click the folder of you project in the left panel to open the file tree, then click create file button and enter the file name to create a .c or .cpp file. And the file will be the main code file of the project.
      • The main code file needs to include the BaseMiniProgram.h header file, and it must include at least three functions: void PreviewApplicationInitialize(), void MainTest(), and void MainTestFinalized().
      #include "BaseMiniProgram.h"
      #include <stdio.h>

      int value = 0;
      int step = 1;
      uint8_t data[1] = {0x01};
      void UpdateSysVar()
      {
      data[0] += step;
      if (data[0] >= 9)
      {
      step = -1;

      }
      else if (data[0] <= 1)
      {
      step = 1;
      }

      CAN_Tx(1, 0x1F0, 1, data);
      }

      void PreviewApplicationInitialize()
      {
      }

      void onRX(EM_ReceiveFrame_t const* msg)
      {
      cnamespace::doubleValue = (double)(msg->data[0])*1.5;
      double doubleValue = cnamespace::doubleValue;
      char Buffer[200];
      snprintf(Buffer,200,"doubleValue = %f",doubleValue);
      show_console_message(Buffer);
      }
      void MainTest()
      {
      register_MainFunction(100, UpdateSysVar);
      register_CANRxEvent(1, 0x1F0, onRX);
      }

      void MainTestFinalized()
      {

      }

2.3 Configure extended include and library path

  1. env_vars.txt: INCLUDE_PATH and LIBRARY_PATH
  2. EXTENDED_LIBRARY_PATH=-lcjson -L"<search path of the library files eg. C:\cJSON\lib>" -lws2_32
  3. EXTENDED_INCLUDE_PATH=-I"C:\cJSON\include"

3. Edit code

  1. You can edit the code in the code editor.
  2. The editor provides function hints during code editing.
    • alt text
    • alt text
    • alt text

4. Build C mini program

4.1 Open the c mini program file (the *.c or *.cpp file) in the code editor.

4.2 From Terminal > Run Task... > click the Build C mini Programe files button in the code editor to build the project.

  1. alt text
  2. alt text
  3. alt text

4.3 If the build is successful, it will output Build successful!.

alt text

5. Execute C mini program

note

Before running C mini program, you need to Build C mini program first.

  1. Open the c mini program file (the *.c or *.cpp file) in the code editor.
  2. From Terminal > Run Task... > click the Execute C mini Programe files button in the code editor to run the project. alt text
note

You need to click the Start Measurement before running the C mini program.

alt text 3. C mini program is running alt text

6. Stop C mini program

From Terminal > Run Task... > click the Stop C mini Programe button in the code editor to stop the C mini program. alt text

7. Programming Help

7.1 APIs

7.2 Examples of the C mini program

  • Examples can be found from here alt text

8. Limitations

Do not assign values to global variables by calling C Mini Program API functions. For example, the situation shown below will cause the C Mini Program to fail to run properly: alt text. You should do it like this: alt text.