File Exchange Pick of the Week

Our best user submissions

Automatically Connect Sink Blocks To Existing Simulink Signals

For today's post, Brett and Jiro welcome guest blogger Greg Wolff.

Greg's pick of the week is SinkAutoConnect by Mike Anthony.

Many of you are aware that you can connect a Single-Input Single-Output block in Simulink by dropping the block onto an existing signal line. Wouldn't it be nice to be able to have the same type of feature for sink blocks such as scopes so you can easily drop sinks onto existing Simulink signals?

Mike Anthony has created the SinkAutoConnect function that when added to a Single-Input block's callback functions, will automatically connect the block to a signal line when you drop the block on an existing signal line.

When I am investigating the simulation results of Simulink models, it is convenient for me to quickly add scopes and outports to signals so I can log or inspect the results.


How The SinkAutoConnect Function Works

Mike takes advantage of the CopyFcn block callback function. This function is executed when a block is copied to a new location. This copy can be from one Simulink model (or library) to another model, or within the same model. The SinkAutoConnect function actually moves the block that you have dropped on the Simulink signal line, and then draws a new Simulink signal line from the new block location to the location where you dropped the block. This new signal line will automatically connect to the existing signal line, and create a branch point (also known as a solder joint).

Add the SinkAutoConnect Function to Your Sink Block

Once you have downloaded this function, it can be added to a single-input sink block by performing the following:
  • Add a single-input block to a model or library.
  • Right-click on the block to get the context menu and select Block Properties.
  • Select the Callbacks tab in the Block Properties window.
  • Select CopyFcn from the Callback functions list.
  • Add the following text to the Content of callback function: "CopyFcn":
  • Click OK

Now when you copy this block it can automate the connection to an existing signal line, if you drop the block on the existing signal line.

To copy a block you can:
  • Left-click and drag it from one model, subsystem, or library to another
  • Right-click and drag it in the same model or subsystem.
  • Comments

    If you would like to leave any comments regarding this post, please click here.

    Published with MATLAB® 7.11

    • print


    要发表评论,请点击 此处 登录到您的 MathWorks 帐户或创建一个新帐户。