{"id":2613,"date":"2010-10-15T14:14:26","date_gmt":"2010-10-15T14:14:26","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/2010\/10\/15\/automatically-connect-sink-blocks-to-existing-simulink-signals\/"},"modified":"2010-10-15T14:14:26","modified_gmt":"2010-10-15T14:14:26","slug":"automatically-connect-sink-blocks-to-existing-simulink-signals","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2010\/10\/15\/automatically-connect-sink-blocks-to-existing-simulink-signals\/","title":{"rendered":"Automatically Connect Sink Blocks To Existing Simulink Signals"},"content":{"rendered":"\r\n<p xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">For today's post, Brett and Jiro welcome guest blogger Greg Wolff.<\/p>\r\n<p xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\"><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/32620\">Greg's<\/a> pick of the week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/28656-sinkautoconnect\">SinkAutoConnect<\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/35643\">Mike Anthony<\/a>.<\/p>\r\n<p xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">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?<\/p>\r\nMike 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.\r\n\r\n<img decoding=\"async\" vspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/greg\/SinkAutoConnect_WriteUp\/scope_drop_move.png\" hspace=\"5\" \/>\r\n<p xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">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.<\/p>\r\n\r\n<h3>Contents<\/h3>\r\n<ul>\r\n\t<li><a href=\"#1\">How The SinkAutoConnect Function Works<\/a><\/li>\r\n\t<li><a href=\"#2\">Add the SinkAutoConnect Function to Your Sink Block<\/a><\/li>\r\n<\/ul>\r\n<h3>How The SinkAutoConnect Function Works<a name=\"1\" title=\"1\"><\/a><\/h3>\r\nMike takes advantage of the <em>CopyFcn<\/em> 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.\r\n\r\nThe 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).\r\n<h3>Add the SinkAutoConnect Function to Your Sink Block<a name=\"2\" title=\"2\"><\/a><\/h3>\r\nOnce you have downloaded this function, it can be added to a single-input sink block by performing the following:\r\n<ul>\r\n\t<li>Add a single-input block to a model or library.<\/li>\r\n<\/ul>\r\n<ul>\r\n\t<li>Right-click on the block to get the context menu and select <em>Block Properties<\/em>.<\/li>\r\n<\/ul>\r\n<img decoding=\"async\" vspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/greg\/SinkAutoConnect_WriteUp\/block_properties.png\" hspace=\"5\" \/>\r\n<ul>\r\n\t<li>Select the <em>Callbacks<\/em> tab in the Block Properties window.<\/li>\r\n<\/ul>\r\n<ul>\r\n\t<li>Select <em>CopyFcn<\/em> from the <em>Callback functions list<\/em>.<\/li>\r\n<\/ul>\r\n<ul>\r\n\t<li>Add the following text to the <em>Content of callback function: \"CopyFcn\"<\/em>:<\/li>\r\n<\/ul>\r\n<pre> SinkAutoConnect;<\/pre>\r\n<ul>\r\n\t<li>Click <em>OK<\/em><\/li>\r\n<\/ul>\r\n<img decoding=\"async\" vspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/greg\/SinkAutoConnect_WriteUp\/block_copyfcn.png\" hspace=\"5\" \/>\r\n<p xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">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.<\/p>\r\nTo copy a block you can:\r\n\t<li>Left-click and drag it from one model, subsystem, or library to another<\/li>\r\n\t<li>Right-click and drag it in the same model or subsystem.<\/li>\r\n<p xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\"><strong>Comments<\/strong><\/p>\r\n<p xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">If you would like to leave any comments regarding this post, please click <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=2613#respond\">here<\/a>.<\/p>\r\n<script language=\"JavaScript\">\r\n\r\n<!--   function grabCode_20c7b23b93ce48838556c7a97de6ce1c() {\r\n\r\n\/\/ Remember the title so we can use it in the new page\r\n\r\ntitle = document.title;\r\n\r\n\/\/ Break up these strings so that their presence\r\n\r\n\/\/ in the Javascript doesn\\\\\\\\\\\\\\\\\\\\\\\\'t mess up the search for\r\n\r\n\/\/ the MATLAB code.\r\n\r\nt1=\\\\\\\\\\\\\\\\\\\\\\\\'20c7b23b93ce48838556c7a97de6ce1c \\\\\\\\\\\\\\\\\\\\\\\\' + \\\\\\\\\\\\\\\\\\\\\\\\'##### \\\\\\\\\\\\\\\\\\\\\\\\' + \\\\\\\\\\\\\\\\\\\\\\\\'SOURCE BEGIN\\\\\\\\\\\\\\\\\\\\\\\\' + \\\\\\\\\\\\\\\\\\\\\\\\' #####\\\\\\\\\\\\\\\\\\\\\\\\';\r\n\r\nt2=\\\\\\\\\\\\\\\\\\\\\\\\'##### \\\\\\\\\\\\\\\\\\\\\\\\' + \\\\\\\\\\\\\\\\\\\\\\\\'SOURCE END\\\\\\\\\\\\\\\\\\\\\\\\' + \\\\\\\\\\\\\\\\\\\\\\\\' #####\\\\\\\\\\\\\\\\\\\\\\\\' + \\\\\\\\\\\\\\\\\\\\\\\\' 20c7b23b93ce48838556c7a97de6ce1c\\\\\\\\\\\\\\\\\\\\\\\\';\r\n\r\nb=document.getElementsByTagName(\\\\\\\\\\\\\\\\\\\\\\\\'body\\\\\\\\\\\\\\\\\\\\\\\\')[0];\r\n\r\ni1=b.innerHTML.indexOf(t1)+t1.length;\r\n\r\ni2=b.innerHTML.indexOf(t2);\r\n\r\ncode_string = b.innerHTML.substring(i1, i2);\r\n\r\ncode_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,\\\\\\\\\\\\\\\\\\\\\\\\'--\\\\\\\\\\\\\\\\\\\\\\\\');\/\/ Use \/x3C\/g instead of the less-than character to avoid errors   \/\/ in the XML parser.\r\n\r\n\/\/ Use \\\\\\\\\\\\\\\\\\\\\\\\'\\x26#60;\\\\\\\\\\\\\\\\\\\\\\\\' instead of \\\\\\\\\\\\\\\\\\\\\\\\'<\\\\\\\\\\\\\\\\\\\\\\\\' so that the XML parser\r\n\r\n\/\/ doesn\\\\\\\\\\\\\\\\\\\\\\\\'t go ahead and substitute the less-than character.\r\n\r\ncode_string = code_string.replace(\/\\x3C\/g, \\\\\\\\\\\\\\\\\\\\\\\\'\\x26#60;\\\\\\\\\\\\\\\\\\\\\\\\');\r\n\r\nauthor = \\\\\\\\\\\\\\\\\\\\\\\\'Greg Wolff\\\\\\\\\\\\\\\\\\\\\\\\';\r\n\r\ncopyright = \\\\\\\\\\\\\\\\\\\\\\\\'Copyright 2010 The MathWorks, Inc.\\\\\\\\\\\\\\\\\\\\\\\\';\r\n\r\nw = window.open();\r\n\r\nd = w.document;\r\n\r\nd.write(\\\\\\\\\\\\\\\\\\\\\\\\'\r\n<pre>\\n\\\\\\\\\\\\\\\\\\\\\\\\');d.write(code_string);                         \r\n\/\/ Add author and copyright lines at the bottom if specified.                        \r\n\r\nif ((author.length > 0) || (copyright.length > 0)) {                        \r\n\r\nd.writeln(\\\\\\\\\\\\\\\\\\\\\\\\'\\\\\\\\\\\\\\\\\\\\\\\\');                        \r\n\r\nd.writeln(\\\\\\\\\\\\\\\\\\\\\\\\'%%\\\\\\\\\\\\\\\\\\\\\\\\');                        \r\n\r\nif (author.length > 0) {                        \r\n\r\nd.writeln(\\\\\\\\\\\\\\\\\\\\\\\\'% _\\\\\\\\\\\\\\\\\\\\\\\\' + author + \\\\\\\\\\\\\\\\\\\\\\\\'_\\\\\\\\\\\\\\\\\\\\\\\\');                        \r\n\r\n}                        \r\n\r\nif (copyright.length > 0) {                        \r\n\r\nd.writeln(\\\\\\\\\\\\\\\\\\\\\\\\'% _\\\\\\\\\\\\\\\\\\\\\\\\' + copyright + \\\\\\\\\\\\\\\\\\\\\\\\'_\\\\\\\\\\\\\\\\\\\\\\\\');                        \r\n\r\n}                        \r\n\r\n}                        \r\n\r\nd.write(\\\\\\\\\\\\\\\\\\\\\\\\'<\/pre>\r\n\\n\\\\\\\\\\\\\\\\\\\\\\\\');d.title = title + \\\\\\\\\\\\\\\\\\\\\\\\' (MATLAB code)\\\\\\\\\\\\\\\\\\\\\\\\';   d.close();\r\n\r\n}\r\n\r\n-->\r\n\r\n<\/script>\r\n\r\n<p style=\"font-weight: lighter; font-size: xx-small; color: gray; font-style: italic; text-align: right\"><a href=\"javascript:grabCode_20c7b23b93ce48838556c7a97de6ce1c()\"><span style=\"font-size: x-small; font-style: italic\">Get the MATLAB code\r\n<noscript><\/noscript><\/span><\/a>\r\n\r\nPublished with MATLAB\u00ae 7.11\r\n\r\n<!--\r\n20c7b23b93ce48838556c7a97de6ce1c ##### SOURCE BEGIN #####\r\n\r\n%% Automatically Connect Sink Blocks To Existing Simulink Signals\r\n\r\n%\r\n\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/32620 Greg's>\r\n\r\n% pick of the week is\r\n\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/28656-sinkautoconnect SinkAutoConnect>\r\n\r\n% by <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/35643 Mike Anthony>.\r\n\r\n%\r\n\r\n% Many of you are aware that you can connect a Single-Input Single-Output block\r\n\r\n% in Simulink by dropping the block onto an existing signal line. Wouldn't\r\n\r\n% it be nice to be able to have the same type of feature for sink blocks\r\n\r\n% such as scopes so you can easily drop sinks onto existing Simulink\r\n\r\n% signals.\r\n\r\n%\r\n\r\n% Mike Anthony has created the SinkAutoConnect function that when added to\r\n\r\n% a Single-Input block's callback functions, will automatically connect the\r\n\r\n% block to a signal line when you drop the block on an existing signal\r\n\r\n% line.\r\n\r\n%\r\n\r\n% <<scope_drop_move.png>>\r\n\r\n%\r\n\r\n% When I am investigating the simulation results of Simulink models, it is\r\n\r\n% convenient for me to quickly add scopes and outports to signals so I can\r\n\r\n% log or inspect the results.\r\n\r\n%\r\n\r\n%% How The SinkAutoConnect Function Works\r\n\r\n% Mike takes advantage of the _CopyFcn_ block callback function. This\r\n\r\n% function is executed when a block is copied to a new location. This copy\r\n\r\n% can be from one Simulink model (or library) to another model, or within\r\n\r\n% the same model.\r\n\r\n%\r\n\r\n% The SinkAutoConnect function actually moves the block that you have\r\n\r\n% dropped on the Simulink signal line, and then draws a new Simulink signal\r\n\r\n% line from the new block location to the location where you dropped the\r\n\r\n% block. This new signal line will automatically connect to the existing\r\n\r\n% signal line, and create a branch point (also known as a solder joint).\r\n\r\n%\r\n\r\n%% Add the SinkAutoConnect Function to Your Sink Block\r\n\r\n% Once you have downloaded this function, it can be added to a single-input\r\n\r\n% sink block by performing the following:\r\n\r\n%\r\n\r\n% * Add a single-input block to a model or library.\r\n\r\n%\r\n\r\n% * Right-click on the block to get the context menu and select _Block\r\n\r\n% Properties_.\r\n\r\n%\r\n\r\n% <<block_properties.png>>\r\n\r\n%\r\n\r\n% * Select the _Callbacks_ tab in the Block Properties window.\r\n\r\n%\r\n\r\n% * Select _CopyFcn_ from the _Callback functions list_.\r\n\r\n%\r\n\r\n% * Add the following text to the _Content of callback function:\r\n\r\n% \"CopyFcn\"_:\r\n\r\n%\r\n\r\n% SinkAutoConnect;\r\n\r\n%\r\n\r\n% * Click _OK_\r\n\r\n%\r\n\r\n% <<block_copyfcn.png>>\r\n\r\n%\r\n\r\n% Now when you copy this block it can automate the connection to an\r\n\r\n% existing signal line, if you drop the block on the existing signal line.\r\n\r\n%\r\n\r\n% To copy a block you can:\r\n\r\n%\r\n\r\n% # Left-click and drag it from one model, subsystem, or library to another\r\n\r\n% # Right-click and drag it in the same model or subsystem.\r\n\r\n%\r\n\r\n%%\r\n\r\n% *Comments*\r\n\r\n%\r\n\r\n% If you would like to leave any comments regarding this post, please click\r\n\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=2595#respond here>.\r\n\r\n##### SOURCE END ##### 20c7b23b93ce48838556c7a97de6ce1c\r\n\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\nFor today's post, Brett and Jiro welcome guest blogger Greg Wolff.\r\nGreg's pick of the week is SinkAutoConnect by Mike Anthony.\r\nMany of you are aware that you can connect a Single-Input... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2010\/10\/15\/automatically-connect-sink-blocks-to-existing-simulink-signals\/\">read more >><\/a><\/p>","protected":false},"author":44,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2613"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/44"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=2613"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2613\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=2613"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=2613"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=2613"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}