Main Content

configureCallback

(Removed) Set callback function and trigger condition for communication with VISA resource

Since R2021a

    As of R2022a, callback functions for the visadev interface have been removed. The configureCallback function and the NumBytesAvailable, BytesAvailableFcnMode, BytesAvailableFcnCount, and BytesAvailableFcn properties are no longer supported for visadev objects.

    Description

    example

    configureCallback(v,"terminator",callbackFcn) sets the callback function callbackFcn to trigger whenever a terminator is available to be read from the VISA resource v. The syntax sets the BytesAvailableFcnMode property of v to "terminator" and the BytesAvailableFcn property to callbackFcn.

    Set the terminator character using configureTerminator.

    example

    configureCallback(v,"byte",count,callbackFcn) sets the callback function callbackFcn to trigger whenever a new count number of bytes are available to be read. The syntax sets the BytesAvailableFcnMode property of v to "byte", the BytesAvailableFcnCount property to count, and the BytesAvailableFcn property to callbackFcn.

    example

    configureCallback(v,"off") turns off callbacks. The syntax sets the BytesAvailableFcnMode property of v to "off".

    Examples

    collapse all

    Create a connection to a VISA resource. This example shows a connection to a device with the alias COM4 using the VISA-Serial interface.

    v = visadev("COM4");

    Set the callback to trigger when a terminator is available to be read.

    configureCallback(v,"terminator",@callbackFcn)

    View the properties to confirm the change.

    v.BytesAvailableFcnMode
    v.BytesAvailableFcn
    ans = 
    
        "terminator"
    
    
    ans =
    
      function_handle with value:
    
        @callbackFcn
    

    Turn the callback off.

    configureCallback(v,"off")

    Verify that the callback is off.

    v.BytesAvailableFcnMode
    ans = 
    
        "off"

    Create a connection to a VISA resource. This example shows a connection to a device with the alias COM4 using the VISA-Serial interface.

    v = visadev("COM4");

    Set the callback to trigger when 50 bytes of data are available to be read.

    configureCallback(v,"byte",50,@callbackFcn)

    View the properties to confirm the change.

    v.BytesAvailableFcnMode
    v.BytesAvailableFcnCount
    v.BytesAvailableFcn
    ans = 
    
        "byte"
    
    
    ans =
    
        50
    
    
    ans =
    
      function_handle with value:
    
        @callbackFcn
    

    Turn the callback off.

    configureCallback(v,"off")

    Verify that the callback is off.

    v.BytesAvailableFcnMode
    ans = 
    
        "off"

    Input Arguments

    collapse all

    VISA resource, specified as a visadev object.

    Example: configureCallback(v,"byte",128,@callbackFcn) sets the callbackFcn callback to trigger each time 128 bytes of new data are available to be read from the VISA resource v.

    Number of bytes of available data to trigger the callback, specified as a positive integer value. Set the BytesAvailableFcnCount property using this argument.

    Example: configureCallback(v,"byte",128,@callbackFcn) sets the callbackFcn callback to trigger each time 128 bytes of new data are available to be read.

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

    Callback function to run when trigger condition is met, specified as a function handle. The function handle can be a named function handle or an anonymous function with input arguments. Set the BytesAvailableFcn property using this argument.

    Example: configureCallback(v,"terminator",@callbackFcn) sets the callbackFcn callback to trigger when a terminator is available to be read.

    Data Types: function_handle

    Version History

    Introduced in R2021a

    expand all