?? compilation.c
字號:
/****************************************************************************
Example using RT-LAB API.
Gives the main step in order to compile a model.
*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Header for getcwd() is platform-dependent
#if defined(WIN32)
#include <direct.h>
#elif defined(__linux__)
#include <unistd.h>
#define _MAX_PATH 256
#endif
#include "OpalApi.h"
#define FALSE 0
#define TRUE 1
void PrintError(int rc, char *funcName);
int main(void)
{
char modelName[_MAX_PATH] = "compilation.mdl";
char modelPath[_MAX_PATH];
char modelPathName[_MAX_PATH*2];
#if defined(WIN32)
char relativePath[] = "\\..\\models\\simulink\\";
#elif defined(__linux__)
char relativePath[] = "/../models/simulink/";
#endif
int rc;
unsigned int option;
unsigned short compilationStatus, displayId;
char displayBuf[512];
if (NULL != getcwd(modelPath, sizeof(modelPath))
&& (strlen(modelPath) + strlen(relativePath) < _MAX_PATH))
{
strcat(modelPath, relativePath);
}
else
{
PrintError(0, "Invalid path");
return 1;
}
// Set current model
strcpy(modelPathName, modelPath);
strcat(modelPathName, modelName);
rc = OpalSetCurrentModel(modelPathName, NULL);
if(EOK != rc)
{
PrintError(rc, "OpalSetCurrentModel");
return(rc);
}
printf("- Setting of model '%s' is completed.\n", modelName);
// Compile the model
rc = OpalRegisterDisplay(DISPLAY_REGISTER_ALL);
if(rc != EOK)
{
PrintError(rc, "OpalRegisterDisplay");
OpalDisconnect();
return rc;
}
option = OP_SEPARATE_ONLY |
OP_GENERATE_ONLY |
OP_TRANSFER_ONLY |
OP_COMPIL_ONLY |
OP_RETRIEVE_FILES_ONLY;
rc = OpalStartCompile(option);
if(rc != EOK)
{
PrintError(rc, "OpalStartCompile");
OpalDisconnect();
return rc;
}
compilationStatus = FALSE;
while(compilationStatus != TRUE)
{
rc = OpalDisplayInformation(displayBuf, 512, OP_API_INFINITE, &compilationStatus, &displayId);
if(rc != EOK)
{
PrintError(rc, "OpalDisplayInformation");
OpalDisconnect();
return rc;
}
printf("%s",displayBuf);
}
rc = OpalRegisterDisplay(DISPLAY_UNREGISTER);
if(rc != EOK)
{
PrintError(rc, "OpalRegisterDisplay");
OpalDisconnect();
return rc;
}
printf("- Model %s is compiled.\n", modelName);
// Disconnect from the model
OpalDisconnect();
printf("- Model %s is disconnected.\n", modelName);
return 0;
}
void PrintError(int rc, char *funcName)
{
char buf[512];
unsigned short len;
OpalGetLastErrMsg(buf, sizeof(buf), &len);
printf("Error %s (code %d) from %s\n", buf, rc, funcName);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -