lib/common.c
branchstable-1.5
changeset 2433 3bdd7a747fae
parent 2383 572948e8b2ed
child 2703 045624f7f4c3
--- a/lib/common.c	Thu Sep 20 09:20:51 2012 +0200
+++ b/lib/common.c	Thu Sep 20 15:28:25 2012 +0200
@@ -2,7 +2,7 @@
  *
  *  $Id$
  *
- *  Copyright (C) 2006-2009  Florian Pose, Ingenieurgemeinschaft IgH
+ *  Copyright (C) 2006-2012  Florian Pose, Ingenieurgemeinschaft IgH
  *
  *  This file is part of the IgH EtherCAT master userspace library.
  *
@@ -33,15 +33,13 @@
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <errno.h>
 #include <string.h>
-#include <sys/ioctl.h>
 #include <sys/mman.h>
 #include <unistd.h>
 #include <sys/socket.h>
 
+#include "ioctl.h"
 #include "master.h"
-#include "master/ioctl.h"
 
 /*****************************************************************************/
 
@@ -75,6 +73,7 @@
     char path[MAX_PATH_LEN];
     ec_master_t *master = NULL;
     ec_ioctl_module_t module_data;
+    int ret;
 
     master = malloc(sizeof(ec_master_t));
     if (!master) {
@@ -87,17 +86,29 @@
     master->first_domain = NULL;
     master->first_config = NULL;
 
-    snprintf(path, MAX_PATH_LEN - 1, "/dev/EtherCAT%u", master_index);
+    snprintf(path, MAX_PATH_LEN - 1,
+#ifdef USE_RTDM
+            "EtherCAT%u",
+#else
+            "/dev/EtherCAT%u",
+#endif
+            master_index);
 
+#ifdef USE_RTDM
+    master->fd = rt_dev_open(path, O_RDWR);
+#else
     master->fd = open(path, O_RDWR);
-    if (master->fd == -1) {
-        fprintf(stderr, "Failed to open %s: %s\n", path, strerror(errno));
+#endif
+    if (EC_IOCTL_IS_ERROR(master->fd)) {
+        fprintf(stderr, "Failed to open %s: %s\n", path,
+                strerror(EC_IOCTL_ERRNO(master->fd)));
         goto out_clear;
     }
 
-    if (ioctl(master->fd, EC_IOCTL_MODULE, &module_data) < 0) {
+    ret = ioctl(master->fd, EC_IOCTL_MODULE, &module_data);
+    if (EC_IOCTL_IS_ERROR(ret)) {
         fprintf(stderr, "Failed to get module information from %s: %s\n",
-                path, strerror(errno));
+                path, strerror(EC_IOCTL_ERRNO(ret)));
         goto out_clear;
     }