EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  <20082009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  <20082009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: Re: CA connection management problem
From: Andrew Johnson <[email protected]>
To: "Owens, PH (Peter)" <[email protected]>
Cc: [email protected]
Date: Fri, 18 Jan 2008 10:02:24 -0600
Hi Pete/Vic,

You cannot just set up the channel and then loop on a
ca_get ; ca_pend_io

Yes you can, and in some cases that's exactly what you should be doing. If you started your IOC *after* your program, your posted code would have called ca_context_create() multiple times without a matching call to ca_context_destroy(), which might explain what you saw (there were probably multiple active contexts which were all reporting disconnects).


I suggest you make it impossible for simple programs ever to call ca_context_create() after it has once returned ECA_NORMAL, and don't use ca_context_destroy() in them at all.

I've attached my modified version of your code which loops calling just ca_get() and ca_pend_io(). I can stop and start the IOC it connects to using either 'exit' or Control-C and the channel reconnects properly in both cases when I restart it. The ca_pend_io(0) after calling ca_create_channel() waits forever for the channel to connect before it starts the loop, but you could do this other ways too.

calling ca_context_create
calling ca_create_channel
calling ca_pend_io(0)
ca_pend_io returned 0x1: value=0x6
ca_pend_io returned 0x1: value=0x8
ca_pend_io returned 0x1: value=0x0
CA.Client.Exception...............................................
Warning: "Virtual circuit disconnect"
Context: "tux.aps.anl.gov:5064"
Source File: ../cac.cpp line 1127
Current Time: Fri Jan 18 2008 09:15:33.826129157
..................................................................
CA.Client.Exception...............................................
Warning: "Virtual circuit disconnect"
Context: "op=0, channel=anjHost:aiExample, type=DBR_SHORT, count=1, ctx="tux.aps.anl.gov:5064""
Source File: ../getCopy.cpp line 86
Current Time: Fri Jan 18 2008 09:15:33.826488069
..................................................................
ca_pend_io failed: User specified timeout on IO operation expired
ca_get failed: Virtual circuit disconnect
ca_pend_io failed: User specified timeout on IO operation expired
ca_get failed: Virtual circuit disconnect
ca_pend_io failed: User specified timeout on IO operation expired
ca_get failed: Virtual circuit disconnect
ca_pend_io failed: User specified timeout on IO operation expired
ca_pend_io returned 0x1: value=0x2
ca_pend_io returned 0x1: value=0x4
ca_pend_io returned 0x1: value=0x6


One other suggestion: In a CA client program like this, using ca_pend_event() instead of sleep() or epicsThreadSleep() can result in exception messages being printed sooner and the program seeming quicker to respond, since the CA library won't output anything while your code is not executing a CA library call.

- Andrew
--
When a distinguished but elderly scientist states that something is
possible, he is almost certainly right.  When he states that something
is impossible, he is very probably wrong.  -- Arthur C. Clarke
#include <stdlib.h>
#include <stdio.h>

#include <epicsThread.h>
#include <cadef.h>

#define EPICS_TIMEOUT 5.0


int main(int argc, char *argv[])
{
    char *PVN = "anjHost:aiExample";

    int rc;
    chid CID;
    double timeout = EPICS_TIMEOUT;
    unsigned short value;

    printf("calling ca_context_create\n");

    rc = ca_context_create(ca_disable_preemptive_callback);
    if (rc != ECA_NORMAL) {
        printf("ca_context_create failed %s\n", ca_message(rc));
        exit(1);
    }

    printf("calling ca_create_channel\n");

    rc = ca_create_channel(PVN, NULL, NULL, 10, &CID);
    if (rc != ECA_NORMAL) {
        printf("ca_create_channel failed: %s\n", ca_message(rc));
        exit(1);
    }

    printf("calling ca_pend_io(0)\n");

    rc = ca_pend_io(0);
    if (rc != ECA_NORMAL) {
        printf("ca_pend_io failed: %s\n", ca_message(rc));
        exit(1);
    }

    for(;;) {
        rc = ca_get(DBR_SHORT, CID, &value);
        if (rc != ECA_NORMAL) {
            printf("ca_get failed: %s\n", ca_message(rc));
        }

        rc = ca_pend_io(timeout);
        if (rc != ECA_NORMAL) {
            printf("ca_pend_io failed: %s\n", ca_message(rc));
        } else {
            printf("ca_pend_io returned 0x%x: value=0x%x\n", rc, value);
        }

        epicsThreadSleep(2);
    }

    exit(0);
}

References:
RE: CA connection management problem Owens, PH (Peter)

Navigate by Date:
Prev: Re: error in communicating to the GPIB device with NI-PCI board Stefan Heim
Next: Re: error in communicating to the GPIB device with NI-PCI board Stefan Heim
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  <20082009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: RE: CA connection management problem Owens, PH (Peter)
Next: CA connection management - vxWorks David Maden
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  <20082009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 02 Sep 2010 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·