{"id":14922,"date":"2024-10-05T03:54:06","date_gmt":"2024-10-05T03:54:06","guid":{"rendered":"https:\/\/www.qec.tw\/?p=14922"},"modified":"2024-10-05T15:36:08","modified_gmt":"2024-10-05T15:36:08","slug":"attachinterrupt-2","status":"publish","type":"post","link":"https:\/\/www.qec.tw\/ja\/ethercat\/api\/dmp\/stepper-dmp\/attachinterrupt-2\/","title":{"rendered":"EthercatDevice_DmpStepper.attachInterrupt()"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">[EthercatDevice_DmpStepper_Generic]<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Description<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Register the event callback function for the EtherCAT slave device. Since this callback function is called within <a href=\"https:\/\/www.qec.tw\/ethercat\/api\/dmp\/stepper-dmp\/update\/\"><code>update()<\/code><\/a>, it is prohibited to call blocking functions and system call-related functions within this callback function if <a href=\"https:\/\/www.qec.tw\/ethercat\/api\/dmp\/stepper-dmp\/update\/\"><code>update()<\/code><\/a> is called in an interrupt callback function (such as <em>Cyclic Callback<\/em>, <em>Error Callback<\/em>, or <em>Event Callback<\/em>).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Derived Class:<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes has-small-font-size\"><table class=\"has-fixed-layout\"><tbody><tr><td>Class Name<\/td><td>Vendor ID<\/td><td>Product Code<\/td><\/tr><tr><td>EthercatDevice_QECR11MP3S<\/td><td>0x00000bc3<\/td><td>0x0086d0d6<\/td><\/tr><tr><td>EthercatDevice_QECR00MP3S<\/td><td>0x00000bc3<\/td><td>0x0086d0d9<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Syntax<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>int attachInterrupt(void (*callback)(int));<\/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] void (*callback)(int)<\/code><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The event callback function to be registered has an integer-type parameter that indicates the event type. The supported event types are as follows:<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes has-small-font-size\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>Definition<\/strong><\/td><td><strong>Code<\/strong><\/td><td><strong>Description<\/strong><\/td><\/tr><tr><td>ECAT_EMERGENCY_STOPPED<\/td><td>1<\/td><td>Emergency stop occurred.<\/td><\/tr><tr><td>ECAT_MACHINE_X_AXIS_LIMIT_TOUCHED<\/td><td>2<\/td><td>The X-axis limit switch has been touched.<\/td><\/tr><tr><td>ECAT_MACHINE_Y_AXIS_LIMIT_TOUCHED<\/td><td>3<\/td><td>The Y-axis limit switch has been touched.<\/td><\/tr><tr><td>ECAT_MACHINE_Z_AXIS_LIMIT_TOUCHED<\/td><td>4<\/td><td>The Z-axis limit switch has been touched.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The remaining event types are determined using the following macros. Since the status of the following events are stored in the process data and this data is not latched, it is recommended to call <a href=\"https:\/\/www.qec.tw\/ethercat\/api\/dmp\/stepper-dmp\/update\/\"><code>update()<\/code><\/a> in the cyclic callback to handle these events and prevent event loss.<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes has-small-font-size\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>Definition<\/strong><\/td><td><strong>Description<\/strong><\/td><\/tr><tr><td>IS_ECAT_ENCODER_1_INDEX_RESET(event)<\/td><td>The Index Reset event of Encoder 1 has been triggered.<\/td><\/tr><tr><td>IS_ECAT_ENCODER_2_INDEX_RESET(event)<\/td><td>The Index Reset event of Encoder 2 has been triggered.<\/td><\/tr><tr><td>IS_ECAT_ENCODER_3_INDEX_RESET(event)<\/td><td>The Index Reset event of Encoder 3 has been triggered.<\/td><\/tr><tr><td>IS_ECAT_ENCODER_X_INDEX_RESET(event)<\/td><td>The Index Reset event of Encoder X has been triggered.<\/td><\/tr><tr><td>IS_ECAT_ENCODER_Y_INDEX_RESET(event)<\/td><td>The Index Reset event of Encoder Y has been triggered.<\/td><\/tr><tr><td>IS_ECAT_ENCODER_Z_INDEX_RESET(event)<\/td><td>The Index Reset event of Encoder Z has been triggered.<\/td><\/tr><tr><td>IS_ECAT_ENCODER_1_OVERFLOW(event)<\/td><td>The Overflow event of Encoder 1 has been triggered.<\/td><\/tr><tr><td>IS_ECAT_ENCODER_2_OVERFLOW(event)<\/td><td>The Overflow event of Encoder 2 has been triggered.<\/td><\/tr><tr><td>IS_ECAT_ENCODER_3_OVERFLOW(event)<\/td><td>The Overflow event of Encoder 3 has been triggered.<\/td><\/tr><tr><td>IS_ECAT_ENCODER_X_OVERFLOW(event)<\/td><td>The Overflow event of Encoder X has been triggered.<\/td><\/tr><tr><td>IS_ECAT_ENCODER_Y_OVERFLOW(event)<\/td><td>The Overflow event of Encoder Y has been triggered.<\/td><\/tr><tr><td>IS_ECAT_ENCODER_Z_OVERFLOW(event)<\/td><td>The Overflow event of Encoder Z has been triggered.<\/td><\/tr><tr><td>IS_ECAT_ENCODER_1_UNDERFLOW(event)<\/td><td>The Underflow event of Encoder 1 has been triggered.<\/td><\/tr><tr><td>IS_ECAT_ENCODER_2_UNDERFLOW(event)<\/td><td>The Underflow event of Encoder 2 has been triggered.<\/td><\/tr><tr><td>IS_ECAT_ENCODER_3_UNDERFLOW(event)<\/td><td>The Underflow event of Encoder 3 has been triggered.<\/td><\/tr><tr><td>IS_ECAT_ENCODER_X_UNDERFLOW(event)<\/td><td>The Underflow event of Encoder X has been triggered.<\/td><\/tr><tr><td>IS_ECAT_ENCODER_Y_UNDERFLOW(event)<\/td><td>The Underflow event of Encoder Y has been triggered.<\/td><\/tr><tr><td>IS_ECAT_ENCODER_Z_UNDERFLOW(event)<\/td><td>The Underflow event of Encoder Z has been triggered.<\/td><\/tr><\/tbody><\/table><\/figure>\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 must be called after a successful execution of <a href=\"https:\/\/www.qec.tw\/ethercat\/api\/master\/ethercatmaster-begin\/\"><code>EthercatMaster::begin()<\/code><\/a>. This function is blocking and cannot be called within the Cyclic Callback.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Example<\/h2>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>#include &quot;Ethercat.h&quot;\n\nEthercatMaster master;\nEthercatDevice_QECR11MP3S slave;\n\nint emergency_stopped;\nint x_limit_touched;\nint y_limit_touched;\nint z_limit_touched;\nint encoder_index_reset[3];\nint encoder_overflow[3];\nint encoder_underflow[3];\nint encoder_xyz_index_reset[3];\nint encoder_xyz_overflow[3];\nint encoder_xyz_underflow[3];\n\nvoid Callback(int event) {\n  switch (event) {\n    case ECAT_EMERGENCY_STOPPED:\n      emergency_stopped = 1;\n      return;\n    case ECAT_MACHINE_X_AXIS_LIMIT_TOUCHED:\n      x_limit_touched = 1;\n      return;\n    case ECAT_MACHINE_Y_AXIS_LIMIT_TOUCHED:\n      y_limit_touched = 1;\n      return;\n    case ECAT_MACHINE_Z_AXIS_LIMIT_TOUCHED:\n      z_limit_touched = 1;\n      return;\n    default:\n      break;\n  }\n\n  if (IS_ECAT_ENCODER_1_INDEX_RESET(event))\n    encoder_index_reset[0] = 1;\n  else if (IS_ECAT_ENCODER_2_INDEX_RESET(event))\n    encoder_index_reset[1] = 1;\n  else if (IS_ECAT_ENCODER_3_INDEX_RESET(event))\n    encoder_index_reset[2] = 1;\n  else if (IS_ECAT_ENCODER_1_OVERFLOW(event))\n    encoder_overflow[0] = 1;\n  else if (IS_ECAT_ENCODER_2_OVERFLOW(event))\n    encoder_overflow[1] = 1;\n  else if (IS_ECAT_ENCODER_3_OVERFLOW(event))\n    encoder_overflow[2] = 1;\n  else if (IS_ECAT_ENCODER_1_UNDERFLOW(event))\n    encoder_underflow[0] = 1;\n  else if (IS_ECAT_ENCODER_2_UNDERFLOW(event))\n    encoder_underflow[1] = 1;\n  else if (IS_ECAT_ENCODER_3_UNDERFLOW(event))\n    encoder_underflow[2] = 1;\n\n  if (IS_ECAT_ENCODER_X_INDEX_RESET(event))\n    encoder_xyz_index_reset[0] = 1;\n  else if (IS_ECAT_ENCODER_Y_INDEX_RESET(event))\n    encoder_xyz_index_reset[1] = 1;\n  else if (IS_ECAT_ENCODER_Z_INDEX_RESET(event))\n    encoder_xyz_index_reset[2] = 1;\n  else if (IS_ECAT_ENCODER_X_OVERFLOW(event))\n    encoder_xyz_overflow[0] = 1;\n  else if (IS_ECAT_ENCODER_Y_OVERFLOW(event))\n    encoder_xyz_overflow[1] = 1;\n  else if (IS_ECAT_ENCODER_Z_OVERFLOW(event))\n    encoder_xyz_overflow[2] = 1;\n  else if (IS_ECAT_ENCODER_X_UNDERFLOW(event))\n    encoder_xyz_underflow[0] = 1;\n  else if (IS_ECAT_ENCODER_Y_UNDERFLOW(event))\n    encoder_xyz_underflow[1] = 1;\n  else if (IS_ECAT_ENCODER_Z_UNDERFLOW(event))\n    encoder_xyz_underflow[2] = 1;\n}\n\nvoid CyclicCallback() {\n  slave.update();\n}\n\nvoid setup() {\n  Serial.begin(115200);\n\n  master.begin();\n  slave.attach(0, master);\n  slave.attachInterrupt(Callback);\n  master.attachCyclicCallback(CyclicCallback);\n  master.start();\n}\n\nvoid loop() {\n  if (emergency_stopped) {\n    emergency_stopped = 0;\n    Serial.println(&quot;ECAT_EMERGENCY_STOPPED&quot;);\n  }\n  if (x_limit_touched) {\n    x_limit_touched = 0;\n    Serial.println(&quot;ECAT_MACHINE_X_AXIS_LIMIT_TOUCHED&quot;);\n  }\n  if (y_limit_touched) {\n    y_limit_touched = 0;\n    Serial.println(&quot;ECAT_MACHINE_Y_AXIS_LIMIT_TOUCHED&quot;);\n  }\n  if (z_limit_touched) {\n    z_limit_touched = 0;\n    Serial.println(&quot;ECAT_MACHINE_Z_AXIS_LIMIT_TOUCHED&quot;);\n  }\n  if (encoder_index_reset[0]) {\n    encoder_index_reset[0] = 0;\n    Serial.println(&quot;IS_ECAT_ENCODER_1_INDEX_RESET&quot;);\n  }\n  if (encoder_index_reset[1]) {\n    encoder_index_reset[1] = 0;\n    Serial.println(&quot;IS_ECAT_ENCODER_2_INDEX_RESET&quot;);\n  }\n  if (encoder_index_reset[2]) {\n    encoder_index_reset[2] = 0;\n    Serial.println(&quot;IS_ECAT_ENCODER_3_INDEX_RESET&quot;);\n  }\n  if (encoder_overflow[0]) {\n    encoder_overflow[0] = 0;\n    Serial.println(&quot;IS_ECAT_ENCODER_1_OVERFLOW&quot;);\n  }\n  if (encoder_overflow[1]) {\n    encoder_overflow[1] = 0;\n    Serial.println(&quot;IS_ECAT_ENCODER_2_OVERFLOW&quot;);\n  }\n  if (encoder_overflow[2]) {\n    encoder_overflow[2] = 0;\n    Serial.println(&quot;IS_ECAT_ENCODER_3_OVERFLOW&quot;);\n  }\n  if (encoder_underflow[0]) {\n    encoder_underflow[0] = 0;\n    Serial.println(&quot;IS_ECAT_ENCODER_1_UNDERFLOW&quot;);\n  }\n  if (encoder_underflow[1]) {\n    encoder_underflow[1] = 0;\n    Serial.println(&quot;IS_ECAT_ENCODER_2_UNDERFLOW&quot;);\n  }\n  if (encoder_underflow[2]) {\n    encoder_underflow[2] = 0;\n    Serial.println(&quot;IS_ECAT_ENCODER_3_UNDERFLOW&quot;);\n  }\n  if (encoder_xyz_index_reset[0]) {\n    encoder_xyz_index_reset[0] = 0;\n    Serial.println(&quot;IS_ECAT_ENCODER_X_INDEX_RESET&quot;);\n  }\n  if (encoder_xyz_index_reset[1]) {\n    encoder_xyz_index_reset[1] = 0;\n    Serial.println(&quot;IS_ECAT_ENCODER_Y_INDEX_RESET&quot;);\n  }\n  if (encoder_xyz_index_reset[2]) {\n    encoder_xyz_index_reset[2] = 0;\n    Serial.println(&quot;IS_ECAT_ENCODER_Z_INDEX_RESET&quot;);\n  }\n  if (encoder_xyz_overflow[0]) {\n    encoder_xyz_overflow[0] = 0;\n    Serial.println(&quot;IS_ECAT_ENCODER_X_OVERFLOW&quot;);\n  }\n  if (encoder_xyz_overflow[1]) {\n    encoder_xyz_overflow[1] = 0;\n    Serial.println(&quot;IS_ECAT_ENCODER_Y_OVERFLOW&quot;);\n  }\n  if (encoder_xyz_overflow[2]) {\n    encoder_xyz_overflow[2] = 0;\n    Serial.println(&quot;IS_ECAT_ENCODER_Z_OVERFLOW&quot;);\n  }\n  if (encoder_xyz_underflow[0]) {\n    encoder_xyz_underflow[0] = 0;\n    Serial.println(&quot;IS_ECAT_ENCODER_X_UNDERFLOW&quot;);\n  }\n  if (encoder_xyz_underflow[1]) {\n    encoder_xyz_underflow[1] = 0;\n    Serial.println(&quot;IS_ECAT_ENCODER_Y_UNDERFLOW&quot;);\n  }\n  if (encoder_xyz_underflow[2]) {\n    encoder_xyz_underflow[2] = 0;\n    Serial.println(&quot;IS_ECAT_ENCODER_Z_UNDERFLOW&quot;);\n  }\n  \/\/ ...\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&nbsp;<a href=\"https:\/\/www.qec.tw\/ethercat\/api\/dmp\/stepper-dmp\/\">EthercatDevice_DmpStepper_Generic Class<\/a>&nbsp;for more QEC Stepper Drivers instructions and API usage.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[EthercatDevice_DmpStepper_Generic] Description Register the event callback function for the EtherCAT slave device. Since this callback function is called within update(), it is prohibited to call [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":14926,"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":[277],"tags":[162,54,191],"class_list":["post-14922","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-stepper-dmp","tag-86duino","tag-ethercat","tag-qec"],"_links":{"self":[{"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/posts\/14922","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/comments?post=14922"}],"version-history":[{"count":0,"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/posts\/14922\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/media\/14926"}],"wp:attachment":[{"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/media?parent=14922"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/categories?post=14922"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/tags?post=14922"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}