- Posts: 153
- Thank you received: 26
Ethercat HAL driver
- Nico2017
- Offline
- Premium Member
-
Less
More
8 years 6 days ago #119428
by Nico2017
Replied by Nico2017 on topic Ethercat HAL driver
Hi,
doing ldd lcec.so
linux-gate.so.1 (0xb7783000)
liblinuxcnchal.so.0 => /usr/lib/liblinuxcnchal.so.0 (0xb7746000)
libethercat.so.1 => /usr/lib/i386-linux-gnu/libethercat.so.1 (0xb773b000)
libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xb76e4000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb752d000)
librt.so.1 => /lib/i386-linux-gnu/librt.so.1 (0xb7524000)
libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0xb7507000)
/lib/ld-linux.so.2 (0xb7785000)
I installed ethercat, using dpkg with github.com/sittner/ec-debianize as I am using debian as it is the OS suggested for linuxcnc. I did try the etherlab installation, building it, without much success as it does not document the file system architecture for debian, during the installation process.
So far I have managed to
-install debian Strech with latest RT prempt kernel : Linux plotter 4.9.0-8-rt-686-pae #1 SMP PREEMPT RT Debian 4.9.110-3+deb9u5 (2018-09-30) i686 GNU/Linux
-install linuxcnc, either 2.7.14 or 2.8.x
-install ethercat using sittner ec-debianize depot ( github.com/sittner/ec-debianize ). After building and installing, Ethercat master and ethercat slaves command work fine
-build and install linuxcnc-ethercat from github.com/sittner/linuxcnc-ethercat (make then sudo make install, or sudo make clean, make then sudo make install if I switch the linuxcnc version to update the kernel)
My problems are:
-when I try to run Linuxcnc 2.7.14 I have a permission denied on Ethercat0 as shown in
LINUXCNC - 2.7.14
Machine configuration directory is '/home/plotter/linuxcnc/configs/LAMGUI'
Machine configuration file is 'lam.ini'
Starting LinuxCNC...
Found file(REL): ./lam-v1.hal
Note: Using POSIX realtime
Failed to open /dev/EtherCAT0: Permission denied
LCEC: requesting master 0 (index 0) failed
lcec: rtapi_app_main: Invalid argument (-22)
./lam-v1.hal:2: waitpid failed /usr/bin/rtapi_app lcec
./lam-v1.hal:2: /usr/bin/rtapi_app exited without becoming ready
./lam-v1.hal:2: insmod for lcec failed, returned -1
Shutting down and cleaning up LinuxCNC...
Note: Using POSIX realtime
LinuxCNC terminated with an error. You can find more information in the log:
/home/plotter/linuxcnc_debug.txt
and
/home/plotter/linuxcnc_print.txt
as well as in the output of the shell command 'dmesg' and in the terminal
-when I build linuxcnc 2.8.x then install it I got
-LINUXCNC - 2.8.0~pre1
Machine configuration directory is '/home/plotter/linuxcnc/configs/LAMGUI'
Machine configuration file is 'lam.ini'
Starting LinuxCNC...
Found file(REL): ./lam-v1.hal
Note: Using POSIX realtime
lcec: dlopen: /usr/lib/linuxcnc/modules/lcec.so: undefined symbol: rtapi_mutex_get
./lam-v1.hal:2: waitpid failed /usr/bin/rtapi_app lcec
./lam-v1.hal:2: /usr/bin/rtapi_app exited without becoming ready
./lam-v1.hal:2: insmod for lcec failed, returned -1
Shutting down and cleaning up LinuxCNC...
Note: Using POSIX realtime
LinuxCNC terminated with an error. You can find more information in the log:
/home/plotter/linuxcnc_debug.txt
and
/home/plotter/linuxcnc_print.txt
as well as in the output of the shell command 'dmesg' and in the terminal
Any advice about how to make either 2.7 or 2.8 working with the ethercat and linuxcnc ethercat driver?
Cheers,
Nicolas
doing ldd lcec.so
linux-gate.so.1 (0xb7783000)
liblinuxcnchal.so.0 => /usr/lib/liblinuxcnchal.so.0 (0xb7746000)
libethercat.so.1 => /usr/lib/i386-linux-gnu/libethercat.so.1 (0xb773b000)
libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xb76e4000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb752d000)
librt.so.1 => /lib/i386-linux-gnu/librt.so.1 (0xb7524000)
libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0xb7507000)
/lib/ld-linux.so.2 (0xb7785000)
I installed ethercat, using dpkg with github.com/sittner/ec-debianize as I am using debian as it is the OS suggested for linuxcnc. I did try the etherlab installation, building it, without much success as it does not document the file system architecture for debian, during the installation process.
So far I have managed to
-install debian Strech with latest RT prempt kernel : Linux plotter 4.9.0-8-rt-686-pae #1 SMP PREEMPT RT Debian 4.9.110-3+deb9u5 (2018-09-30) i686 GNU/Linux
-install linuxcnc, either 2.7.14 or 2.8.x
-install ethercat using sittner ec-debianize depot ( github.com/sittner/ec-debianize ). After building and installing, Ethercat master and ethercat slaves command work fine
-build and install linuxcnc-ethercat from github.com/sittner/linuxcnc-ethercat (make then sudo make install, or sudo make clean, make then sudo make install if I switch the linuxcnc version to update the kernel)
My problems are:
-when I try to run Linuxcnc 2.7.14 I have a permission denied on Ethercat0 as shown in
LINUXCNC - 2.7.14
Machine configuration directory is '/home/plotter/linuxcnc/configs/LAMGUI'
Machine configuration file is 'lam.ini'
Starting LinuxCNC...
Found file(REL): ./lam-v1.hal
Note: Using POSIX realtime
Failed to open /dev/EtherCAT0: Permission denied
LCEC: requesting master 0 (index 0) failed
lcec: rtapi_app_main: Invalid argument (-22)
./lam-v1.hal:2: waitpid failed /usr/bin/rtapi_app lcec
./lam-v1.hal:2: /usr/bin/rtapi_app exited without becoming ready
./lam-v1.hal:2: insmod for lcec failed, returned -1
Shutting down and cleaning up LinuxCNC...
Note: Using POSIX realtime
LinuxCNC terminated with an error. You can find more information in the log:
/home/plotter/linuxcnc_debug.txt
and
/home/plotter/linuxcnc_print.txt
as well as in the output of the shell command 'dmesg' and in the terminal
-when I build linuxcnc 2.8.x then install it I got
-LINUXCNC - 2.8.0~pre1
Machine configuration directory is '/home/plotter/linuxcnc/configs/LAMGUI'
Machine configuration file is 'lam.ini'
Starting LinuxCNC...
Found file(REL): ./lam-v1.hal
Note: Using POSIX realtime
lcec: dlopen: /usr/lib/linuxcnc/modules/lcec.so: undefined symbol: rtapi_mutex_get
./lam-v1.hal:2: waitpid failed /usr/bin/rtapi_app lcec
./lam-v1.hal:2: /usr/bin/rtapi_app exited without becoming ready
./lam-v1.hal:2: insmod for lcec failed, returned -1
Shutting down and cleaning up LinuxCNC...
Note: Using POSIX realtime
LinuxCNC terminated with an error. You can find more information in the log:
/home/plotter/linuxcnc_debug.txt
and
/home/plotter/linuxcnc_print.txt
as well as in the output of the shell command 'dmesg' and in the terminal
Any advice about how to make either 2.7 or 2.8 working with the ethercat and linuxcnc ethercat driver?
Cheers,
Nicolas
Please Log in or Create an account to join the conversation.
- Grotius
- Offline
- Platinum Member
-
Less
More
- Posts: 2419
- Thank you received: 2349
8 years 6 days ago - 8 years 6 days ago #119448
by Grotius
Replied by Grotius on topic Ethercat HAL driver
Hi Nico,
Is the file EtherCAT0 in your dev directory on C drive?
I made a empty file EtherCAT0 and placed this in C:dev/
I hope this helps you a little bit.
Failed to open /dev/EtherCAT0: Permission denied,
Is the file EtherCAT0 in your dev directory on C drive?
I made a empty file EtherCAT0 and placed this in C:dev/
I hope this helps you a little bit.
Last edit: 8 years 6 days ago by Grotius.
Please Log in or Create an account to join the conversation.
- Grotius
- Offline
- Platinum Member
-
Less
More
- Posts: 2419
- Thank you received: 2349
8 years 5 days ago - 8 years 5 days ago #119494
by Grotius
Replied by Grotius on topic Ethercat HAL driver
Hi,
I have a general question about the Ethercat.comp file used with Linuxcnc.
Here is a sample of 2 found ethercat.comp file's
Version 1. wiki.linuxcnc.org/cgi-bin/wiki.pl?Contri...EtherCAT_Digital_I_O
Version 2. wiki.linuxcnc.org/cgi-bin/wiki.pl?Etherlab
Version 1:
Version 2:
If you want to compile the ethercat.comp file with latest version of linuxcnc it will not compile.
It has to do with librarie's, and much more. Okey a lot to solve in the component code.
Find out the error code's yourself : sudo halcompile --install ethercat.comp
My idea is to start working on a new ethercat.comp file.
If we get one good ehercat.comp file, that would also a very good Ethercat start option for today's linuxcnc user's i think.
A example : integrating ethercat in a custom made linuxcnc version is now a bit of a problem. In my opinion that is not documented before.
Here is my start of the new component, it compiles without issues :
I have a general question about the Ethercat.comp file used with Linuxcnc.
Here is a sample of 2 found ethercat.comp file's
Version 1. wiki.linuxcnc.org/cgi-bin/wiki.pl?Contri...EtherCAT_Digital_I_O
Version 2. wiki.linuxcnc.org/cgi-bin/wiki.pl?Etherlab
Version 1:
Warning: Spoiler!
component ethercat"Ethercat.";
pin out bit eingang_0;
pin out bit eingang_1;
pin out bit eingang_2;
pin out bit eingang_3;
pin in bit ausgang_0;
pin in bit ausgang_1;
pin in bit ausgang_2;
pin in bit ausgang_3;
option extra_setup;
option extra_cleanup;
//option constructable no;
function update nofp;
;;
MODULE_LICENSE("GPL");
// RTAI
//#include "/usr/realtime-2.6.15-magma/include/rtai_sched.h"
//#include "/usr/realtime-2.6.15-magma/include/rtai_sem.h"
// EtherCAT
#include "/home/ruediger/ethercat-1.3.0/include/ecrt.h"
#include "/home/ruediger/ethercat-1.3.0/include/ecdb.h"
/*****************************************************************************/
// EtherCAT
static ec_master_t *master = NULL;
static ec_domain_t *domain1 = NULL;
spinlock_t master_lock = SPIN_LOCK_UNLOCKED;
static ec_master_status_t master_status, old_status = {};
// data fields
static void *r_dig_in;
static void *r_dig_out;
const static ec_pdo_reg_t domain1_pdo_regs[] = {
{"1", Beckhoff_EL1014_Inputs, &r_dig_in},
{"2", Beckhoff_EL2004_Outputs, &r_dig_out},
{}
};
/*****************************************************************************/
#define MAX 8
int io[MAX] = {0,};
RTAPI_MP_ARRAY_INT(io, MAX, "I/O addresses of serial ports");
/***********************************************************************
* LOCAL FUNCTION DECLARATIONS *
************************************************************************/
static int request_lock(void *data);
static void release_lock(void *data);
/*****************************************************************************/
EXTRA_SETUP() {
ec_slave_t *slave;
rtapi_print_msg(RTAPI_MSG_INFO,"Starting...\n");
//printk(KERN_INFO PFX "Starting...\n");
if (!(master = ecrt_request_master(0))) {
rtapi_print_msg(RTAPI_MSG_INFO,"BRequesting master 0 failed!\n");
//printk(KERN_ERR PFX "Requesting master 0 failed!\n");
goto out_return;
}
ecrt_master_callbacks(master, request_lock, release_lock, NULL);
rtapi_print_msg(RTAPI_MSG_INFO,"Registering domain...\n");
//printk(KERN_INFO PFX "Registering domain...\n");
if (!(domain1 = ecrt_master_create_domain(master))) {
rtapi_print_msg(RTAPI_MSG_INFO,"Domain creation failed!\n");
//printk(KERN_ERR PFX "Domain creation failed!\n");
goto out_release_master;
}
rtapi_print_msg(RTAPI_MSG_INFO,"Registering PDOs...\n");
//rintk(KERN_INFO PFX "Registering PDOs...\n");
if (ecrt_domain_register_pdo_list(domain1, domain1_pdo_regs)) {
rtapi_print_msg(RTAPI_MSG_INFO,"PDO registration failed!\n");
//printk(KERN_ERR PFX "PDO registration failed!\n");
goto out_release_master;
}
rtapi_print_msg(RTAPI_MSG_INFO,"Activating master...\n");
//printk(KERN_INFO PFX "Activating master...\n");
if (ecrt_master_activate(master)) {
rtapi_print_msg(RTAPI_MSG_INFO,"Failed to activate master!\n");
//printk(KERN_ERR PFX "Failed to activate master!\n");
goto out_release_master;
}
rtapi_print_msg(RTAPI_MSG_INFO,"Started.\n");
//printk(KERN_INFO PFX "Started.\n");
return 0;
out_release_master:
rtapi_print_msg(RTAPI_MSG_INFO,"Releasing master...\n");
//printk(KERN_ERR PFX "Releasing master...\n");
ecrt_release_master(master);
out_return:
rtapi_print_msg(RTAPI_MSG_INFO,"Failed to load. Aborting.\n");
//printk(KERN_ERR PFX "Failed to load. Aborting.\n");
return -1;
}
EXTRA_CLEANUP() {
rtapi_print_msg(RTAPI_MSG_INFO,"Stopping...\n");
//printk(KERN_INFO PFX "Stopping...\n");
rtapi_print_msg(RTAPI_MSG_INFO,"Releasing master...\n");
//printk(KERN_INFO PFX "Releasing master...\n");
ecrt_release_master(master);
rtapi_print_msg(RTAPI_MSG_INFO,"Unloading.\n");
//printk(KERN_INFO PFX "Unloading.\n");
}
/*****************************************************/
/*****************************************************/
FUNCTION(update) {
// receive
spin_lock(&master_lock);
ecrt_master_receive(master);
ecrt_domain_process(domain1);
spin_unlock(&master_lock);
//EC_WRITE_U8(r_dig_out, blink ? 0x0F : 0x00);
eingang_0 = EC_READ_BIT(r_dig_in, 0);
eingang_1 = EC_READ_BIT(r_dig_in, 1);
eingang_2 = EC_READ_BIT(r_dig_in, 2);
eingang_3 = EC_READ_BIT(r_dig_in, 3);
EC_WRITE_BIT(r_dig_out, 0, ausgang_0);
EC_WRITE_BIT(r_dig_out, 1, ausgang_1);
EC_WRITE_BIT(r_dig_out, 2, ausgang_2);
EC_WRITE_BIT(r_dig_out, 3, ausgang_3);
spin_lock(&master_lock);
ecrt_master_get_status(master, &master_status);
spin_unlock(&master_lock);
if (master_status.bus_status != old_status.bus_status) {
rtapi_print_msg(RTAPI_MSG_INFO,"bus status changed to %i.\n", master_status.bus_status);
//printk(KERN_INFO PFX "bus status changed to %i.\n",
// master_status.bus_status);
}
if (master_status.bus_tainted != old_status.bus_tainted) {
rtapi_print_msg(RTAPI_MSG_INFO,"tainted flag changed to %u.\n", master_status.bus_tainted);
//printk(KERN_INFO PFX "tainted flag changed to %u.\n",
// master_status.bus_tainted);
}
if (master_status.slaves_responding !=
old_status.slaves_responding) {
rtapi_print_msg(RTAPI_MSG_INFO,"slaves_responding changed to %u.\n", master_status.slaves_responding);
//printk(KERN_INFO PFX "slaves_responding changed to %u.\n",
// master_status.slaves_responding);
}
old_status = master_status;
// send
spin_lock(&master_lock);
ecrt_domain_queue(domain1);
spin_unlock(&master_lock);
spin_lock(&master_lock);
ecrt_master_send(master);
spin_unlock(&master_lock);
}
/*****************************************************************************/
static int request_lock(void *data)
{
spin_lock(&master_lock);
return 0; // access allowed
}
/*****************************************************************************/
static void release_lock(void *data)
{
spin_unlock(&master_lock);
}
/*****************************************************************************/
pin out bit eingang_0;
pin out bit eingang_1;
pin out bit eingang_2;
pin out bit eingang_3;
pin in bit ausgang_0;
pin in bit ausgang_1;
pin in bit ausgang_2;
pin in bit ausgang_3;
option extra_setup;
option extra_cleanup;
//option constructable no;
function update nofp;
;;
MODULE_LICENSE("GPL");
// RTAI
//#include "/usr/realtime-2.6.15-magma/include/rtai_sched.h"
//#include "/usr/realtime-2.6.15-magma/include/rtai_sem.h"
// EtherCAT
#include "/home/ruediger/ethercat-1.3.0/include/ecrt.h"
#include "/home/ruediger/ethercat-1.3.0/include/ecdb.h"
/*****************************************************************************/
// EtherCAT
static ec_master_t *master = NULL;
static ec_domain_t *domain1 = NULL;
spinlock_t master_lock = SPIN_LOCK_UNLOCKED;
static ec_master_status_t master_status, old_status = {};
// data fields
static void *r_dig_in;
static void *r_dig_out;
const static ec_pdo_reg_t domain1_pdo_regs[] = {
{"1", Beckhoff_EL1014_Inputs, &r_dig_in},
{"2", Beckhoff_EL2004_Outputs, &r_dig_out},
{}
};
/*****************************************************************************/
#define MAX 8
int io[MAX] = {0,};
RTAPI_MP_ARRAY_INT(io, MAX, "I/O addresses of serial ports");
/***********************************************************************
* LOCAL FUNCTION DECLARATIONS *
************************************************************************/
static int request_lock(void *data);
static void release_lock(void *data);
/*****************************************************************************/
EXTRA_SETUP() {
ec_slave_t *slave;
rtapi_print_msg(RTAPI_MSG_INFO,"Starting...\n");
//printk(KERN_INFO PFX "Starting...\n");
if (!(master = ecrt_request_master(0))) {
rtapi_print_msg(RTAPI_MSG_INFO,"BRequesting master 0 failed!\n");
//printk(KERN_ERR PFX "Requesting master 0 failed!\n");
goto out_return;
}
ecrt_master_callbacks(master, request_lock, release_lock, NULL);
rtapi_print_msg(RTAPI_MSG_INFO,"Registering domain...\n");
//printk(KERN_INFO PFX "Registering domain...\n");
if (!(domain1 = ecrt_master_create_domain(master))) {
rtapi_print_msg(RTAPI_MSG_INFO,"Domain creation failed!\n");
//printk(KERN_ERR PFX "Domain creation failed!\n");
goto out_release_master;
}
rtapi_print_msg(RTAPI_MSG_INFO,"Registering PDOs...\n");
//rintk(KERN_INFO PFX "Registering PDOs...\n");
if (ecrt_domain_register_pdo_list(domain1, domain1_pdo_regs)) {
rtapi_print_msg(RTAPI_MSG_INFO,"PDO registration failed!\n");
//printk(KERN_ERR PFX "PDO registration failed!\n");
goto out_release_master;
}
rtapi_print_msg(RTAPI_MSG_INFO,"Activating master...\n");
//printk(KERN_INFO PFX "Activating master...\n");
if (ecrt_master_activate(master)) {
rtapi_print_msg(RTAPI_MSG_INFO,"Failed to activate master!\n");
//printk(KERN_ERR PFX "Failed to activate master!\n");
goto out_release_master;
}
rtapi_print_msg(RTAPI_MSG_INFO,"Started.\n");
//printk(KERN_INFO PFX "Started.\n");
return 0;
out_release_master:
rtapi_print_msg(RTAPI_MSG_INFO,"Releasing master...\n");
//printk(KERN_ERR PFX "Releasing master...\n");
ecrt_release_master(master);
out_return:
rtapi_print_msg(RTAPI_MSG_INFO,"Failed to load. Aborting.\n");
//printk(KERN_ERR PFX "Failed to load. Aborting.\n");
return -1;
}
EXTRA_CLEANUP() {
rtapi_print_msg(RTAPI_MSG_INFO,"Stopping...\n");
//printk(KERN_INFO PFX "Stopping...\n");
rtapi_print_msg(RTAPI_MSG_INFO,"Releasing master...\n");
//printk(KERN_INFO PFX "Releasing master...\n");
ecrt_release_master(master);
rtapi_print_msg(RTAPI_MSG_INFO,"Unloading.\n");
//printk(KERN_INFO PFX "Unloading.\n");
}
/*****************************************************/
/*****************************************************/
FUNCTION(update) {
// receive
spin_lock(&master_lock);
ecrt_master_receive(master);
ecrt_domain_process(domain1);
spin_unlock(&master_lock);
//EC_WRITE_U8(r_dig_out, blink ? 0x0F : 0x00);
eingang_0 = EC_READ_BIT(r_dig_in, 0);
eingang_1 = EC_READ_BIT(r_dig_in, 1);
eingang_2 = EC_READ_BIT(r_dig_in, 2);
eingang_3 = EC_READ_BIT(r_dig_in, 3);
EC_WRITE_BIT(r_dig_out, 0, ausgang_0);
EC_WRITE_BIT(r_dig_out, 1, ausgang_1);
EC_WRITE_BIT(r_dig_out, 2, ausgang_2);
EC_WRITE_BIT(r_dig_out, 3, ausgang_3);
spin_lock(&master_lock);
ecrt_master_get_status(master, &master_status);
spin_unlock(&master_lock);
if (master_status.bus_status != old_status.bus_status) {
rtapi_print_msg(RTAPI_MSG_INFO,"bus status changed to %i.\n", master_status.bus_status);
//printk(KERN_INFO PFX "bus status changed to %i.\n",
// master_status.bus_status);
}
if (master_status.bus_tainted != old_status.bus_tainted) {
rtapi_print_msg(RTAPI_MSG_INFO,"tainted flag changed to %u.\n", master_status.bus_tainted);
//printk(KERN_INFO PFX "tainted flag changed to %u.\n",
// master_status.bus_tainted);
}
if (master_status.slaves_responding !=
old_status.slaves_responding) {
rtapi_print_msg(RTAPI_MSG_INFO,"slaves_responding changed to %u.\n", master_status.slaves_responding);
//printk(KERN_INFO PFX "slaves_responding changed to %u.\n",
// master_status.slaves_responding);
}
old_status = master_status;
// send
spin_lock(&master_lock);
ecrt_domain_queue(domain1);
spin_unlock(&master_lock);
spin_lock(&master_lock);
ecrt_master_send(master);
spin_unlock(&master_lock);
}
/*****************************************************************************/
static int request_lock(void *data)
{
spin_lock(&master_lock);
return 0; // access allowed
}
/*****************************************************************************/
static void release_lock(void *data)
{
spin_unlock(&master_lock);
}
/*****************************************************************************/
Version 2:
Warning: Spoiler!
component ethercat"Ethercat.";
pin out bit eingang_0;
pin out bit eingang_1;
pin out bit eingang_2;
pin out bit eingang_3;
pin out bit eingang_4;
pin out bit eingang_5;
pin out bit eingang_6;
pin out bit eingang_7;
pin in bit ausgang_0;
pin in bit ausgang_1;
pin in bit ausgang_2;
pin in bit ausgang_3;
pin in bit ausgang_4;
pin in bit ausgang_5;
pin in bit ausgang_6;
pin in bit ausgang_7;
option extra_setup;
option extra_cleanup;
//option constructable no;
function update nofp;
license "GPL";
;;
#include "/opt/ethercat/include/ecrt.h"
/*****************************************************************************/
// EtherCAT
static ec_master_t *master = NULL;
static ec_domain_t *domain1 = NULL;
spinlock_t master_lock = SPIN_LOCK_UNLOCKED;
static ec_master_state_t master_status, old_status = {};
// data fields
static uint8_t *domain1_pd; // process data memory
// offsets to data fields
static unsigned int o_dig_in[8], bo_dig_in[8];
static unsigned int o_dig_out[8], bo_dig_out[8];
// pdo definitions may be read from autogenerated file
//#include "ethercat_cstruct.c"
#define Beckhoff_EL2004 0x00000002, 0x07D43052
#define Beckhoff_EL1014 0x00000002, 0x03F63052
const static ec_pdo_entry_reg_t domain1_pdo_regs[] = {
{ 0, 1, Beckhoff_EL2004, 0x7000, 1, &o_dig_out[0], &bo_dig_in[0]},
{ 0, 1, Beckhoff_EL2004, 0x7010, 1, &o_dig_out[1], &bo_dig_in[1]},
{ 0, 1, Beckhoff_EL2004, 0x7020, 1, &o_dig_out[2], &bo_dig_in[2]},
{ 0, 1, Beckhoff_EL2004, 0x7030, 1, &o_dig_out[3], &bo_dig_in[3]},
{ 0, 2, Beckhoff_EL2004, 0x7000, 1, &o_dig_out[4], &bo_dig_in[4]},
{ 0, 2, Beckhoff_EL2004, 0x7010, 1, &o_dig_out[5], &bo_dig_in[5]},
{ 0, 2, Beckhoff_EL2004, 0x7020, 1, &o_dig_out[6], &bo_dig_in[6]},
{ 0, 2, Beckhoff_EL2004, 0x7030, 1, &o_dig_out[7], &bo_dig_in[7]},
{ 0, 3, Beckhoff_EL1014, 0x6000, 1, &o_dig_in[0] , &bo_dig_out[0]},
{ 0, 3, Beckhoff_EL1014, 0x6010, 1, &o_dig_in[1] , &bo_dig_out[1]},
{ 0, 3, Beckhoff_EL1014, 0x6020, 1, &o_dig_in[2] , &bo_dig_out[2]},
{ 0, 3, Beckhoff_EL1014, 0x6030, 1, &o_dig_in[3] , &bo_dig_out[3]},
{ 0, 4, Beckhoff_EL1014, 0x6000, 1, &o_dig_in[4] , &bo_dig_out[4]},
{ 0, 4, Beckhoff_EL1014, 0x6010, 1, &o_dig_in[5] , &bo_dig_out[5]},
{ 0, 4, Beckhoff_EL1014, 0x6020, 1, &o_dig_in[6] , &bo_dig_out[6]},
{ 0, 4, Beckhoff_EL1014, 0x6030, 1, &o_dig_in[7] , &bo_dig_out[7]},
/* { 0, 1, Beckhoff_EL2004, 0x7000, 1, &o_dig_out[0], NULL}, */
/* { 0, 4, Beckhoff_EL1014, 0x6000, 1, &o_dig_in[0] , NULL}, */
{}
};
/***********************************************************************
* LOCAL FUNCTION DECLARATIONS *
************************************************************************/
void request_lock(void *data)
{
spin_lock(&master_lock);
}
void release_lock(void *data)
{
spin_unlock(&master_lock);
}
/*****************************************************************************/
EXTRA_SETUP() {
rtapi_print_msg(RTAPI_MSG_INFO,"Starting...\n");
//printk(KERN_INFO PFX "Starting...\n");
if (!(master = ecrt_request_master(0))) {
rtapi_print_msg(RTAPI_MSG_INFO,"BRequesting master 0 failed!\n");
//printk(KERN_ERR PFX "Requesting master 0 failed!\n");
goto out_return;
}
ecrt_master_callbacks(master, request_lock, release_lock, NULL);
rtapi_print_msg(RTAPI_MSG_INFO,"Registering domain...\n");
//printk(KERN_INFO PFX "Registering domain...\n");
if (!(domain1 = ecrt_master_create_domain(master))) {
rtapi_print_msg(RTAPI_MSG_INFO,"Domain creation failed!\n");
//printk(KERN_ERR PFX "Domain creation failed!\n");
goto out_release_master;
}
rtapi_print_msg(RTAPI_MSG_INFO,"Registering PDOs...\n");
//rintk(KERN_INFO PFX "Registering PDOs...\n");
if (ecrt_domain_reg_pdo_entry_list(domain1, domain1_pdo_regs)) {
rtapi_print_msg(RTAPI_MSG_INFO,"PDO registration failed!\n");
//printk(KERN_ERR PFX "PDO registration failed!\n");
goto out_release_master;
}
rtapi_print_msg(RTAPI_MSG_INFO,"Activating master...\n");
//printk(KERN_INFO PFX "Activating master...\n");
if (ecrt_master_activate(master)) {
rtapi_print_msg(RTAPI_MSG_INFO,"Failed to activate master!\n");
//printk(KERN_ERR PFX "Failed to activate master!\n");
goto out_release_master;
}
domain1_pd = ecrt_domain_data(domain1);
rtapi_print_msg(RTAPI_MSG_INFO,"Started.\n");
//printk(KERN_INFO PFX "Started.\n");
return 0;
out_release_master:
rtapi_print_msg(RTAPI_MSG_INFO,"Releasing master...\n");
//printk(KERN_ERR PFX "Releasing master...\n");
ecrt_release_master(master);
master= NULL;
out_return:
rtapi_print_msg(RTAPI_MSG_INFO,"Failed to load. Aborting.\n");
//printk(KERN_ERR PFX "Failed to load. Aborting.\n");
return -1;
}
EXTRA_CLEANUP() {
rtapi_print_msg(RTAPI_MSG_INFO,"Stopping...\n");
//printk(KERN_INFO PFX "Stopping...\n");
if (master) {
rtapi_print_msg(RTAPI_MSG_INFO,"Releasing master...\n");
//printk(KERN_INFO PFX "Releasing master...\n");
ecrt_release_master(master);
}
rtapi_print_msg(RTAPI_MSG_INFO,"Unloading.\n");
//printk(KERN_INFO PFX "Unloading.\n");
}
/*****************************************************/
/*****************************************************/
FUNCTION(update) {
// receive
spin_lock(&master_lock);
ecrt_master_receive(master);
ecrt_domain_process(domain1);
spin_unlock(&master_lock);
eingang_0 = EC_READ_BIT( domain1_pd+o_dig_in[0], bo_dig_in[0]);
eingang_1 = EC_READ_BIT( domain1_pd+o_dig_in[1], bo_dig_in[1]);
eingang_2 = EC_READ_BIT( domain1_pd+o_dig_in[2], bo_dig_in[2]);
eingang_3 = EC_READ_BIT( domain1_pd+o_dig_in[3], bo_dig_in[3]);
eingang_4 = EC_READ_BIT( domain1_pd+o_dig_in[4], bo_dig_in[4]);
eingang_5 = EC_READ_BIT( domain1_pd+o_dig_in[5], bo_dig_in[5]);
eingang_6 = EC_READ_BIT( domain1_pd+o_dig_in[6], bo_dig_in[6]);
eingang_7 = EC_READ_BIT( domain1_pd+o_dig_in[7], bo_dig_in[7]);
EC_WRITE_BIT(domain1_pd+o_dig_out[0], bo_dig_out[0], ausgang_0);
EC_WRITE_BIT(domain1_pd+o_dig_out[1], bo_dig_out[1], ausgang_1);
EC_WRITE_BIT(domain1_pd+o_dig_out[2], bo_dig_out[2], ausgang_2);
EC_WRITE_BIT(domain1_pd+o_dig_out[3], bo_dig_out[3], ausgang_3);
EC_WRITE_BIT(domain1_pd+o_dig_out[4], bo_dig_out[4], ausgang_4);
EC_WRITE_BIT(domain1_pd+o_dig_out[5], bo_dig_out[5], ausgang_5);
EC_WRITE_BIT(domain1_pd+o_dig_out[6], bo_dig_out[6], ausgang_6);
EC_WRITE_BIT(domain1_pd+o_dig_out[7], bo_dig_out[7], ausgang_7);
/* eingang_0= EC_READ_BIT( domain1_pd+o_dig_in[0],0); */
/* EC_WRITE_BIT(domain1_pd+o_dig_out[0],0,ausgang_0); */
spin_lock(&master_lock);
ecrt_master_state(master, &master_status);
spin_unlock(&master_lock);
if (master_status.al_states != old_status.al_states) {
rtapi_print_msg(RTAPI_MSG_INFO,"bus status changed to %i.\n", master_status.al_states);
}
if (master_status.slaves_responding !=
old_status.slaves_responding) {
rtapi_print_msg(RTAPI_MSG_INFO,"slaves_responding changed to %u.\n", master_status.slaves_responding);
}
old_status = master_status;
// send
spin_lock(&master_lock);
ecrt_domain_queue(domain1);
spin_unlock(&master_lock);
spin_lock(&master_lock);
ecrt_master_send(master);
spin_unlock(&master_lock);
}
pin out bit eingang_0;
pin out bit eingang_1;
pin out bit eingang_2;
pin out bit eingang_3;
pin out bit eingang_4;
pin out bit eingang_5;
pin out bit eingang_6;
pin out bit eingang_7;
pin in bit ausgang_0;
pin in bit ausgang_1;
pin in bit ausgang_2;
pin in bit ausgang_3;
pin in bit ausgang_4;
pin in bit ausgang_5;
pin in bit ausgang_6;
pin in bit ausgang_7;
option extra_setup;
option extra_cleanup;
//option constructable no;
function update nofp;
license "GPL";
;;
#include "/opt/ethercat/include/ecrt.h"
/*****************************************************************************/
// EtherCAT
static ec_master_t *master = NULL;
static ec_domain_t *domain1 = NULL;
spinlock_t master_lock = SPIN_LOCK_UNLOCKED;
static ec_master_state_t master_status, old_status = {};
// data fields
static uint8_t *domain1_pd; // process data memory
// offsets to data fields
static unsigned int o_dig_in[8], bo_dig_in[8];
static unsigned int o_dig_out[8], bo_dig_out[8];
// pdo definitions may be read from autogenerated file
//#include "ethercat_cstruct.c"
#define Beckhoff_EL2004 0x00000002, 0x07D43052
#define Beckhoff_EL1014 0x00000002, 0x03F63052
const static ec_pdo_entry_reg_t domain1_pdo_regs[] = {
{ 0, 1, Beckhoff_EL2004, 0x7000, 1, &o_dig_out[0], &bo_dig_in[0]},
{ 0, 1, Beckhoff_EL2004, 0x7010, 1, &o_dig_out[1], &bo_dig_in[1]},
{ 0, 1, Beckhoff_EL2004, 0x7020, 1, &o_dig_out[2], &bo_dig_in[2]},
{ 0, 1, Beckhoff_EL2004, 0x7030, 1, &o_dig_out[3], &bo_dig_in[3]},
{ 0, 2, Beckhoff_EL2004, 0x7000, 1, &o_dig_out[4], &bo_dig_in[4]},
{ 0, 2, Beckhoff_EL2004, 0x7010, 1, &o_dig_out[5], &bo_dig_in[5]},
{ 0, 2, Beckhoff_EL2004, 0x7020, 1, &o_dig_out[6], &bo_dig_in[6]},
{ 0, 2, Beckhoff_EL2004, 0x7030, 1, &o_dig_out[7], &bo_dig_in[7]},
{ 0, 3, Beckhoff_EL1014, 0x6000, 1, &o_dig_in[0] , &bo_dig_out[0]},
{ 0, 3, Beckhoff_EL1014, 0x6010, 1, &o_dig_in[1] , &bo_dig_out[1]},
{ 0, 3, Beckhoff_EL1014, 0x6020, 1, &o_dig_in[2] , &bo_dig_out[2]},
{ 0, 3, Beckhoff_EL1014, 0x6030, 1, &o_dig_in[3] , &bo_dig_out[3]},
{ 0, 4, Beckhoff_EL1014, 0x6000, 1, &o_dig_in[4] , &bo_dig_out[4]},
{ 0, 4, Beckhoff_EL1014, 0x6010, 1, &o_dig_in[5] , &bo_dig_out[5]},
{ 0, 4, Beckhoff_EL1014, 0x6020, 1, &o_dig_in[6] , &bo_dig_out[6]},
{ 0, 4, Beckhoff_EL1014, 0x6030, 1, &o_dig_in[7] , &bo_dig_out[7]},
/* { 0, 1, Beckhoff_EL2004, 0x7000, 1, &o_dig_out[0], NULL}, */
/* { 0, 4, Beckhoff_EL1014, 0x6000, 1, &o_dig_in[0] , NULL}, */
{}
};
/***********************************************************************
* LOCAL FUNCTION DECLARATIONS *
************************************************************************/
void request_lock(void *data)
{
spin_lock(&master_lock);
}
void release_lock(void *data)
{
spin_unlock(&master_lock);
}
/*****************************************************************************/
EXTRA_SETUP() {
rtapi_print_msg(RTAPI_MSG_INFO,"Starting...\n");
//printk(KERN_INFO PFX "Starting...\n");
if (!(master = ecrt_request_master(0))) {
rtapi_print_msg(RTAPI_MSG_INFO,"BRequesting master 0 failed!\n");
//printk(KERN_ERR PFX "Requesting master 0 failed!\n");
goto out_return;
}
ecrt_master_callbacks(master, request_lock, release_lock, NULL);
rtapi_print_msg(RTAPI_MSG_INFO,"Registering domain...\n");
//printk(KERN_INFO PFX "Registering domain...\n");
if (!(domain1 = ecrt_master_create_domain(master))) {
rtapi_print_msg(RTAPI_MSG_INFO,"Domain creation failed!\n");
//printk(KERN_ERR PFX "Domain creation failed!\n");
goto out_release_master;
}
rtapi_print_msg(RTAPI_MSG_INFO,"Registering PDOs...\n");
//rintk(KERN_INFO PFX "Registering PDOs...\n");
if (ecrt_domain_reg_pdo_entry_list(domain1, domain1_pdo_regs)) {
rtapi_print_msg(RTAPI_MSG_INFO,"PDO registration failed!\n");
//printk(KERN_ERR PFX "PDO registration failed!\n");
goto out_release_master;
}
rtapi_print_msg(RTAPI_MSG_INFO,"Activating master...\n");
//printk(KERN_INFO PFX "Activating master...\n");
if (ecrt_master_activate(master)) {
rtapi_print_msg(RTAPI_MSG_INFO,"Failed to activate master!\n");
//printk(KERN_ERR PFX "Failed to activate master!\n");
goto out_release_master;
}
domain1_pd = ecrt_domain_data(domain1);
rtapi_print_msg(RTAPI_MSG_INFO,"Started.\n");
//printk(KERN_INFO PFX "Started.\n");
return 0;
out_release_master:
rtapi_print_msg(RTAPI_MSG_INFO,"Releasing master...\n");
//printk(KERN_ERR PFX "Releasing master...\n");
ecrt_release_master(master);
master= NULL;
out_return:
rtapi_print_msg(RTAPI_MSG_INFO,"Failed to load. Aborting.\n");
//printk(KERN_ERR PFX "Failed to load. Aborting.\n");
return -1;
}
EXTRA_CLEANUP() {
rtapi_print_msg(RTAPI_MSG_INFO,"Stopping...\n");
//printk(KERN_INFO PFX "Stopping...\n");
if (master) {
rtapi_print_msg(RTAPI_MSG_INFO,"Releasing master...\n");
//printk(KERN_INFO PFX "Releasing master...\n");
ecrt_release_master(master);
}
rtapi_print_msg(RTAPI_MSG_INFO,"Unloading.\n");
//printk(KERN_INFO PFX "Unloading.\n");
}
/*****************************************************/
/*****************************************************/
FUNCTION(update) {
// receive
spin_lock(&master_lock);
ecrt_master_receive(master);
ecrt_domain_process(domain1);
spin_unlock(&master_lock);
eingang_0 = EC_READ_BIT( domain1_pd+o_dig_in[0], bo_dig_in[0]);
eingang_1 = EC_READ_BIT( domain1_pd+o_dig_in[1], bo_dig_in[1]);
eingang_2 = EC_READ_BIT( domain1_pd+o_dig_in[2], bo_dig_in[2]);
eingang_3 = EC_READ_BIT( domain1_pd+o_dig_in[3], bo_dig_in[3]);
eingang_4 = EC_READ_BIT( domain1_pd+o_dig_in[4], bo_dig_in[4]);
eingang_5 = EC_READ_BIT( domain1_pd+o_dig_in[5], bo_dig_in[5]);
eingang_6 = EC_READ_BIT( domain1_pd+o_dig_in[6], bo_dig_in[6]);
eingang_7 = EC_READ_BIT( domain1_pd+o_dig_in[7], bo_dig_in[7]);
EC_WRITE_BIT(domain1_pd+o_dig_out[0], bo_dig_out[0], ausgang_0);
EC_WRITE_BIT(domain1_pd+o_dig_out[1], bo_dig_out[1], ausgang_1);
EC_WRITE_BIT(domain1_pd+o_dig_out[2], bo_dig_out[2], ausgang_2);
EC_WRITE_BIT(domain1_pd+o_dig_out[3], bo_dig_out[3], ausgang_3);
EC_WRITE_BIT(domain1_pd+o_dig_out[4], bo_dig_out[4], ausgang_4);
EC_WRITE_BIT(domain1_pd+o_dig_out[5], bo_dig_out[5], ausgang_5);
EC_WRITE_BIT(domain1_pd+o_dig_out[6], bo_dig_out[6], ausgang_6);
EC_WRITE_BIT(domain1_pd+o_dig_out[7], bo_dig_out[7], ausgang_7);
/* eingang_0= EC_READ_BIT( domain1_pd+o_dig_in[0],0); */
/* EC_WRITE_BIT(domain1_pd+o_dig_out[0],0,ausgang_0); */
spin_lock(&master_lock);
ecrt_master_state(master, &master_status);
spin_unlock(&master_lock);
if (master_status.al_states != old_status.al_states) {
rtapi_print_msg(RTAPI_MSG_INFO,"bus status changed to %i.\n", master_status.al_states);
}
if (master_status.slaves_responding !=
old_status.slaves_responding) {
rtapi_print_msg(RTAPI_MSG_INFO,"slaves_responding changed to %u.\n", master_status.slaves_responding);
}
old_status = master_status;
// send
spin_lock(&master_lock);
ecrt_domain_queue(domain1);
spin_unlock(&master_lock);
spin_lock(&master_lock);
ecrt_master_send(master);
spin_unlock(&master_lock);
}
If you want to compile the ethercat.comp file with latest version of linuxcnc it will not compile.
It has to do with librarie's, and much more. Okey a lot to solve in the component code.
Find out the error code's yourself : sudo halcompile --install ethercat.comp
My idea is to start working on a new ethercat.comp file.
If we get one good ehercat.comp file, that would also a very good Ethercat start option for today's linuxcnc user's i think.
A example : integrating ethercat in a custom made linuxcnc version is now a bit of a problem. In my opinion that is not documented before.
Here is my start of the new component, it compiles without issues :
Warning: Spoiler!
component ethercat"Ethercat.";
description
"""
Ethercat Component
Modification list :
1. Changed include source from ethercat to etherlab
2. Start from zero
3. When writing a new component it is importand to use also "case" in programming style.
This will make a nice routing in the workflow of handling different senario's, like emergency stop,
and what to do in that senario.
Expanding "case" is very easy, just copy and rename a case, and add case name to typedef enum.
4. Don't us goto statements in your code.
5. In C style you can write your mind into the code.
""";
author "Grotius CNC Machines, started Oktober 2018";
license "GPL";
option singleton yes;
//Ethercat terminal hal connection :
//Servo hal connection :
//Stepper hal connection ;
//Input hal connection :
pin in bit Enable "Enable this ethercat component";
pin in bit Input_0 "Comment ....";
//Output hal connection :
pin out bit Ethercat_enabled "Connect to user gui led";
pin out bit Output_0 "Comment ....";
function _;
;;
#include "/opt/etherlab/include/ecrt.h"
// EtherCAT
static ec_master_t *master = NULL;
static ec_domain_t *domain1 = NULL;
//spinlock_t master_lock = SPIN_LOCK_UNLOCKED;
static ec_master_state_t master_status, old_status = {};
// data fields
static uint8_t *domain1_pd; // process data memory
// offsets to data fields
static unsigned int o_dig_in[8], bo_dig_in[8];
static unsigned int o_dig_out[8], bo_dig_out[8];
// pdo definitions may be read from autogenerated file
//#include "ethercat_cstruct.c"
#define Beckhoff_EL2004 0x00000002, 0x07D43052
#define Beckhoff_EL1014 0x00000002, 0x03F63052
const static ec_pdo_entry_reg_t domain1_pdo_regs[] = {
{ 0, 1, Beckhoff_EL2004, 0x7000, 1, &o_dig_out[0], &bo_dig_in[0]},
{ 0, 1, Beckhoff_EL2004, 0x7010, 1, &o_dig_out[1], &bo_dig_in[1]},
{ 0, 1, Beckhoff_EL2004, 0x7020, 1, &o_dig_out[2], &bo_dig_in[2]},
{ 0, 1, Beckhoff_EL2004, 0x7030, 1, &o_dig_out[3], &bo_dig_in[3]},
{ 0, 2, Beckhoff_EL2004, 0x7000, 1, &o_dig_out[4], &bo_dig_in[4]},
{ 0, 2, Beckhoff_EL2004, 0x7010, 1, &o_dig_out[5], &bo_dig_in[5]},
{ 0, 2, Beckhoff_EL2004, 0x7020, 1, &o_dig_out[6], &bo_dig_in[6]},
{ 0, 2, Beckhoff_EL2004, 0x7030, 1, &o_dig_out[7], &bo_dig_in[7]},
{ 0, 3, Beckhoff_EL1014, 0x6000, 1, &o_dig_in[0] , &bo_dig_out[0]},
{ 0, 3, Beckhoff_EL1014, 0x6010, 1, &o_dig_in[1] , &bo_dig_out[1]},
{ 0, 3, Beckhoff_EL1014, 0x6020, 1, &o_dig_in[2] , &bo_dig_out[2]},
{ 0, 3, Beckhoff_EL1014, 0x6030, 1, &o_dig_in[3] , &bo_dig_out[3]},
{ 0, 4, Beckhoff_EL1014, 0x6000, 1, &o_dig_in[4] , &bo_dig_out[4]},
{ 0, 4, Beckhoff_EL1014, 0x6010, 1, &o_dig_in[5] , &bo_dig_out[5]},
{ 0, 4, Beckhoff_EL1014, 0x6020, 1, &o_dig_in[6] , &bo_dig_out[6]},
{ 0, 4, Beckhoff_EL1014, 0x6030, 1, &o_dig_in[7] , &bo_dig_out[7]},
};
typedef enum { INIT, SELECT} state_T;
state_T state = INIT;
FUNCTION(_) {
switch(state){
case INIT:
if(Enable){
Ethercat_enabled = 1;
state = SELECT; // If ethercat input is enabled the case function jump's to case SELECT:
}
if(!Enable){
Ethercat_enabled = 0;
state = INIT;
}
break;
case SELECT:
domain1_pd = ecrt_domain_data(domain1);
ecrt_master_receive(master);
ecrt_domain_process(domain1);
EC_WRITE_BIT(domain1_pd+o_dig_out[0], bo_dig_out[0], Output_0);
break;
}
}
description
"""
Ethercat Component
Modification list :
1. Changed include source from ethercat to etherlab
2. Start from zero
3. When writing a new component it is importand to use also "case" in programming style.
This will make a nice routing in the workflow of handling different senario's, like emergency stop,
and what to do in that senario.
Expanding "case" is very easy, just copy and rename a case, and add case name to typedef enum.
4. Don't us goto statements in your code.
5. In C style you can write your mind into the code.
""";
author "Grotius CNC Machines, started Oktober 2018";
license "GPL";
option singleton yes;
//Ethercat terminal hal connection :
//Servo hal connection :
//Stepper hal connection ;
//Input hal connection :
pin in bit Enable "Enable this ethercat component";
pin in bit Input_0 "Comment ....";
//Output hal connection :
pin out bit Ethercat_enabled "Connect to user gui led";
pin out bit Output_0 "Comment ....";
function _;
;;
#include "/opt/etherlab/include/ecrt.h"
// EtherCAT
static ec_master_t *master = NULL;
static ec_domain_t *domain1 = NULL;
//spinlock_t master_lock = SPIN_LOCK_UNLOCKED;
static ec_master_state_t master_status, old_status = {};
// data fields
static uint8_t *domain1_pd; // process data memory
// offsets to data fields
static unsigned int o_dig_in[8], bo_dig_in[8];
static unsigned int o_dig_out[8], bo_dig_out[8];
// pdo definitions may be read from autogenerated file
//#include "ethercat_cstruct.c"
#define Beckhoff_EL2004 0x00000002, 0x07D43052
#define Beckhoff_EL1014 0x00000002, 0x03F63052
const static ec_pdo_entry_reg_t domain1_pdo_regs[] = {
{ 0, 1, Beckhoff_EL2004, 0x7000, 1, &o_dig_out[0], &bo_dig_in[0]},
{ 0, 1, Beckhoff_EL2004, 0x7010, 1, &o_dig_out[1], &bo_dig_in[1]},
{ 0, 1, Beckhoff_EL2004, 0x7020, 1, &o_dig_out[2], &bo_dig_in[2]},
{ 0, 1, Beckhoff_EL2004, 0x7030, 1, &o_dig_out[3], &bo_dig_in[3]},
{ 0, 2, Beckhoff_EL2004, 0x7000, 1, &o_dig_out[4], &bo_dig_in[4]},
{ 0, 2, Beckhoff_EL2004, 0x7010, 1, &o_dig_out[5], &bo_dig_in[5]},
{ 0, 2, Beckhoff_EL2004, 0x7020, 1, &o_dig_out[6], &bo_dig_in[6]},
{ 0, 2, Beckhoff_EL2004, 0x7030, 1, &o_dig_out[7], &bo_dig_in[7]},
{ 0, 3, Beckhoff_EL1014, 0x6000, 1, &o_dig_in[0] , &bo_dig_out[0]},
{ 0, 3, Beckhoff_EL1014, 0x6010, 1, &o_dig_in[1] , &bo_dig_out[1]},
{ 0, 3, Beckhoff_EL1014, 0x6020, 1, &o_dig_in[2] , &bo_dig_out[2]},
{ 0, 3, Beckhoff_EL1014, 0x6030, 1, &o_dig_in[3] , &bo_dig_out[3]},
{ 0, 4, Beckhoff_EL1014, 0x6000, 1, &o_dig_in[4] , &bo_dig_out[4]},
{ 0, 4, Beckhoff_EL1014, 0x6010, 1, &o_dig_in[5] , &bo_dig_out[5]},
{ 0, 4, Beckhoff_EL1014, 0x6020, 1, &o_dig_in[6] , &bo_dig_out[6]},
{ 0, 4, Beckhoff_EL1014, 0x6030, 1, &o_dig_in[7] , &bo_dig_out[7]},
};
typedef enum { INIT, SELECT} state_T;
state_T state = INIT;
FUNCTION(_) {
switch(state){
case INIT:
if(Enable){
Ethercat_enabled = 1;
state = SELECT; // If ethercat input is enabled the case function jump's to case SELECT:
}
if(!Enable){
Ethercat_enabled = 0;
state = INIT;
}
break;
case SELECT:
domain1_pd = ecrt_domain_data(domain1);
ecrt_master_receive(master);
ecrt_domain_process(domain1);
EC_WRITE_BIT(domain1_pd+o_dig_out[0], bo_dig_out[0], Output_0);
break;
}
}
Last edit: 8 years 5 days ago by Grotius.
Please Log in or Create an account to join the conversation.
- Nico2017
- Offline
- Premium Member
-
Less
More
- Posts: 153
- Thank you received: 26
8 years 3 days ago - 7 years 11 months ago #119562
by Nico2017
Replied by Nico2017 on topic Ethercat HAL driver
Hi @Grotius,
it does actually help.
The /dev/Ethercat0 was already there but with some restrained permission so after a sudo chmod a+rwx Ethercat0, the linuxcnc 2.7 and linuxcnc 2.8 were able to carry on.The only issue is I have to do that everytime I log in as the permission seems not to be saved for some reason. Any idea about how I could make the permission permanent?
Edit: to make the /dev/EtherCAT0 usage permanent just do sudo adduser $USER ethercat, and/or sudo adduser root ethercat then you have to reboot (see post askubuntu.com/questions/373096/how-do-i-...ssions-for-dev-ttys0 for a similar case.)
However it did show another error for linuxcnc 2.8, which I believe is link to an error seen on the make of the linuxcnc-ethercat.
Using the linuxcnc-ethercat last commit:
commit b02252a79d11f1c9dd5884bac1a53743b3818d39
Merge: 22bcaa9 333dec5
Author: Sascha Ittner <sascha.ittner@modusoft.de>
Date: Fri Aug 17 16:37:32 2018 +0200
Merge pull request #60 from sittner/add-fsoe-support
Add fsoe support
I obtain
LINUXCNC - 2.8.0~pre1
Machine configuration directory is '/home/laminator/linuxcnc/configs/LAMGUI'
Machine configuration file is 'lam.ini'
Starting LinuxCNC...
Found file(REL): ./lam-v1.hal
Note: Using POSIX realtime
lcec: dlopen: /usr/lib/linuxcnc/modules/lcec.so: undefined symbol: rtapi_mutex_get
./lam-v1.hal:2: waitpid failed /usr/bin/rtapi_app lcec
./lam-v1.hal:2: /usr/bin/rtapi_app exited without becoming ready
./lam-v1.hal:2: insmod for lcec failed, returned -1
Shutting down and cleaning up LinuxCNC...
Note: Using POSIX realtime
LinuxCNC terminated with an error. You can find more information in the log:
/home/laminator/linuxcnc_debug.txt
and
/home/laminator/linuxcnc_print.txt
as well as in the output of the shell command 'dmesg' and in the terminal
Using the linuxcnc-ethercat commit:
commit 7b1e4bb0bb0b5886486b98fc2511b2333402ad0d
Author: Sascha Ittner <sascha@wicky.rb.modusoft.lan>
Date: Sat Mar 10 10:03:44 2018 +0100
use linuxcnc's Makefile.modinc to build RT component
I obtain:
LINUXCNC - 2.8.0~pre1
Machine configuration directory is '/home/laminator/linuxcnc/configs/LAMGUI'
Machine configuration file is 'lam.ini'
Starting LinuxCNC...
Found file(REL): ./lam-v1.hal
Note: Using POSIX realtime
lcec: dlopen: /usr/lib/linuxcnc/modules/lcec.so: undefined symbol: ecrt_slave_config_sdo
./lam-v1.hal:2: waitpid failed /usr/bin/rtapi_app lcec
./lam-v1.hal:2: /usr/bin/rtapi_app exited without becoming ready
./lam-v1.hal:2: insmod for lcec failed, returned -1
Shutting down and cleaning up LinuxCNC...
Note: Using POSIX realtime
LinuxCNC terminated with an error. You can find more information in the log:
/home/laminator/linuxcnc_debug.txt
and
/home/laminator/linuxcnc_print.txt
as well as in the output of the shell command 'dmesg' and in the terminal
I believe this is related to the last post on github.com/sittner/linuxcnc-ethercat/issues/57 > and github.com/sittner/linuxcnc-ethercat/issues/61
Any idea how to avoid this error?
Thanks a lot for the help,
Nicolas
it does actually help.
The /dev/Ethercat0 was already there but with some restrained permission so after a sudo chmod a+rwx Ethercat0, the linuxcnc 2.7 and linuxcnc 2.8 were able to carry on.The only issue is I have to do that everytime I log in as the permission seems not to be saved for some reason. Any idea about how I could make the permission permanent?
Edit: to make the /dev/EtherCAT0 usage permanent just do sudo adduser $USER ethercat, and/or sudo adduser root ethercat then you have to reboot (see post askubuntu.com/questions/373096/how-do-i-...ssions-for-dev-ttys0 for a similar case.)
However it did show another error for linuxcnc 2.8, which I believe is link to an error seen on the make of the linuxcnc-ethercat.
Using the linuxcnc-ethercat last commit:
commit b02252a79d11f1c9dd5884bac1a53743b3818d39
Merge: 22bcaa9 333dec5
Author: Sascha Ittner <sascha.ittner@modusoft.de>
Date: Fri Aug 17 16:37:32 2018 +0200
Merge pull request #60 from sittner/add-fsoe-support
Add fsoe support
I obtain
LINUXCNC - 2.8.0~pre1
Machine configuration directory is '/home/laminator/linuxcnc/configs/LAMGUI'
Machine configuration file is 'lam.ini'
Starting LinuxCNC...
Found file(REL): ./lam-v1.hal
Note: Using POSIX realtime
lcec: dlopen: /usr/lib/linuxcnc/modules/lcec.so: undefined symbol: rtapi_mutex_get
./lam-v1.hal:2: waitpid failed /usr/bin/rtapi_app lcec
./lam-v1.hal:2: /usr/bin/rtapi_app exited without becoming ready
./lam-v1.hal:2: insmod for lcec failed, returned -1
Shutting down and cleaning up LinuxCNC...
Note: Using POSIX realtime
LinuxCNC terminated with an error. You can find more information in the log:
/home/laminator/linuxcnc_debug.txt
and
/home/laminator/linuxcnc_print.txt
as well as in the output of the shell command 'dmesg' and in the terminal
Using the linuxcnc-ethercat commit:
commit 7b1e4bb0bb0b5886486b98fc2511b2333402ad0d
Author: Sascha Ittner <sascha@wicky.rb.modusoft.lan>
Date: Sat Mar 10 10:03:44 2018 +0100
use linuxcnc's Makefile.modinc to build RT component
I obtain:
LINUXCNC - 2.8.0~pre1
Machine configuration directory is '/home/laminator/linuxcnc/configs/LAMGUI'
Machine configuration file is 'lam.ini'
Starting LinuxCNC...
Found file(REL): ./lam-v1.hal
Note: Using POSIX realtime
lcec: dlopen: /usr/lib/linuxcnc/modules/lcec.so: undefined symbol: ecrt_slave_config_sdo
./lam-v1.hal:2: waitpid failed /usr/bin/rtapi_app lcec
./lam-v1.hal:2: /usr/bin/rtapi_app exited without becoming ready
./lam-v1.hal:2: insmod for lcec failed, returned -1
Shutting down and cleaning up LinuxCNC...
Note: Using POSIX realtime
LinuxCNC terminated with an error. You can find more information in the log:
/home/laminator/linuxcnc_debug.txt
and
/home/laminator/linuxcnc_print.txt
as well as in the output of the shell command 'dmesg' and in the terminal
I believe this is related to the last post on github.com/sittner/linuxcnc-ethercat/issues/57 > and github.com/sittner/linuxcnc-ethercat/issues/61
Any idea how to avoid this error?
Thanks a lot for the help,
Nicolas
Last edit: 7 years 11 months ago by Nico2017. Reason: More precise answer
Please Log in or Create an account to join the conversation.
- Grotius
- Offline
- Platinum Member
-
Less
More
- Posts: 2419
- Thank you received: 2349
8 years 3 days ago - 8 years 3 days ago #119566
by Grotius
Replied by Grotius on topic Ethercat HAL driver
Okey guy's,
I have some news. Struggling with include files in hal.
Done some test's. I needed the "/opt/etherlab/include/ecrt.h" to work with linuxcnc hal. In hal we can couple a lot of stuff.
Nothing happened and linuxcnc refused to load dlopen .....
So i start from zero with a sucesfull test to that directory, to print some info.
Next thing will be integrating a bigger file.
in postgui.hal
ethercat component, ethercat.comp :
(compiled in terminal by : sudo halcompile --install ethercat.comp)
The external_file.h is located in directory : /opt/etherlab/include/external_file.h
The file below is : external_file.h (it is a short file, only containing a function with a print message, for fun, function is in fact : () )
Inside the function we say only print some info :
Output in linuxcnc terminal :
So i think this is a first start to use Ethercat to Linuxcnc hal for me.
I have some news. Struggling with include files in hal.
Done some test's. I needed the "/opt/etherlab/include/ecrt.h" to work with linuxcnc hal. In hal we can couple a lot of stuff.
Nothing happened and linuxcnc refused to load dlopen .....
So i start from zero with a sucesfull test to that directory, to print some info.
Next thing will be integrating a bigger file.
in postgui.hal
Code:
loadrt ethercat
addf ethercat servo-thread
ethercat component, ethercat.comp :
(compiled in terminal by : sudo halcompile --install ethercat.comp)
Code:
component ethercat"ethercat";
description
"""
Test Component
""";
author "Grotius CNC Machines, started Oktober 2018";
license "GPL";
option singleton yes;
//Input hal connection :
pin in bit Testpin_in "Enable this component";
//Output hal connection :
pin out bit Testpin_out "Connect to user gui led";
function _;
;;
#include <stdio.h>
#include "/opt/etherlab/include/external_file.h"
typedef enum { INIT, SELECT} state_T;
state_T state = INIT;
FUNCTION(_) {
switch(state){
case INIT:
state = SELECT;
break;
case SELECT:
// do something with the include file
function_print();
break;
}
}
The external_file.h is located in directory : /opt/etherlab/include/external_file.h
The file below is : external_file.h (it is a short file, only containing a function with a print message, for fun, function is in fact : () )
Inside the function we say only print some info :
Code:
#include<stdio.h>
int function_print()
{
printf("external file print");
return 0;
}
Output in linuxcnc terminal :
So i think this is a first start to use Ethercat to Linuxcnc hal for me.
Last edit: 8 years 3 days ago by Grotius.
Please Log in or Create an account to join the conversation.
- gbcwbz
- Offline
- New Member
-
Less
More
- Posts: 7
- Thank you received: 1
7 years 11 months ago #120133
by gbcwbz
Replied by gbcwbz on topic Ethercat HAL driver
Hi Nicolas,
Please refer to IgH Master 1.5.2 Documentation Chapter 9.5
Then you can use that device as non-root user.
Regards
Bryan
Please refer to IgH Master 1.5.2 Documentation Chapter 9.5
The device nodes will be created with mode 0660 and group root by default. If “nor-
mal” users shall have reading access, a udev rule file (for example /etc/udev/rules.d/99-
EtherCAT.rules) has to be created with the following contents:Code:KERNEL ==" EtherCAT [0 -9]*" , MODE ="0664"
Then you can use that device as non-root user.
Regards
Bryan
The following user(s) said Thank You: Nico2017
Please Log in or Create an account to join the conversation.
Time to create page: 0.531 seconds