{"id":10621,"date":"2024-08-28T03:07:20","date_gmt":"2024-08-28T03:07:20","guid":{"rendered":"https:\/\/www.qec.tw\/?p=10621"},"modified":"2024-08-28T03:22:33","modified_gmt":"2024-08-28T03:22:33","slug":"ethercatmaster-start","status":"publish","type":"post","link":"https:\/\/www.qec.tw\/zh\/ethercat\/api\/master\/ethercatmaster-start\/","title":{"rendered":"EthercatMaster.start()"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">[Ethercat Master]<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Description<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Start the EtherCAT master, configure the SM, FMMU, and DC registers of all slaves, and switch the EtherCAT state machine to the Operational state.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Syntax<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>int start(uint64_t cycletime_ns = 0, EthercatMasterMode mode = ECAT_FREERUN);<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Parameters<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>[in] uint64_t cycletime_ns<\/code><br>EtherCAT cycle time. The EtherCAT firmware will periodically generate interrupts according to this cycle time to update process data and handle acyclic transmissions. If the user has registered a Cyclic Callback and the EtherCAT master control mode is not set to <code>ECAT_FREERUN_MANUAL<\/code>, the callback will be called during these periodic interrupts.<\/li>\n\n\n\n<li><code>[in] EthercatMasterMode mode<\/code><br>Selection of the EtherCAT control mode. For detailed descriptions of each mode, please refer to the examples below.\n<ul class=\"wp-block-list\">\n<li><code>ECAT_SYNC<\/code><\/li>\n\n\n\n<li><code>ECAT_FREERUN<\/code><\/li>\n\n\n\n<li><code>ECAT_FREERUN_MANUAL<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Return Value<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Return an <a href=\"https:\/\/www.qec.tw\/ethercat\/api\/error-code\/\">error code<\/a>. If the returned value is zero, it indicates a successful execution of this function.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Comment<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This function is blocking and cannot be called within the callback functions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">We will show how to select the EtherCAT control modes (<code>ECAT_SYNC<\/code>, <code>ECAT_FREERUN<\/code>, <code>ECAT_FREERUN_MANUAL<\/code>) in the following examples.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><code>ECAT_SYNC<\/code><\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1004\" height=\"492\" src=\"https:\/\/www.qec.tw\/wp-content\/uploads\/2022\/09\/image-1.png\" alt=\"ECAT_SYNC_Diagram\" class=\"wp-image-14109\" srcset=\"https:\/\/www.qec.tw\/wp-content\/uploads\/2022\/09\/image-1.png 1004w, https:\/\/www.qec.tw\/wp-content\/uploads\/2022\/09\/image-1-300x147.png 300w, https:\/\/www.qec.tw\/wp-content\/uploads\/2022\/09\/image-1-768x376.png 768w, https:\/\/www.qec.tw\/wp-content\/uploads\/2022\/09\/image-1-18x9.png 18w, https:\/\/www.qec.tw\/wp-content\/uploads\/2022\/09\/image-1-600x294.png 600w\" sizes=\"(max-width: 1004px) 100vw, 1004px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">This mode offers the highest level of dual-system synchronization. As shown in the diagram, the numbered arrows indicate the sequence of operations, with no branching present. After the EtherCAT firmware triggers a cyclic interrupt to the EtherCAT master library (step 2), it waits for an ACK response from the EtherCAT master library (step 8) before proceeding with the next action. If the user has registered a cyclic callback, the cyclic interrupt will call it, as shown in step 4. As long as the user reads the current input process data within the cyclic callback, processes it, calculates the output process data, and writes it back, the current cycle will send the output process data to the EtherCAT network, fulfilling the requirements of real-time control systems.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>#include &quot;Ethercat.h&quot;\n\nEthercatMaster master;\n\nvoid CyclicCallback() {\n  \/\/ ...\n}\n\nvoid setup() {\n  master.begin();\n  master.attachCyclicCallback(CyclicCallback);\n  master.start(1000000, ECAT_SYNC);\n}\n\nvoid loop() {\n  \/\/ ... \n}<\/pre><\/div>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><code>ECAT_FREERUN<\/code><\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1004\" height=\"508\" src=\"https:\/\/www.qec.tw\/wp-content\/uploads\/2022\/09\/image-2.png\" alt=\"ECAT_FREERUN_Diagram\" class=\"wp-image-14110\" srcset=\"https:\/\/www.qec.tw\/wp-content\/uploads\/2022\/09\/image-2.png 1004w, https:\/\/www.qec.tw\/wp-content\/uploads\/2022\/09\/image-2-300x152.png 300w, https:\/\/www.qec.tw\/wp-content\/uploads\/2022\/09\/image-2-768x389.png 768w, https:\/\/www.qec.tw\/wp-content\/uploads\/2022\/09\/image-2-18x9.png 18w, https:\/\/www.qec.tw\/wp-content\/uploads\/2022\/09\/image-2-600x304.png 600w\" sizes=\"(max-width: 1004px) 100vw, 1004px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">This is the free-run mode without dual-system synchronization. As shown in the diagram, the numbered arrows indicate the sequence of operations. However, a branching occurs at step 3 because, after the EtherCAT firmware triggers a cyclic interrupt to the EtherCAT master library (step 2), it does not wait for the EtherCAT master library and directly continues with the next action. The two systems operate independently, with no synchronization. If the user has registered a cyclic callback, the cyclic interrupt will call it, as shown in step 4A.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>#include &quot;Ethercat.h&quot;\n\nEthercatMaster master;\n\nvoid CyclicCallback() {\n  \/\/ ...\n}\n\nvoid setup() {\n  master.begin();\n  master.attachCyclicCallback(CyclicCallback);\n  master.start(1000000, ECAT_FREERUN);\n}\n\nvoid loop() {\n  \/\/ ...\n}<\/pre><\/div>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><code>ECAT_FREERUN_MANUAL<\/code><\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1004\" height=\"356\" src=\"https:\/\/www.qec.tw\/wp-content\/uploads\/2022\/09\/image-3.png\" alt=\"ECAT_FREERUN_MANUAL_Diagram\" class=\"wp-image-14111\" srcset=\"https:\/\/www.qec.tw\/wp-content\/uploads\/2022\/09\/image-3.png 1004w, https:\/\/www.qec.tw\/wp-content\/uploads\/2022\/09\/image-3-300x106.png 300w, https:\/\/www.qec.tw\/wp-content\/uploads\/2022\/09\/image-3-768x272.png 768w, https:\/\/www.qec.tw\/wp-content\/uploads\/2022\/09\/image-3-18x6.png 18w, https:\/\/www.qec.tw\/wp-content\/uploads\/2022\/09\/image-3-600x213.png 600w\" sizes=\"(max-width: 1004px) 100vw, 1004px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">This is also a free-run mode without dual-system synchronization. The primary difference from the&nbsp;<code>ECAT_FREERUN<\/code>&nbsp;mode is that there is no cyclic interrupt to update process data and handle acyclic commands. Instead, the user must manually call&nbsp;<code>EthercatMaster::update()<\/code>&nbsp;to update process data and handle acyclic commands. Additionally, since there is no cyclic interrupt in this mode, the cyclic callback will not be called. As indicated by the numbered arrows in the diagram, the two systems operate independently, with no synchronization.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>#include &quot;Ethercat.h&quot;\n\nEthercatMaster master;\n\nvoid setup() {\n  master.begin();\n  master.start(1000000, ECAT_FREERUN_MANUAL);\n}\n\nvoid loop() {\n  \/\/ ...\n  master.update();\n}<\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\">Please see the&nbsp;<a href=\"https:\/\/www.qec.tw\/ethercat\/api\/ethercat-library-api-user-manual\/\">EtherCAT Library User Manual<\/a>&nbsp;for more QEC EtherCAT instructions and API usage.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[Ethercat Master] Description Start the EtherCAT master, configure the SM, FMMU, and DC registers of all slaves, and switch the EtherCAT state machine to the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":10622,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[250],"tags":[162,54,191],"class_list":["post-10621","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-master","tag-86duino","tag-ethercat","tag-qec"],"_links":{"self":[{"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/posts\/10621","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/comments?post=10621"}],"version-history":[{"count":0,"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/posts\/10621\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/media\/10622"}],"wp:attachment":[{"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/media?parent=10621"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/categories?post=10621"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/tags?post=10621"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}