question

Jose Sousa avatar image
0 Likes"
Jose Sousa asked

How to create my own variables to pass as parameters to a defined function?

I have a .dll that I made to read data from flexsim and send it to a sqlite database while a simulation is running. This is the function that i call in a flexsim trigger:

  1. __declspec(dllexport) int InsertDb(int runNumber, double time, const char* dataKey, const char* dataValue) {
  2.  
  3.  
  4.     sqlite3* db;
  5.     char* errMsg = 0;
  6.     char sql[1000];
  7.  
  8.  
  9.     int rc = sqlite3_open("path/to/database.db", &db);
  10.     if (rc != SQLITE_OK) {
  11.         fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
  12.         return rc;
  13.     }
  14.  
  15.  
  16.     snprintf(sql, sizeof(sql),
  17.         "INSERT INTO SimulationData (RunNumber, Time, DataKey, DataValue) VALUES (%d, %f, '%s', '%s');",
  18.         runNumber, time, dataKey, dataValue);
  19.  
  20.  
  21.     rc = sqlite3_exec(db, sql, NULL, NULL, &errMsg);
  22.     if (rc != SQLITE_OK) {
  23.         fprintf(stderr, "SQL error: %s\n", errMsg);
  24.         sqlite3_free(errMsg);
  25.     }
  26.  
  27.  
  28.     sqlite3_close(db);
  29.     return rc;
  30. }
  31.  

When i run the simulation everything works, but, as you can imagine, the records inside the database are all empty. Thats because im struggling to find a way to fill these parameters:

  1. (RunNumber, Time, DataKey, DataValue)
  • RunNumber
    • The number of the simulation running
  • Time
    • Timestamp of when the simulation started
  • DataKey
    • The name of the current component where the box is
  • DataValue
    • The trigger event thats happening (like a short description, eg. "Item entered on Processor")


I want to fill those values dinamically but i cant find a way to make it.

FlexSim 25.0.2
databaseexport datavariablesdll cflexsim25
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

0 Answers