[etherlab-dev] Patch to add rescan option to user library
Rob Stocks
rjs at computerway.biz
Thu Feb 21 10:22:21 CET 2013
Occasionally, I find that if my application is killed without deactivating
and releasing the master nicely, the slave data is corrupted (slave names
aren't shown, states are wrong, vendor id and product id are zero,
incorrect alias etc.). An example is shown here:
4 100:4 PREOP E 0x00000000:0x00000000
Executing a rescan from the ethercat command line tool fixes the problem:
4 101:0 PREOP + EL5001 1K. SSI Encoder
Therefore, I have added an ecrt_master_rescan function to the user library
and I call this in my application immediately after acquiring the master.
This ensures that the slaves are updated when my application starts.
It might be an idea to initiate a rescan whenever the master switches back
to idle mode (whether gracefully or not) then this would not be necessary.
Patch file for this change below (and also attached).
Apply with 'patch -u -p0 < rescan.patch'
--- ethercat-1.5.2/include/ecrt.h.orig 2013-02-21 03:58:50.000000000 -0500
+++ ethercat-1.5.2/include/ecrt.h 2013-02-21 03:46:12.000000000 -0500
@@ -1010,6 +1010,14 @@
*/
);
+/* Initiates a full slave rescan.
+ *
+ * \return Zero on success, otherwise negative error code.
+ */
+int ecrt_master_rescan(
+ const ec_master_t *master
+ );
+
/** Sets the application time.
*
* The master has to know the application's time when operating slaves with
--- ethercat-1.5.2/lib/master.c.orig 2013-02-21 03:58:37.000000000 -0500
+++ ethercat-1.5.2/lib/master.c 2013-02-21 03:44:36.000000000 -0500
@@ -666,6 +666,22 @@
/****************************************************************************/
+int ecrt_master_rescan(const ec_master_t *master)
+{
+ int ret;
+
+ ret = ioctl(master->fd, EC_IOCTL_MASTER_RESCAN, 0);
+ if (EC_IOCTL_IS_ERROR(ret)) {
+ fprintf(stderr, "Failed to initiate rescan: %s\n",
+ strerror(EC_IOCTL_ERRNO(ret)));
+ return -EC_IOCTL_ERRNO(ret);
+ }
+
+ return 0;
+}
+
+/****************************************************************************/
+
void ecrt_master_application_time(ec_master_t *master, uint64_t app_time)
{
ec_ioctl_app_time_t data;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.etherlab.org/pipermail/etherlab-dev/attachments/20130221/098d5d7d/attachment-0002.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rescan.patch
Type: application/octet-stream
Size: 1291 bytes
Desc: not available
URL: <http://lists.etherlab.org/pipermail/etherlab-dev/attachments/20130221/098d5d7d/attachment-0003.obj>
More information about the Etherlab-dev
mailing list