Skip to content

Commit

Permalink
Update to new version
Browse files Browse the repository at this point in the history
- Updated data type constants
- TDMS_GenerateGroupPath() and TDMS_GenerateChannelPath() have been streamlined
- Object add functions updated
- User can add property to the file, groups and channels using TDMS_AddPropertyToFile(),  TDMS_AddPropertyToGroup() and TDMS_AddPropertyToChannel functions.
  • Loading branch information
Hossein-M98 committed May 17, 2023
1 parent 0c3b8f5 commit 27f9afd
Show file tree
Hide file tree
Showing 4 changed files with 570 additions and 428 deletions.
164 changes: 110 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,23 @@ TDMS_Channel_t Channel1Group1;
```
4. Create File, Channel Group and Channel objects. For example:
```C
if (TDMS_CreateFile("File Description",
"File Title",
"File Author",
&FileTDMS) != TDMS_OK)
if (TDMS_InitFile(&FileTDMS) != TDMS_OK)
printf("Create file failed!");

if (TDMS_AddGroup(&FileTDMS,
"Group 1 name",
"Group 1 Description",
&Group1) != TDMS_OK)
if (TDMS_AddGroupToFile(&Group1,
&FileTDMS,
"Group 1 name") != TDMS_OK)
printf("Add Group failed!");

