Using DWDAtaReaderLib
Hi,
I'm a developer, my name is Gaojianjun. By using DWDataReaderLib, I have a few quesions. Can you help me?
1. How to get every channel's sample rate in dxd or d7d file?
2. Using the win32&64 C example to read d7d or dxd file, the channel's Scale is different from open it in Dewesoft Application.For example AI 0 channel's Scale is 5,but DReader_c_win.exe read it is 0.0003,in XML node is ...<Scale>5</Scale>.
3. Using DWAddReader/DWSetActiveReader can open multiple file, but how to close one opened file and keep other still opened? The DWCloseDataFile() close all file or close the active file? If it close active file the other file which index above it is decrement 1 ?
Software engineer
Hi Gaojianjun,
I assume you are using DWDataReaderExample.c, right?Ok, here are my answers:
1. How to get every channel's sample rate in d7d or dxd file?
Currently you cannot get it directly. But there is a workaround. You can use this code to get the XML of the channel:
max_len = sizeof(int);
ret_buff = malloc(max_len);
DWGetChannelProps(ch_list[i].
xml_props_len = *(int*)ret_buff;
free(ret_buff);
// channel's XML properties
if (xml_props_len > 0)
{
ret_buff = malloc(xml_props_len);
memset(ret_buff, 0, xml_props_len);
DWGetChannelProps(ch_list[i].
printf("\nXML properties=\n%s\n\n", (char*)ret_buff);
free(ret_buff);
}
If the SRDiv node is available in the XML then the channel's rate is fi.sample_rate / SRDiv.
If SRDiv node is not available then SRDiv is 1 (default) and channel's rate is fi.sample_rate.
fi.sample_rate is global rate defined in the beginning of the source code of DWDataReaderExample.c.
2. Using the win32&64 C example to read d7d or dxd file, the channel's Scale is different from open it in Dewesoft Application. For example AI 0 channel's Scale is 5,but DReader_c_win.exe read it is 0.0003,in XML node is ...<Scale>5</Scale>.
Well, maybe the scale in DWDataReader is calculated some other way. I, again, suggest reading the XML node of the channel and reading scale there. See the item 1.
3. Using DWAddReader/DWSetActiveReader can open multiple file,but how to close one opened file and keep other still opened?the DWCloseDataFile() close all file or close the active file? If it close active file the other file which index above it is decrement 1 ?thanks
DWCloseDataFile() will close the active file and clear it's structures. It will not change the index. If you have two data files (index 0 and index 1) in list and close the first one the second one will still have index 1. Please take a look at the code below. I reduced it so you get a clear picture what DWCloseDataFiles() does.
for (...)
{
DWAddReader(); // adds a new reader
DWGetNumReaders(&num_readers);
if ((file_index >= 0) && (file_index < num_readers))
{
DWSetActiveReader(file_index); // sets the active reader
}
// ... add your own code here
if (DWCloseDataFile() != DWSTAT_OK) // close active reader
printf("\nERROR: DWCloseDataFile\n");
}
if (DWDeInit() != DWSTAT_OK) // clear dll
printf("\nERROR: DWDeInit\n");
if (CloseDWDLL() == 0) // close dll
printf("\nERROR: CloseDWDLL\n");