Using DWDAtaReaderLib

User Question

Posted on 03.09.2015 08:22

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 ?

Thanks
Andrej Ikica
Software engineer
Posted on 03.09.2015 08:56

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:

// get length of XML properties
max_len = sizeof(int);
ret_buff = malloc(max_len);
DWGetChannelProps(ch_list[i].index, DW_CH_XMLPROPS_LEN, ret_buff, &max_len);
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].index, DW_CH_XMLPROPS, ret_buff, &xml_props_len);
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");

Login to reply to this topic. If you don't have account yet, you can signup for free account .