Data Acquisition (DAQ) and Control from Microstar Laboratories

Knowledge Base: Applications

Q10121 Do I need special drivers to reload data I capture using my DAP board?

Tags: Help, MATLAB, applications, software environments, data logging

Applies to: All DAPL versions, all DAP models, all MATLAB versions, most software environments

I perform my post-processing analysis using MATLAB. Do I need special drivers to read a file of logged data that I captured using a Data Acquisition Processor?

Binary data logged to a file directly from a Data Acquisition Processor communication pipe will be in a format that MATLAB or any other software environment should have no trouble reading. You don't need any special drivers or conversion utilities to reload data that you stored previously.

For capturing the data stream, open a Windows file handle the normal "binary write" mode and write the data as the DAP sends it. The default data format, with 16-bit signed integer values, gives the most compact representation, and the best data transfer rates.

To load the data into MATLAB (or any other application environment), open a Windows file handle in the usual manner for "binary read" mode. In MATLAB, you have additional options to arrange the data into a matrix with rows representing channels and columns representing capture time. MATLAB converts the data into the appropriate internal data type automatically. Typical MATLAB m-script lines will look something like the following:

   % MATLAB --- Locate data file written by the data acquisition app
   fhandle  =  fopen('MyFileName.bin','int16')
   % Let MATLAB read and convert data to its internal format
   mydatamatrix  =  fread(fhandle,[4,100]);
   ...
   fclose(fhandle)

This is not much different from the way it is done in an ordinary programming language such as C++.

   // C++ --- Set up a storage buffer to receive data
   nterms = 400;
   pIntBuffer = malloc(nterms * sizeof(short int));
   fhandle  =  fopen("Path\To\File","rb")
   // Let C++ read the block of data in the original format
   fread(pIntBuffer, sizeof(short int), nterms, fhandle);
   ...
   fclose(fhandle);

The only reason that you might want to consider using special "drivers" — more specifically, the DAPtools for MATLAB API [1] — is when you need to bypass the intermediate logged data file and process data on-the-fly. The script is not a lot different, but it substitutes a DAP communication pipe handle for an ordinary file handle.

  % Set up communications
  dapdata = dapopen('//./Dap0/$binout', 'read')
  dapcmds = dapopen('//./Dap0/$sysin', 'write')

  % Tell the DAP board what you want it to send
  dapcnfig(dapcmds, 'DAPConfigFile.dap');

  % Fetch the data blocks in MATLAB matrix form
  mydatamatrix =  dapgetm(daphandle, [4,100], 'int16');
  ...

  % Close the communication channels
  dappstr(dapcmds,'RESET')
  dapclose(dapdata)
  dapclose(dapcmds)

The only hazard is that the data must be processed at "real time rates," and MATLAB is not a natural real-time environment. It must be scripted to read the data often enough to keep pace with the data that the DAP is configured to send.

There are some situations when it is better not to use the default data type for transfers; for example, when there is intensive pre-processing performed on-board, and a higher-precision data type is necessary to preserve information. Other data types can be configured in the DAP processing and the MATLAB environment for the transfers, but the two configurations must be consistent.

L 22371

[1] DAPtools for MATLAB is available with the DAPtools Software Standard and Professional Editions.