Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Create Your Adaptor from the Demo Adaptor

Use the demo adaptor as a template for creating a custom adaptor which you can build, test, and access from the toolbox. The following sections provide a sequence of steps for adaptor modification. The examples in this topic create a custom adaptor named MyAdaptor with a vendor ID of my.

Edit and Build Your Adaptor

This section describes the step to make a new custom adaptor based on the shipped demo adaptor. This example modifies only the names of the adaptor, vendor, and devices, without any functional changes. You build the custom adaptor in a local folder, then add the build folders to the MATLAB path. This section uses two folder locations throughout:

LocationDescription
matlabrootMATLAB installation location. This is the MATLAB used both for the building of the adaptor, and for accessing the adaptor through a data acquisition session.
C:\adaptors\daqsdkLocal file location where the new adaptor is modified and built.
  1. Create the build area in a location of your choice. This example works with a new folder, C:\adaptors\daqsdk. Create a subfolder here called src, and within that a subfolder named daqadaptor.

  2. Copy the folder DemoAdaptor from matlabroot\toolbox\daq\daqsdk\src\daqadaptor into C:\adaptors\daqsdk\src\daqadaptor.

  3. Inside C:\adaptors\daqsdk\src\daqadaptor, rename the folder DemoAdapter to be MyAdaptor.

    Navigate into MyAdaptor, and rename three of its files according to the following table:

    Original NameNew Name
    custom_demo.cppcustom_my.cpp
    demoadaptor.cppmyadaptor.cpp
    demoadaptor.hppmyadaptor.hpp
  4. With a text editor, modify each of the three new files in the previous table, replacing all occurrences of text DemoAdaptor, demoadaptor, DemoDriver, and custom_demo.cpp with MyAdaptor, myadaptor, MyDriver, and custom_my.cpp, respectively, keeping the letter capitalization style with each replacement.

  5. Further edit the contents of myadaptor.cpp as shown in the following table:

    Original TextUpdated Text
    {
        shortName = "MW";
        fullName = "MathWorks";
        driverName = "DemoAdaptor";
    
        return DAQSuccess;
    }
    {
        shortName = "MY";
        fullName = "MyAdaptor";
        driverName = "MyDriver";
    
        return DAQSuccess;
    }
     prefix = "MWDev";
    prefix = "MyDev";

    With these modifications saved and in place, you are ready to build the adaptor.

  6. In MATLAB, run the following utility to build the executable MEX-file for MyAdaptor:

    daq.sdk.utility.mex.buildAdaptor('MyAdaptor','custom_my', ...
      'C:\adaptors\daqsdk\src\daqadaptor\MyAdaptor','C:\adaptors\daqsdk\bin\win64')

    The function input arguments specify the adaptor name, source code file, source file location, and where to put the built output.

    Note

    The buildAdaptor function requires that your system be configured with Microsoft® Visual Studio® 2013 or later.

  7. Create the folder C:\adaptors\daqsdk\+daq, and copy into it the folder +demoadaptor found at matlabroot\toolbox\daq\daqsdk\+daq\+demoadaptor.

  8. Navigate into C:\adaptors\daqsdk\+daq, and rename +demoadaptor to +myadaptor.

  9. Navigate into C:\adaptors\daqsdk\+daq\+myadaptor, and edit these two MATLAB files in that folder:

    Session.m
    VendorInfo.m
    • In both of these files, replace all occurrences of the texts DemoAdaptor and demoadaptor with MyAdaptor and myadaptor, respectively, keeping the letter capitalization style with each replacement.

    • In the VendorInfo file, use % characters to comment out the lines that hide the adaptor, between the begin and end remove indicators. The change looks like this:

      % BEGIN REMOVE
      %   if daq.internal.getOptions().HideDAQSDKAdaptor
      %      throw(MException(message('daqsdk:HardwareInfo:VendorIsHidden', mfilename('class'))));
      %   end
      % END REMOVE
    • Save and close the files.

    Your modified adaptor is now ready for use.

Use Your Adaptor in a Session

This example shows how to access the vendor and device represented by your modified adaptor. A data acquisition session with your adaptor allows you to add channels and get information from the device.

Start MATLAB, and use the following commands to make your adaptor available.

addpath 'C:\adaptors\daqsdk\bin\win64'
addpath 'C:\adaptors\daqsdk'

Then you can access your adaptor.

v = daq.getVendors
v = 

Number of vendors: 2

index     ID      Operational         Comment         
----- ----------- ----------- ------------------------
1     ni          false       Click here for more info
2     my          true        MyAdaptor

Use the index of the vendor ID my to get more information.

vendor = v(2)
vendor = 

Data acquisition vendor 'MyAdaptor':

            ID: 'my'
      FullName: 'MyAdaptor'
AdaptorVersion: '3.11 (R2017a)'
DriverVersion: '1.0.0'
IsOperational: true

Create a session for your device.

s = daq.createSession('my')
s = 

Data acquisition session using MyAdaptor hardware:
   Will run for 1 second (1000 scans) at 1000 scans/second.
   No channels have been added.
ch1 = addAnalogOutputChannel(s,'MyDev0','ao0','Voltage')
ch1 = 

Data acquisition analog output voltage channel 'ao0' on device 'MyDev0':

TerminalConfig: SingleEnded
          Range: -10 to +10 Volts
           Name: ''
             ID: 'ao0'
         Device: [1x1 daq.sdk.DeviceInfo]
MeasurementType: 'Voltage'
s
s = 

Data acquisition session using MyAdaptor hardware:
   No data queued.  Will run at 1000 scans/second.
   Number of channels: 1
      index Type Device Channel   MeasurementType        Range       Name
      ----- ---- ------ ------- ------------------- ---------------- ----
      1     ao   MyDev0 ao0     Voltage (SingleEnd) -10 to +10 Volts
whos
  Name      Size             Bytes  Class                                 Attributes

  ch1       1x1                  8  daq.sdk.AnalogOutputVoltageChannel
  s         1x1                  8  daq.myadaptor.Session
  v         1x2                 16  daq.VendorInfo
  vendor    1x1                  8  daq.myadaptor.VendorInfo

See Also

Functions

Related Examples

More About

Was this topic helpful?