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  2008  2009  2010  2011  <20122013  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  2008  2009  2010  2011  <20122013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: RE: access record info from asyn
From: Mark Rivers <[email protected]>
To: "'Hinko Kocevar'" <[email protected]>
Cc: Tech Talk <[email protected]>
Date: Thu, 13 Sep 2012 14:08:16 +0000
Hi Hinko,

OK, now I understand.

Is each parameter in your application server associated with a single EPICS record? If so, then I think the following solution should work:


record(ai, "MyParam")
  field(DTYP, "asynFloat64")
  field(INP, "@asyn($(PORT),0,1)MY_PARAM")
}

record(longout, "MyParamScan")
  field(DOL, "MyParam.SCAN CP MS")
  field(DTYP, "asynInt32")
  field(OUT, "@asyn($(PORT),0,1)MY_PARAM_SCAN)
}

In your driver implement writeInt32()

#include <dbScan.h>

myDriver::writeInt32(asynUser, *pasynUser, epicsInt32 value)
{
  function = pasynUser->reason;

  if (value == SCAN_IO_EVENT) {
    registerCallbackApplicationServer(function);
  } else {
    cancelCallbackApplicationServer(function);
  }
}

Mark


-----Original Message-----
From: Hinko Kocevar [mailto:[email protected]] 
Sent: Thursday, September 13, 2012 8:11 AM
To: Mark Rivers
Cc: Tech Talk
Subject: Re: access record info from asyn

Dear Mark,


On 09/13/2012 02:50 PM, Mark Rivers wrote:
> Hi Hinko,
>
> I should also point out that if you use the asynPortDriver C++ base class to write your driver, it is very easy to implement what I described previously.

Yes, we are using C++ asynPortDriver, I should of mentioned it earlier.

>
> You will have a callback function in your driver to receive callbacks from the application server when something changes. Here is what that code would look like.
>
> void myDriver::serverCallback(int setting, int value)
> {
>    // Assume "setting" is the parameter number in the asynPort driver parameter library.
>    // If not then look up parameter number from "setting"
>
>    // Take the driver lock
>    lock();
>    // Set the value in the asynPortDriver parameter library
>    setIntegerParam(setting, value);
>
>    // Do callbacks to any registered clients, i.e. device support for records with SCAN=I/O Intr
>    doParamCallbacks();
>
>    // Release the driver lock
>    unlock();
> }

Yes, this is how we do it. In IOC code we have a callback function that 
is called by the application (server) every time that the value of 
served parameter changes - this change is emitted as a "notification" 
over the network. Callback gets new value in an argument, looks up asyn 
parameter in local storage, sets the asyn parameter value and calls 
doParamCallback() in the end..

What we can not control since we do not know the state of the PVs SCAN 
field (in the code) is when to enable/disable the arrival of 
notifications in the server that would hit EPICS IOC callback.

>
> That's all there is to it.  Now if records change from SCAN=I/O Intr to SCAN=1 second your driver does not need to do anything.  Because the latest value is always in the parameter library, your driver can use the base class implementation of asynInt32->read(), which just returns the latest value from the parameter library.  You don't need to implement asynInt32->read().

We are seeing that indeed PV is as expected scanned on 1 second for this 
case, but that did not stop notifications from arriving anyway, since we 
did not unregister them on the server - our code - so the CPU, memory 
and network load remains.

Thank you!

Hinko


>
> Mark
>
> ________________________________________
> From: Mark Rivers
> Sent: Thursday, September 13, 2012 7:36 AM
> To: Hinko Kocevar; Tech Talk
> Subject: RE: access record info from asyn
>
> Hi Hinko,
>
> I'm not quite sure I understand what you are asking.
>
> Here is what I recommend:
>
> - Use the standard asyn device support that comes with asyn. It automatically registers for callbacks with your driver when the record is set to SCAN=I/O Intr, and unregisters when SCAN is set to something else. That is registering/unregistering the record from your driver, not your driver from the application server.
>
> - Your driver uses the normal asynManager functions for doing callbacks, which traverses a linked list of registered callback clients. If there are no records with SCAN=I/O Intr then your driver will find an empty list.
>
> - One approach is to have your application server ALWAYS do callbacks to your driver, so your driver always has the latest value. If records are put into SCAN=1 second for example, then they will call the asynInt32->read() function in your driver (for example), where they will always get the latest value.
>
> - An alternative approach is to have the asynInt32->read() function in your driver poll the application server, rather than always getting callbacks.
>
> Which approach to use depends on the frequency with which values are changing in your application server. If they are changing very fast and there are no records with SCAN=I/O Intr then polling is more efficient. If they are changing slowly then callbacks is more efficient.
>
> There is no mechanism for your driver to be asynchronously notified when the number of registered callback clients on an interface changes. However, you can use pasynManager->interrupt start to query the number of clients from the size of the linked list.
>
> Mark
>
> _______________________________________
> From: [email protected] [[email protected]] on behalf of Hinko Kocevar [[email protected]]
> Sent: Thursday, September 13, 2012 1:44 AM
> To: Tech Talk
> Subject: access record info from asyn
>
> Hi,
>
> I'm writing Asyn driver that will interface our application daemon
> running on Linux OS.
>
> Application daemon is capable of emitting notifications that can tell
> the client (asyn) that there is a change in value. Asyn driver would
> register a callback to receive this notifications - everything is nice
> and running till now, assuming that record SCAN field is set to I/O Intr
> (camonitor refreshes value as expected).
>
> How can I detect if user wants to change the SCAN field value to
> Passive? This would in turn mean that we need to unregister from the
> notifications that our application is sending and expect the user to do
> caget like access.
>
>
> Thank you!
> Hinko
>
> --
> Hinko Kocevar
> Software development engineer
> Instrumentation Technologies d.d.
> Velika pot 22, SI-5250 Solkan - Slovenia
> T:+386 5 3352600, F:+386 5 3352601
> E-mail: [email protected]
> http://www.i-tech.si
>
> The information transmitted is intended solely for the
> addressee and may contain confidential and/or privileged
> information. Any review, retention, disclosure or other use
> by persons other than the intended recipient is prohibited.
> If you received this in error, please notify the sender and
> delete all copies.
>


-- 
Hinko Kocevar
Software development engineer
Instrumentation Technologies d.d.
Velika pot 22, SI-5250 Solkan - Slovenia
T:+386 5 3352600, F:+386 5 3352601
E-mail: [email protected]
http://www.i-tech.si

The information transmitted is intended solely for the
addressee and may contain confidential and/or privileged
information. Any review, retention, disclosure or other use
by persons other than the intended recipient is prohibited.
If you received this in error, please notify the sender and
delete all copies.


Replies:
Re: access record info from asyn Hinko Kocevar
Re: access record info from asyn Hinko Kocevar
References:
access record info from asyn Hinko Kocevar
RE: access record info from asyn Mark Rivers
RE: access record info from asyn Mark Rivers
Re: access record info from asyn Hinko Kocevar

Navigate by Date:
Prev: Re: waveform changes using subArray Hinko Kocevar
Next: Re: waveform changes using subArray Ned Arnold
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: Re: access record info from asyn Hinko Kocevar
Next: Re: access record info from asyn Hinko Kocevar
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 18 Nov 2013 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·