if (TDMS_AddChannel(&Group1,
tdsTypeU8,
"Channel 1 name",
"Channel 1 Description",
"Channel 1 unit",
&Channel1Group1) != TDMS_OK)
if (TDMS_AddChannelToGroup(&Channel1Group1,
&Group1,
"Channel 1 name",
TDMS_DataType_U8) != TDMS_OK)
printf("Add Channel 1 failed!");
```
5. Generate first part of file with `TDMS_GenFirstPart` and save the out buffer on disk.
6. Add data to Channels with `TDMS_SetChannelDataValues` or add data to all Channels of a Channel Group with `TDMS_SetGroupDataValues` then save the out buffer on disk.
6. Add properties to File, Channel Group or Channel with `TDMS_AddPropertyToFile`, `TDMS_AddPropertyToGroup` or `TDMS_AddPropertyToChannel` then save the out buffer on disk.
7. Add data to Channels with `TDMS_SetChannelDataValues` or add data to all Channels of a Channel Group with `TDMS_SetGroupDataValues` then save the out buffer on disk.
## Example
```C
Expand Down Expand Up @@ -72,56 +67,118 @@ int main()
uint8_t *Buffer;
uint32_t Size = 0;
MyFile = fopen("./output/Test.tdms", "wb");
MyFile = fopen("./Test.tdms", "wb");
if (!MyFile)
{
printf("File open failed!\n");
char ch;
scanf("%c", &ch);
return (1);
}
if (TDMS_CreateFile("File Description",
"File Title",
"File Author",
&FileTDMS) != TDMS_OK)
printf("Create file failed!");
if (TDMS_InitFile(&FileTDMS) != TDMS_OK)
printf("Init file failed!");
if (TDMS_AddGroup(&FileTDMS,
"Group 1 name",
"Group 1 Description",
&Group1) != TDMS_OK)
printf("Add Group failed!");
if (TDMS_AddGroup(&FileTDMS,
"Group 2 name",
"Group 2 Description",
&Group2) != TDMS_OK)
printf("Add Group failed!");
if (TDMS_AddChannel(&Group1,
tdsTypeU8,
"Channel 1 name",
"Channel 1 Description",
"Channel 1 unit",
&Channel1Group1) != TDMS_OK)
if (TDMS_AddGroupToFile(&Group1,
&FileTDMS,
"Group 1 name") != TDMS_OK)
printf("Add Group 1 failed!");
if (TDMS_AddGroupToFile(&Group2,
&FileTDMS,
"Group 2 name") != TDMS_OK)
printf("Add Group 2 failed!");
if (TDMS_AddChannelToGroup(&Channel1Group1,
&Group1,
"Channel 1 name",
TDMS_DataType_U8) != TDMS_OK)
printf("Add Channel 1 failed!");
if (TDMS_AddChannel(&Group1,
tdsTypeSingleFloat,
"Channel 2 name",
"Channel 2 Description",
"Channel 2 unit",
&Channel2Group1) != TDMS_OK)
if (TDMS_AddChannelToGroup(&Channel2Group1,
&Group1,
"Channel 2 name",
TDMS_DataType_SingleFloat) != TDMS_OK)
printf("Add Channel 2 failed!");
if (TDMS_AddChannel(&Group2,
tdsTypeTimeStamp,
"Channel 1 name",
"Channel 1 Description",
"Channel 1 unit",
&Channel1Group2) != TDMS_OK)
printf("Add Channel 4 failed!");
if (TDMS_AddChannelToGroup(&Channel1Group2,
&Group2,
"Channel 3 name",
TDMS_DataType_TimeStamp) != TDMS_OK)
printf("Add Channel 3 failed!");
TDMS_GenFirstPart(&FileTDMS, NULL, &Size);
Buffer = MEMALLOC(Size + 1);
TDMS_GenFirstPart(&FileTDMS, Buffer, &Size);
fwrite(Buffer, 1, Size, MyFile);
free(Buffer);
TDMS_AddPropertyToFile(NULL,
&Size,
"Description",
TDMS_DataType_String,
"A file generated by TDMS library");
Buffer = MEMALLOC(Size + 1);
TDMS_AddPropertyToFile(Buffer,
&Size,
"Description",
TDMS_DataType_String,
"A file generated by TDMS library");
fwrite(Buffer, 1, Size, MyFile);
free(Buffer);
TDMS_AddPropertyToFile(NULL,
&Size,
"Author",
TDMS_DataType_String,
"Hossein-M98");
Buffer = MEMALLOC(Size + 1);
TDMS_AddPropertyToFile(Buffer,
&Size,
"Author",
TDMS_DataType_String,
"Hossein-M98");
fwrite(Buffer, 1, Size, MyFile);
free(Buffer);
TDMS_AddPropertyToGroup(&Group1,
NULL,
&Size,
"Description",
TDMS_DataType_String,
"This is Group 1");
Buffer = MEMALLOC(Size + 1);
TDMS_AddPropertyToGroup(&Group1,
Buffer,
&Size,
"Description",
TDMS_DataType_String, "This is Group 1");
fwrite(Buffer, 1, Size, MyFile);
free(Buffer);
TDMS_AddPropertyToChannel(&Channel1Group2,
NULL,
&Size,
"Description",
TDMS_DataType_String,
"This is a Date and Time channel");
Buffer = MEMALLOC(Size + 1);
TDMS_AddPropertyToChannel(&Channel1Group2,
Buffer,
&Size,
"Description",
TDMS_DataType_String,
"This is a Date and Time channel");
fwrite(Buffer, 1, Size, MyFile);
free(Buffer);
uint8_t Data[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14};
float Data2[] = {100.25, 101.5, 102.75, 103.25, 104.5, 105.75};
TDMS_SetGroupDataValues(&Group1, NULL, &Size,
Expand All @@ -134,7 +191,7 @@ int main()
fwrite(Buffer, 1, Size, MyFile);
free(Buffer);
uint64_t second = TDMS_TimeSecond(2021, 2, 22, 10, 0, 0);
uint64_t second = TDMS_TimeSecond(2023, 5, 17, 12, 14, 10);
TDMS_Timestamp_t Data4[] = {{.Fraction = 0, .Second = second}};
TDMS_SetChannelDataValues(&Channel1Group2, NULL, &Size,
Data4, sizeof(Data4) / sizeof(TDMS_Timestamp_t));
Expand All @@ -144,7 +201,6 @@ int main()
fwrite(Buffer, 1, Size, MyFile);
free(Buffer);
fclose(MyFile);
return (0);
}
Expand Down
Loading

0 comments on commit 27f9afd

Please sign in to comment.