Method SaveDataAsync
Namespace: Belay.Core.Examples
Assembly: Belay.Core.dll
SaveDataAsync()
Save current data buffer and statistics to persistent storage. This runs after stopping threads but before hardware cleanup.
csharp
[Teardown(Order = 2, IgnoreErrors = true)]
[PythonCode("\n import json\n import time\n \n try:\n # Save data buffer if it exists\n if 'data_buffer' in globals() and data_buffer:\n backup_data = {\n 'readings': data_buffer,\n 'statistics': {\n 'totalReadings': globals().get('reading_count', 0),\n 'totalErrors': globals().get('error_count', 0),\n 'lastDisconnect': time.ticks_ms()\n }\n }\n \n with open('sensor_backup.json', 'w') as f:\n json.dump(backup_data, f)\n \n print(f'Saved {len(data_buffer)} readings to backup file')\n \n # Save device status\n status = {\n 'lastDisconnect': time.ticks_ms(),\n 'cleanShutdown': True,\n 'readingCount': globals().get('reading_count', 0),\n 'errorCount': globals().get('error_count', 0)\n }\n \n with open('device_status.json', 'w') as f:\n json.dump(status, f)\n \n except Exception as e:\n print(f'Data save warning: {e}')\n ", EnableParameterSubstitution = false)]
Task SaveDataAsync()