Skip to content

Commit

Permalink
Add EIP_timeout config option
Browse files Browse the repository at this point in the history
  • Loading branch information
Kay committed Feb 4, 2022
1 parent dc25369 commit bd31bec
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
3 changes: 3 additions & 0 deletions changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ in ether_ipApp/src/drvEtherIP.h are updated accordingly,
so that you can see the current version at runtime via
drvEtherIP_report.

* 2022, Feb 4 ether_ip-3-5
Make EIP_timeout(ms) configurable.

* 2021, Sep 3 ether_ip-3-4
Log port number as decimal, since that's more familiar than hex.

Expand Down
9 changes: 7 additions & 2 deletions ether_ipApp/src/drvEtherIP.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
/* See drvEtherIP_initHook() */
static int databaseIsReady = false;

int EIP_TIMEOUT = 5000;

double drvEtherIP_default_rate = 0.0;

DrvEtherIP_Private drvEtherIP_private = { {NULL, NULL}, 0 };
Expand Down Expand Up @@ -498,7 +500,7 @@ static eip_bool assert_PLC_connect(PLC *plc)
return true;
EIP_printf_time(4, "EIP connecting %s\n", plc->name);
if (! EIP_startup(plc->connection, plc->ip_addr,
ETHERIP_PORT, plc->slot, ETHERIP_TIMEOUT))
ETHERIP_PORT, plc->slot, EIP_TIMEOUT))
{
errlogPrintf("EIP connection failed for %s:%d\n",
plc->ip_addr, ETHERIP_PORT);
Expand Down Expand Up @@ -838,7 +840,7 @@ static void PLC_scan_task(PLC *plc)
eip_bool transfer_ok, reset_next_schedule;

quantum = epicsThreadSleepQuantum();
timeout = (double)ETHERIP_TIMEOUT/1000.0;
timeout = (double)EIP_TIMEOUT/1000.0;
scan_loop: /* --------- The Scan Loop for one PLC -------- */
if (epicsMutexLock(plc->lock) != epicsMutexLockOK)
{
Expand Down Expand Up @@ -1031,6 +1033,9 @@ void drvEtherIP_help()
printf(" 2: show more error info\n");
printf(" 1: show severe error messages\n");
printf(" 0: keep quiet\n");
printf(" EIP_timeout(<milliseconds>)\n");
printf(" - define the default timeout for connecting to PLC and reading responses\n");
printf(" (default: %d ms)\n", EIP_TIMEOUT);
printf(" drvEtherIP_default_rate(<seconds>)\n");
printf(" - define the default scan rate\n");
printf(" (if neither SCAN nor INP/OUT provide one)\n");
Expand Down
4 changes: 2 additions & 2 deletions ether_ipApp/src/drvEtherIP.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "dl_list.h"

#define ETHERIP_MAYOR 3
#define ETHERIP_MINOR 4
#define ETHERIP_MINOR 5

/* For timing */
#define EIP_MIN_TIMEOUT 0.1 /* second */
Expand All @@ -27,7 +27,7 @@
#define ETHERIP_PORT 0xAF12

/* TCP timeout in millisec for connection and readback */
#define ETHERIP_TIMEOUT 5000
extern int EIP_TIMEOUT;

typedef struct __TagInfo TagInfo; /* forwards */
typedef struct __ScanList ScanList;
Expand Down
8 changes: 8 additions & 0 deletions ether_ipApp/src/drvEtherIPRegister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ static void EIP_verbosityCall(const iocshArgBuf * args) {
EIP_verbosity = args[0].ival;
}

static const iocshArg EIP_timeoutArg0 = {"value", iocshArgInt};
static const iocshArg *const EIP_timeoutArgs[1] = {&EIP_timeoutArg0};
static const iocshFuncDef EIP_timeoutDef = {"EIP_timeout", 1, EIP_timeoutArgs};
static void EIP_timeoutCall(const iocshArgBuf * args) {
EIP_TIMEOUT = args[0].ival;
}

static const iocshArg EIP_buffer_limitArg0 = {"bytes", iocshArgInt};
static const iocshArg *const EIP_buffer_limitArgs[1] = {&EIP_buffer_limitArg0};
static const iocshFuncDef EIP_buffer_limitDef = {"EIP_buffer_limit", 1, EIP_buffer_limitArgs};
Expand Down Expand Up @@ -103,6 +110,7 @@ static void drvEtherIP_read_tagCall(const iocshArgBuf * args) {
void drvEtherIP_Register() {
iocshRegister(&drvEtherIP_default_rateDef, drvEtherIP_default_rateCall);
iocshRegister(&EIP_verbosityDef , EIP_verbosityCall);
iocshRegister(&EIP_timeoutDef , EIP_timeoutCall);
iocshRegister(&EIP_buffer_limitDef , EIP_buffer_limitCall);
iocshRegister(&drvEtherIP_helpDef , drvEtherIP_helpCall);
iocshRegister(&drvEtherIP_initDef , drvEtherIP_initCall);
Expand Down
1 change: 1 addition & 0 deletions iocBoot/iocether_ip/st.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ eipIoc_registerRecordDeviceDriver(pdbbase)
drvEtherIP_init()

# EIP_verbosity(10)
# EIP_timeout(5000)

drvEtherIP_define_PLC("plc1", "160.91.233.45", 0)

Expand Down

0 comments on commit bd31bec

Please sign in to comment.