I am trying out etherlab to connect my computer to a Parker Hannifin motor 
controller - you can read about it here: 
http://www.parker.com/Literature/Electromechanical%20North%20America/CATALOGS-BROCHURES/PSeries/PSeries_UG_EtherCAT_A.pdf


I am trying to tell it to use a certain PDO, which on page 68 of the manual is 
called 1st PDO mapping.  I use the ecrt_slave_config_pdos function to tell it 
what PDO to use.  But whenever I run the program, and ask it to print out the 
PDO using ecrt_master_get_pdo and ecrt_master_get_pdo_entry, I get output that 
tells me it is using the 2nd PDO mapping (see below).  I feel like I am missing 
something.  Is there a good sample program that shows me how to set up 
something like this that I can copy?


(I have used EC-Master from Acontis, and I was able operate the controller 
using their software.  But I want to find an open source solution.)


Output of my program:

Output PDO 0x1601 with 4 entries:
  PDO entry 0: 0x6040 0 16
  PDO entry 1: 0x607a 0 32
  PDO entry 2: 0x60b8 0 16
  PDO entry 3: 0x60fe 1 32
Input PDO 0x1a01 with 6 entries:
  PDO entry 0: 0x6041 0 16
  PDO entry 1: 0x6064 0 32
  PDO entry 2: 0x60f4 0 32
  PDO entry 3: 0x60b9 0 16
  PDO entry 4: 0x60ba 0 32
  PDO entry 5: 0x60fd 0 32

Thanks, Stephen
#include <ecrt.h>
#include <pthread.h>
#include <sys/time.h>
#include <signal.h>
#include <math.h>
#include <stdio.h>

ec_master_t *master;
ec_slave_config_t *slave0;

int main() {
  int ret_val;

  if ((master = ecrt_open_master(0)) == NULL) {
    printf("Unable to request master\n");
    exit(1);
  }

  if ((ret_val = ecrt_master_reserve(master)) < 0) {
    printf("Unable to reserve master %d\n", ret_val);
    exit(1);
  }

  ec_domain_t *domain;

  if ((domain = ecrt_master_create_domain(master)) == NULL) {
    printf("Unable to create domain\n");
  }

  if ((slave0 = ecrt_master_slave_config(master, 0, 0, 0x9000089, 0x10001)) == NULL) {
    printf("Unable to request slave0\n");
    exit(1);
  }

#define SYNC_OUT	2
#define SYNC_IN		3

  ec_pdo_entry_info_t pdo_entries_out[] = {{0x6040, 0, 16},
                                           {0x6071, 0, 16},
                                           {0x607a, 0, 32},
                                           {0x6060, 0, 8},
                                           {0x60b8, 0, 16}};
  ec_pdo_info_t pdos_out[] = {{0x1600, 5, pdo_entries_out}};
//  ec_pdo_info_t pdos_out[] = {{0x1600, 0, NULL}};
  ec_sync_info_t syncs_out[] = {{SYNC_OUT, EC_DIR_OUTPUT, 1, pdos_out, EC_WD_DEFAULT}};
  if ((ret_val = ecrt_slave_config_pdos(slave0, 1, syncs_out)) < 0) {
    printf("Unable to configure output pdos %d\n", ret_val);
    exit(1);
  }

  ec_pdo_info_t pdos_in[] = {{0x1a00, 0, NULL}, {0x1a01, 0, NULL}, {0x1a02, 0, NULL}, {0x1a03, 0, NULL}};
  ec_sync_info_t syncs_in[] = {{SYNC_IN, EC_DIR_INPUT, 4, pdos_in, EC_WD_DEFAULT}};
  if ((ret_val = ecrt_slave_config_pdos(slave0, 1, syncs_in)) < 0) {
    printf("Unable to configure input pdos %d\n", ret_val);
    exit(1);
  }

  ec_pdo_info_t pdo_read;
  ec_pdo_entry_info_t pdo_entry;

  if ((ret_val = ecrt_master_get_pdo(master, 0, SYNC_OUT, 0, &pdo_read)) < 0) {
    printf("Unable to read output pdos %d\n", ret_val);
    exit(1);
  }
  printf("Output PDO 0x%x with %d entries:\n", pdo_read.index, pdo_read.n_entries);

  for (int i=0; i<pdo_read.n_entries; i++) {
    if ((ret_val = ecrt_master_get_pdo_entry(master, 0, SYNC_OUT, 0, i, &pdo_entry)) < 0) {
      printf("Unable to read output pdo entry %d %d\n", i, ret_val);
      exit(1);
    }
    printf("  PDO entry %d: 0x%x %d %d\n", i, pdo_entry.index, pdo_entry.subindex, pdo_entry.bit_length);
  }

  if ((ret_val = ecrt_master_get_pdo(master, 0, SYNC_IN, 0, &pdo_read)) < 0) {
    printf("Unable to read input pdos %d\n", ret_val);
    exit(1);
  }
  printf("Input PDO 0x%x with %d entries:\n", pdo_read.index, pdo_read.n_entries);

  for (int i=0; i<pdo_read.n_entries; i++) {
    if ((ret_val = ecrt_master_get_pdo_entry(master, 0, SYNC_IN, 0, i, &pdo_entry)) < 0) {
      printf("Unable to read output pdo entry %d %d\n", i, ret_val);
      exit(1);
    }
    printf("  PDO entry %d: 0x%x %d %d\n", i, pdo_entry.index, pdo_entry.subindex, pdo_entry.bit_length);
  }

}
_______________________________________________
etherlab-users mailing list
etherlab-users@etherlab.org
http://lists.etherlab.org/mailman/listinfo/etherlab-users

Reply via email to