?? basic_example1.c
字號:
/****************************************************************************
Example using RT-LAB API.
Gives the main step in order to connect and receive data from
a model.
*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <malloc.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"
void PrintError(int rc, char *funcName);
#define FALSE 0
#define TRUE 1
int main(void)
{
char modelName[_MAX_PATH] = "basic_example1.mdl";
int rc;
OP_API_INSTANCE_ID instId;
short state;
unsigned short realTimeMode;
/**************************************************************************
*
* CONNECTION STEP
*
***************************************************************************/
// The state's variable give the state of the model (loaded, running , ...)
rc = OpalConnectByName(modelName, NULL, TRUE, FALSE, FALSE, &instId, &state);
if(EOK != rc)
{
PrintError(rc, "OpalConnectByName");
return(rc);
}
printf("- The connection with '%s' is completed.\n", modelName);
switch(state)
{
case MODEL_PAUSED:
printf("- The model is paused.\n");
break;
case MODEL_RUNNING:
printf("- The model is running.\n");
break;
default:
break;
}
rc = OpalGetSystemControl(TRUE);
if(EOK != rc)
{
PrintError(rc, "OpalGetSystemControl");
return(rc);
}
printf("- The system control is acquired.\n");
// Verify that the model is running
if(state == MODEL_RUNNING)
{
rc = OpalPause();
if(EOK != rc)
{
PrintError(rc, "OpalPause");
return(rc);
}
}
else if(state == MODEL_PAUSED)
{
rc = OpalExecute(1.0);
if(EOK != rc)
{
PrintError(rc, "OpalExecute");
return(rc);
}
}
rc = OpalGetModelState(&state, &realTimeMode);
if(EOK != rc)
{
PrintError(rc, "GetModelState");
return(rc);
}
switch(state)
{
case MODEL_PAUSED:
printf("- The model is now paused.\n");
break;
case MODEL_RUNNING:
printf("- The model is now running.\n");
break;
default:
break;
}
rc = OpalGetSystemControl(FALSE);
if(EOK != rc)
{
PrintError(rc, "OpalGetSystemControl");
return(rc);
}
printf("- The system control is released.\n");
OpalDisconnect();
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);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -