Changes between Version 1 and Version 2 of PacpusTutorials/ManagingDbtFiles
- Timestamp:
- Apr 15, 2014, 3:37:31 PM (11 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
PacpusTutorials/ManagingDbtFiles
v1 v2 70 70 }}} 71 71 72 After we open the DBT file in writing mode with this code: 72 After we open the DBT file in writing mode with the open method that takes in parameters: 73 - the name of the DBT file 74 - the management mode of DBT file (WriteMode, ReadMode) 75 - the ID of data 76 - the size of the data structure 73 77 74 78 {{{ … … 77 81 dbtFile_.open("my_struct_file.dbt", WriteMode, FILE_MYSTRUCT, sizeof(MYSTRUCT)); 78 82 } catch (DbiteException & e) { 79 cerr << "error opening dbt file: "<< kSickDbtFileName << ", " << e.what() << endl;83 cerr << "error opening dbt file: my_struct_file.dbt, " << e.what() << endl; 80 84 return; 81 85 } 82 86 }}} 83 87 84 The my_struct_file.dbt file will be created in current path of the application (often it is the folder where you launched the applicationPacpusSensor).88 The my_struct_file.dbt file will be created in the current path of the application (often it is the folder where you have launched the application !PacpusSensor). 85 89 90 === step 3: writing data in DBT file === 91 92 {{{ 93 #!cpp 94 95 MYSTRUCT data; 96 data.data1 = 22; 97 data.data2 = 42; 98 data.data3 = 11; 99 100 road_time_t time = road_time(); // the timestamp of the data 101 road_timerange_t timerange = 0; // if not use, please set the value to 0 102 103 try { 104 dbtFile_.writeRecord(time, timerange, (char *) &data, sizeof(data)); 105 } catch (DbiteException & e) { 106 cerr << "error writing data: " << e.what() << endl; 107 return; 108 } 109 }}} 110 111 === step 4: closing DBT file === 112 113 At the end of your program don't forget to close correctly the DBT file: 114 {{{ 115 #!cpp 116 117 dbtFile_.close(); 118 119 }}}