#include <stdio.h>
#include <conio.h>
#include "VSPE_API.h"
#pragma comment(lib,"VSPE_API.lib")
int main()
{
const char* config_file_path = "1.vspe";
const char* activationKey = "";
bool result;
printf("%s\n",vspe_getVersionInformation());
result = vspe_activate(activationKey);
if(result == false){
printf("VSPE API activation error: %s", vspe_get_activation_error());
return 1;
}
result = vspe_initialize();
if(result == false){
printf("Initialization error");
return 1;
}
vspe_destroyAllDevices();
result = vspe_stopEmulation();
if(result == false)
{
printf("Error: emulation cannot be stopped: maybe one of VSPE devices is still used.");
vspe_release();
return 1;
}
int deviceId = vspe_createDevice("Connector", "9;0");
if(deviceId == -1)
{
printf("Error: cannot create device\n");
vspe_release();
return 1;
}
deviceId = vspe_createDevice("Splitter", "10;9;0;19200,0,8,1,0,0;0;0;0");
if(deviceId == -1)
{
printf("Error: cannot create device\n");
vspe_release();
return 1;
}
deviceId = vspe_createDevice("Pair", "21;22;0");
if(deviceId == -1)
{
printf("Error: cannot create device\n");
vspe_release();
return 1;
}
result = vspe_saveConfiguration(config_file_path);
if(result == false)
{
printf("Error: cannot save configuration");
vspe_release();
return 1;
}
result = vspe_loadConfiguration(config_file_path);
if(result == false)
{
printf("Error: cannot load configuration");
vspe_release();
return 1;
}
result = vspe_startEmulation();
if(result == false)
{
printf("Error: cannot start emulation");
vspe_release();
return 1;
}
int i, count = vspe_getDevicesCount();
for(i = 0;i<count;++i)
{
int ok, used;
const char* name, *initString;
int deviceId = vspe_getDeviceIdByIdx(i);
if(vspe_getDeviceInfo(deviceId, &name, &initString, &ok, &used))
{
printf("Detected device: %s (%s). Status: %s, Used: %s\n",
name, initString, ok == 1 ? "OK" : "ERROR",
used == 1 ? "YES" : "NO");
}
}
printf("Press any key to quit");
_getch();
result = vspe_stopEmulation();
if(result == false)
{
printf("Error: emulation cannot be stopped: maybe one of VSPE devices is still used.");
return 1;
}
vspe_release();
return 0;
}