{"id":6062,"date":"2022-09-16T11:20:25","date_gmt":"2022-09-16T03:20:25","guid":{"rendered":"https:\/\/www.tosunai.com\/?p=6062"},"modified":"2024-04-23T15:20:41","modified_gmt":"2024-04-23T07:20:41","slug":"reuse-methods-for-tsmaster-automation-modules","status":"publish","type":"post","link":"https:\/\/www.tosunai.com\/en\/reuse-methods-for-tsmaster-automation-modules\/","title":{"rendered":"New Feature Release | Reuse Methods for TSMaster Automation Modules"},"content":{"rendered":"
\n\t\t\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t
\n\t\t\t
overviewPreface<\/h5>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\t

Today we continue to introduce you to TSMaster's new feature, the Automation Module. Usually in the development process, if a certain logic will be used repeatedly in different scenarios, the first thing we think of is to encapsulate it into a function for reuse.<\/p><\/section>

<\/section>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t
\n\t\t\t

I. Control gear signal generating pulse<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t
Control gear signal to generate pulse<\/h5>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\t

> First go to the project folder, find the database folder in the Demo folder, drag in the example database file, then open the bus simulation, check auto start and check all the nodes so that it can run up automatically. We then open the trace and graph window and drag the block signal we are interested in into the graph, we then come to the automation module and press enter to add the action.<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t

\n\t\t\t\t
\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"TSMaster\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\t

> The first action is set to wait for 1 second, here rewrite to 1,000 milliseconds, the message is not filled, so that it will not automatically pop up the READ window; the second action is set to change the block to two, at this time, just select the signal read\/write attribute, click the right button to select our can signal for the block signal just now and click OK, and change this value to 2; the third action is to wait for three seconds, at this time we just copy the first action, press the key and paste to paste the wait action, then we will change 1,000 to 3,000, that is, wait for three seconds; the fourth action will change the blocking to 0, at this time, just copy the gear=2 to paste under the wait and change the 2 to 0; the last action to wait for one more second, we just need to wait the first wait to the last action and paste it. This realizes a process of waiting 3 seconds from block 0 to 2 to 0. Then we press F9 to run the program, from the graphics we can clearly see the process of changing gears, the process lasted 3 seconds.<\/p><\/section>

<\/section>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"TSMaster\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t
\n\t\t\t

II. Modify the width and height of the pulse<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t
Modify the pulse width and height<\/h5>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\t

Being a function is not as simple as just calling it, but also parameterizing what is run. For example, modifying the width and height of the pulse.<\/p>

> This requires going back into our module and adding the variables height and width. Select the type of variable and then add two double type variables in the variable list, named time and value, we will abbreviate them as t and v, and change the default value of time to 3,000, as well as just 3 seconds value to 2. Afterwards, we click on the properties page, and then click on the blank space in the flowchart, so that the module's properties are selected.<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t

\n\t\t\t\t
\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"TSMaster\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\t

> There is a column called Module Level Parameters in the bottom, right click on it and add a parameter group. We first rename the first parameter group as short, and right-click on this parameter group, select Add Parameter, will open a dialog box, which defaults to help us select the two variables we just added, we directly click OK, so that the increase of two sub-parameters, the value of these two parameters can be rewritten as a parameter of the module level arbitrarily.<\/p><\/section>

<\/section>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"TSMaster\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\t

> For example, we can change the time for short to 1,000 milliseconds and change the value of v to 3. Then we can add a second parameter group, just right click on the first parameter group, copy the selection, and click paste in the blank space, and we get the pasted parameter group. We rename it to long, and then we change t to 5000, the wait time will be a little longer, and we change v to 5. So far we have created two groups of parameters, short delay and long delay.<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t

\n\t\t\t\t
\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"TSMaster\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\t

> Subsequently, we switch to the module screen, you can see the bottom of the module appears two parameterized entries, respectively, short delay and long delay, then we need to associate our code and parameters, we go back to this gear = 2 this action, double-click after you can see that the judgment value is written to death 2, we click on the selection of the local variable, select our value, so that makes this gear, has become a dynamic value, then the name we can rewrite at will, such as set gear, and then wait for the time, we can also associate it to our local variables, that is, the t, then this will realize the two variables just set and our program binding.<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t

\n\t\t\t\t
\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"TSMaster\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\t

> Then we next select our short delay, press F9, the program will run in short delay, you can see that his delay time is just one second, and his peak value is 3. Then go back to our module list and select the long delay, press F9 and you can see that our program is running in long delay, it's delay length is 5 seconds, and the peak value is 5. So that's how a module is parameterized. So this is how to parameterize a module. Then we can list as many parameters as we want, and the number of parameters is not limited, so that we can realize the same logic for the same test for different inputs for various controls.<\/p><\/section>

<\/section>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"TSMaster\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t
\n\t\t\t

III. Reuse methods for automation modules<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t
Reuse methods of automation modules<\/h5>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\t

> First make this module a library, rename the module to set gear, so the name becomes set gear, then we right click inside the module list, create a new sub-module and name it caller, that is, caller, to call our current gear setting module. This time we go to the module page, we can right click on set gear and move it to the code base, after selecting it we go to the bottom and there is a static code base, expand it and you can see that our set gear is already in the static code base. The good thing about a static codebase is that it can't be modified arbitrarily, which means that any codebase we add can be saved here permanently and can be called from any of the modules above.<\/p><\/section>

<\/section>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"TSMaster\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\t

Then go back to the entry point of our caller function, press CTRL plus Enter, create a new action group, select the action group, then click on Properties, go to the right side to find the function of linking submodules, and then we can link to the code base of the set gear that we have just done, which realizes the association between our action group and the library file.<\/p>

> As a library, the two variables inside its own module will not be created automatically, it is necessary to add variables with the same name inside the caller's module, we add two double type variables, rename it as t and v, then these two values can be changed arbitrarily, so that we can also realize the parameterization of the library, for example, we can shorten it to 500, then v is changed to 1, then we run the current caller, then we can see that after the gear runs, its value becomes 1, and the length of the delay becomes 500 milliseconds. For example, we can make it shorter by changing it to 500, and then we can change v to 1, and then we can run the current caller, and then we can see that after the gear is run, its value changes to 1, and the delay length changes to 500 milliseconds.<\/p><\/section>

<\/section>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"TSMaster\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\t

If we wish to call it multiple times, we can simply copy this action group ctrl c, ctrl v and then press F9 again, so that we can see the call repeated multiple times, and we can even modify the variable again each time to give it a different result each time it is run.<\/p>

Then we can try to change it, let's say we'll change the selection, change it to 3,000, and then the value to 5, and then we'll F9, start it up, and this time we can see our new program running with different parameters. So that's one module and one complete parameterization.<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t

\n\t\t\t\t
\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"TSMaster\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t
\n\t\t\t

About More<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\t

The above is the reuse method of automation module of TSMaster's new features, we will see you in the next issue! (You can watch our B-site video for specific operation explanation)<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t

\n\t\t\t\t
\n\t\t\t\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\tTSMaster More video tutorials \u2192<\/span>\n\t\t\t\t\t<\/span>\n\t\t\t\t\t<\/a>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>","protected":false},"excerpt":{"rendered":"

overview Preface Today we continue to introduce you to a new feature of TSMaster - the Automation Module. Usually, during development, if a certain logic will [...]<\/p>","protected":false},"author":11,"featured_media":6043,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"","ocean_second_sidebar":"","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"","ocean_custom_header_template":"","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"","ocean_menu_typo_font_family":"","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"on","ocean_gallery_id":[],"footnotes":""},"categories":[90],"tags":[142,244,247],"class_list":["post-6062","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software-tutorial","tag-tsmaster","tag-244","tag-247","entry","has-media","owp-thumbs-layout-horizontal","owp-btn-normal","owp-tabs-layout-horizontal","has-no-thumbnails","has-product-nav"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tosunai.com\/en\/wp-json\/wp\/v2\/posts\/6062","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tosunai.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tosunai.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tosunai.com\/en\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tosunai.com\/en\/wp-json\/wp\/v2\/comments?post=6062"}],"version-history":[{"count":0,"href":"https:\/\/www.tosunai.com\/en\/wp-json\/wp\/v2\/posts\/6062\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.tosunai.com\/en\/wp-json\/wp\/v2\/media\/6043"}],"wp:attachment":[{"href":"https:\/\/www.tosunai.com\/en\/wp-json\/wp\/v2\/media?parent=6062"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tosunai.com\/en\/wp-json\/wp\/v2\/categories?post=6062"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tosunai.com\/en\/wp-json\/wp\/v2\/tags?post=6062"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}