--- a/etherlab/etherlab.py Tue Mar 26 09:34:30 2013 +0900
+++ b/etherlab/etherlab.py Tue Mar 26 12:42:49 2013 +0900
@@ -1188,12 +1188,12 @@
SLAVE_CONFIGURATION_TEMPLATE = """
if (!(slave%(slave)d = ecrt_master_slave_config(master, %(alias)d, %(position)d, 0x%(vendor).8x, 0x%(product_code).8x))) {
- fprintf(stderr, "Failed to get slave %(device_type)s configuration at alias %(alias)d and position %(position)d.\\n");
+ SLOGF(LOG_CRITICAL, "Failed to get slave %(device_type)s configuration at alias %(alias)d and position %(position)d.\\n");
return -1;
}
if (ecrt_slave_config_pdos(slave%(slave)d, EC_END, slave_%(slave)d_syncs)) {
- fprintf(stderr, "Failed to configure PDOs for slave %(device_type)s at alias %(alias)d and position %(position)d.\\n");
+ SLOGF(LOG_CRITICAL, "Failed to configure PDOs for slave %(device_type)s at alias %(alias)d and position %(position)d.\\n");
return -1;
}
"""
@@ -1203,7 +1203,7 @@
uint8_t value[%(data_size)d];
EC_WRITE_%(data_type)s((uint8_t *)value, %(data)s);
if (ecrt_master_sdo_download(master, %(slave)d, 0x%(index).4x, 0x%(subindex).2x, (uint8_t *)value, %(data_size)d, &abort_code)) {
- fprintf(stderr, "Failed to initialize slave %(device_type)s at alias %(alias)d and position %(position)d.\\nError: %%d\\n", abort_code);
+ SLOGF(LOG_CRITICAL, "Failed to initialize slave %(device_type)s at alias %(alias)d and position %(position)d.\\nError: %%d\\n", abort_code);
return -1;
}
}
@@ -1213,7 +1213,7 @@
{
uint8_t value[%(data_size)d];
if (ecrt_master_sdo_upload(master, %(slave)d, 0x%(index).4x, 0x%(subindex).2x, (uint8_t *)value, %(data_size)d, &result_size, &abort_code)) {
- fprintf(stderr, "Failed to get default value for output PDO in slave %(device_type)s at alias %(alias)d and position %(position)d.\\nError: %%d\\n", abort_code);
+ SLOGF(LOG_CRITICAL, "Failed to get default value for output PDO in slave %(device_type)s at alias %(alias)d and position %(position)d.\\nError: %%d\\n", abort_code);
return -1;
}
%(real_var)s = EC_READ_%(data_type)s((uint8_t *)value);
--- a/etherlab/plc_etherlab.c Tue Mar 26 09:34:30 2013 +0900
+++ b/etherlab/plc_etherlab.c Tue Mar 26 12:42:49 2013 +0900
@@ -38,6 +38,12 @@
static ec_domain_t *domain1 = NULL;
static int first_sent=0;
%(slaves_declaration)s
+#define SLOGF(level, format, args...)\
+{\
+ char sbuf[256];\
+ int slen = snprintf(sbuf , sizeof(sbuf) , format , ##args);\
+ LogMessage(level, sbuf, slen);\
+}
/* Beremiz plugin functions */
int __init_%(location)s(int argc,char **argv)
@@ -58,7 +64,7 @@
%(slaves_configuration)s
if (ecrt_domain_reg_pdo_entry_list(domain1, domain1_regs)) {
- fprintf(stderr, "PDO entry registration failed!\n");
+ SLOGF(LOG_CRITICAL, "PDO entry registration failed!\n");
return -1;
}
@@ -73,7 +79,7 @@
sprintf(&rt_dev_file[0],"%%s%%u",EC_RTDM_DEV_FILE_NAME,0);
rt_fd = rt_dev_open( &rt_dev_file[0], 0);
if (rt_fd < 0) {
- fprintf(stderr, "Can't open %%s\n", &rt_dev_file[0]);
+ SLOGF(LOG_CRITICAL, "Can't open %%s\n", &rt_dev_file[0]);
return -1;
}
@@ -81,7 +87,7 @@
MstrAttach.domainindex = ecrt_domain_index(domain1);
rtstatus = ecrt_rtdm_master_attach(rt_fd, &MstrAttach);
if (rtstatus < 0) {
- fprintf(stderr, "Cannot attach to master over rtdm\n");
+ SLOGF(LOG_CRITICAL, "Cannot attach to master over rtdm\n");
return -1;
}
@@ -89,11 +95,11 @@
return -1;
if (!(domain1_pd = ecrt_domain_data(domain1))) {
- fprintf(stderr, "domain1_pd: 0x%%.6lx\n", (unsigned long)domain1_pd);
+ SLOGF(LOG_CRITICAL, "domain1_pd: 0x%%.6lx\n", (unsigned long)domain1_pd);
return -1;
}
- fprintf(stdout, "Master %(master_number)d activated...\n");
+ SLOGF(LOG_INFO, "Master %(master_number)d activated...\n");
first_sent = 0;