From d1586a6ad317fa7c702fd9475370b607eef35aaf Mon Sep 17 00:00:00 2001 From: r2k-in-the-vortex <30666740+r2k-in-the-vortex@users.noreply.github.com> Date: Thu, 7 Dec 2023 19:55:42 +0200 Subject: [PATCH] Wideregistersupport (#6) * fixes for multiple pdos of same data direction and for undeclared IO variables in PLC program * wide register support, 32, 64bit --------- Authored-by: r2k --- src/ecat_handler/ecat_handler.c | 30 +++++++++++++++++++++++++----- src/ecat_handler/ecat_handler.h | 8 +++++++- src/ethercat_src.c | 18 +++++++++++------- src/ethercat_src.h | 8 +++++++- src/main.c | 16 +++++++++++++++- 5 files changed, 65 insertions(+), 15 deletions(-) diff --git a/src/ecat_handler/ecat_handler.c b/src/ecat_handler/ecat_handler.c index bf84be3..47fd4af 100644 --- a/src/ecat_handler/ecat_handler.c +++ b/src/ecat_handler/ecat_handler.c @@ -259,13 +259,9 @@ int NameTypeAndPrefix(PdoRegistryEntry *pdo, char *name, char *prefix, char *dty } else if (pdo->bitlength == 32){ strcpy(dtype, "DINT"); strcpy(prefix, "D"); - log_error("Bitlen %i not implemented and not supported", pdo->bitlength); - return -1; } else if (pdo->bitlength == 64){ strcpy(dtype, "LINT"); strcpy(prefix, "L"); - log_error("Bitlen %i not implemented and not supported", pdo->bitlength); - return -1; } else{ log_error("Bitlen %i not implemented and not supported", pdo->bitlength); return -1; @@ -511,7 +507,11 @@ int EtherCATcyclic(int buffersize, int8var_call_back byte_input, int8var_call_back byte_output, int16var_call_back word_input, - int16var_call_back word_output){ + int16var_call_back word_output, + int32var_call_back dword_input, + int32var_call_back dword_output, + int64var_call_back lword_input, + int64var_call_back lword_output){ if(!config_done)return 0; if(!msgonce){ @@ -579,6 +579,16 @@ int EtherCATcyclic(int buffersize, if(!config->config_only_flag && ptr){ *ptr = EC_READ_U16(domain1_pd + pdo.offset); } + } else if(pdo.bitlength == 32){ + uint32_t *ptr = dword_input(i); + if(!config->config_only_flag && ptr){ + *ptr = EC_READ_U32(domain1_pd + pdo.offset); + } + } else if(pdo.bitlength == 64){ + uint64_t *ptr = lword_input(i); + if(!config->config_only_flag && ptr){ + *ptr = EC_READ_U64(domain1_pd + pdo.offset); + } } } @@ -604,6 +614,16 @@ int EtherCATcyclic(int buffersize, if(!config->config_only_flag && ptrout){ EC_WRITE_U16(domain1_pd + pdo.offset, *ptrout); } + } else if(pdo.bitlength == 32){ + uint32_t *ptrout = dword_output(i); + if(!config->config_only_flag && ptrout){ + EC_WRITE_U32(domain1_pd + pdo.offset, *ptrout); + } + } else if(pdo.bitlength == 64){ + uint64_t *ptrout = lword_output(i); + if(!config->config_only_flag && ptrout){ + EC_WRITE_U64(domain1_pd + pdo.offset, *ptrout); + } } } } diff --git a/src/ecat_handler/ecat_handler.h b/src/ecat_handler/ecat_handler.h index ee7edfb..19aa13c 100644 --- a/src/ecat_handler/ecat_handler.h +++ b/src/ecat_handler/ecat_handler.h @@ -104,6 +104,8 @@ extern "C"{ typedef u_int8_t *(*boolvar_call_back) (int, int); typedef u_int8_t *(*int8var_call_back) (int); typedef u_int16_t *(*int16var_call_back) (int); +typedef u_int32_t *(*int32var_call_back) (int); +typedef u_int64_t *(*int64var_call_back) (int); typedef int logger_callback(char*); @@ -117,7 +119,11 @@ int EtherCATcyclic(int buffersize, int8var_call_back byte_input, int8var_call_back byte_output, int16var_call_back word_input, - int16var_call_back word_output); + int16var_call_back word_output, + int32var_call_back dword_input, + int32var_call_back dword_output, + int64var_call_back lword_input, + int64var_call_back lword_output); void terminate_handler(); diff --git a/src/ethercat_src.c b/src/ethercat_src.c index dce7220..40caf97 100644 --- a/src/ethercat_src.c +++ b/src/ethercat_src.c @@ -145,13 +145,17 @@ int ethercat_configure(char *paramsfile, type_logger_callback logfptr){ } int ethercat_callcyclic(int buffersize, - boolvar_call_back bool_input, - boolvar_call_back bool_output, - int8var_call_back byte_input, - int8var_call_back byte_output, - int16var_call_back word_input, - int16var_call_back word_output){ - return EtherCATcyclic(buffersize, bool_input, bool_output, byte_input, byte_output, word_input, word_output); + boolvar_call_back bool_input, + boolvar_call_back bool_output, + int8var_call_back byte_input, + int8var_call_back byte_output, + int16var_call_back word_input, + int16var_call_back word_output, + int32var_call_back dword_input, + int32var_call_back dword_output, + int64var_call_back lword_input, + int64var_call_back lword_output){ + return EtherCATcyclic(buffersize, bool_input, bool_output, byte_input, byte_output, word_input, word_output, dword_input, dword_output, lword_input, lword_output); } int ethercat_read_sdo(){ diff --git a/src/ethercat_src.h b/src/ethercat_src.h index 4537ed5..7c85c1a 100644 --- a/src/ethercat_src.h +++ b/src/ethercat_src.h @@ -7,6 +7,8 @@ extern "C"{ typedef u_int8_t *(*boolvar_call_back) (int, int); typedef u_int8_t *(*int8var_call_back) (int); typedef u_int16_t *(*int16var_call_back) (int); +typedef u_int32_t *(*int32var_call_back) (int); +typedef u_int64_t *(*int64var_call_back) (int); typedef void (*type_logger_callback) (unsigned char*); // Setup before realtime @@ -19,7 +21,11 @@ int ethercat_callcyclic(int buffersize, int8var_call_back byte_input, int8var_call_back byte_output, int16var_call_back word_input, - int16var_call_back word_output); + int16var_call_back word_output, + int32var_call_back dword_input, + int32var_call_back dword_output, + int64var_call_back lword_input, + int64var_call_back lword_output); // CoE access int ethercat_read_sdo(); diff --git a/src/main.c b/src/main.c index fb24452..82cd685 100644 --- a/src/main.c +++ b/src/main.c @@ -29,12 +29,18 @@ uint8_t shortvar = 0; uint16_t longvar = 0; +uint32_t dwordvar = 0; +uint64_t lwordvar = 0; uint8_t *bool_input_call_back(int a, int b){ return &shortvar; } uint8_t *bool_output_call_back(int a, int b){ return &shortvar; } uint8_t *byte_input_call_back(int a){ return &shortvar; } uint8_t *byte_output_call_back(int a){ return &shortvar; } uint16_t *int_input_call_back(int a){ return &longvar; } uint16_t *int_output_call_back(int a){ return &longvar; } +uint32_t *dint_input_call_back(int a){ return &dwordvar; } +uint32_t *dint_output_call_back(int a){ return &dwordvar; } +uint64_t *lint_input_call_back(int a){ return &lwordvar; } +uint64_t *lint_output_call_back(int a){ return &lwordvar; } void logger_callbackf(unsigned char *msg){ printf("PLC log: %s", msg); } //----------------------------------------------------------------------------- @@ -58,6 +64,10 @@ int main (int argc, char **argv){ int8var_call_back byte_output_callback = byte_output_call_back; int16var_call_back int_input_callback = int_input_call_back; int16var_call_back int_output_callback = int_output_call_back; + int32var_call_back dint_input_callback = dint_input_call_back; + int32var_call_back dint_output_callback = dint_output_call_back; + int64var_call_back lint_input_callback = lint_input_call_back; + int64var_call_back lint_output_callback = lint_output_call_back; for (int i = 0; i < 100; i++){ ethercat_callcyclic(BUFFER_SIZE, @@ -66,7 +76,11 @@ int main (int argc, char **argv){ byte_input_callback, byte_output_callback, int_input_callback, - int_output_callback); + int_output_callback, + dint_input_callback, + dint_output_callback, + lint_input_callback, + lint_output_callback); sleepms(100); }