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  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  <20232024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  <20232024 
<== Date ==> <== Thread ==>

Subject: RE: Using asyn as a TCP socket client in AD ioc
From: Mark Rivers via Tech-talk <tech-talk at aps.anl.gov>
To: "Marco A. Barra Montevechi Filho" <marco.filho at lnls.br>, "tech-talk at aps.anl.gov" <tech-talk at aps.anl.gov>
Date: Thu, 23 Feb 2023 00:33:56 +0000

Hi Marco,

 

1 - Can i instantiate my asynPort inside the cpp code to avoid using drvAsynIPPortConfigure?

 

Yes, you can simply call drvAsynIPPortConfigure() from your cpp code.  drvAsynIPPortConfigure is both a C callable function and an iocsh command.  The C callable function drvAsynIPPortConfigure is defined in drvAsynIPPort.h.  Here is an example of calling drvAsynIPPortConfigure() from within C++ code:

https://github.com/epics-modules/quadEM/blob/226441817aa2a8345c344db4ede24c564e776cf5/quadEMApp/src/drvNSLS_EM.cpp#L213

 

However, in general I prefer to create the port in the st.cmd file.  That way you can easily enable asynTrace in your st.cmd file to see the communication to the device.


2 - How can i write/read to the connected port?

 

You first need to call pasynOctetSyncIO->connect() to connect an asynUser structure to the port you created above.  You do this using the name of the port you passed to drvAsynIPPortConfigure.  It does not matter if you created that port in the st.cmd file or in your C++ code.  Here is an example from the same driver above:

https://github.com/epics-modules/quadEM/blob/226441817aa2a8345c344db4ede24c564e776cf5/quadEMApp/src/drvNSLS_EM.cpp#L222

 

You tried to do this, but you passed &pasynUserSelf.  That won’t work,  pasynUserSelf is the asynUser for your asynPortDriver object.  You need to allocate a new asynUser structure and pass that.  In this example that pasynUser is a private class variable:

https://github.com/epics-modules/quadEM/blob/226441817aa2a8345c344db4ede24c564e776cf5/quadEMApp/src/drvNSLS_EM.h#L53

 

You then call pasynOctetSyncIO->write()

https://github.com/epics-modules/quadEM/blob/226441817aa2a8345c344db4ede24c564e776cf5/quadEMApp/src/drvNSLS_EM.cpp#L273

 

or  pasynOctetSyncIO->writeRead()

https://github.com/epics-modules/quadEM/blob/226441817aa2a8345c344db4ede24c564e776cf5/quadEMApp/src/drvNSLS_EM.cpp#L276

 

3 - Is there a minimal working example which i can follow?

 

The example above is this:

https://github.com/epics-modules/quadEM/blob/master/quadEMApp/src/drvNSLS_EM.cpp

 

There are several areaDetector drivers that do exactly what you are doing, make a simple socket connection to a vendor server.

 

ADPilatus talks to the Dectris camserver.  It calls drvAsynIPPortConfigure in the st.cmd

https://github.com/areaDetector/ADPilatus/blob/master/pilatusApp/src/pilatusDetector.cpp

 

ADmarCCD talks to the Rayonix server.  It calls drvAsynIPPortConfigure in the st.cmd

https://github.com/areaDetector/ADmarCCD/blob/master/marCCDApp/src/marCCD.cpp

 

Search for “pasynOctetSyncIO” in both of those drivers.

 

Mark

 

 

 

From: Tech-talk <tech-talk-bounces at aps.anl.gov> On Behalf Of Marco A. Barra Montevechi Filho via Tech-talk
Sent: Wednesday, February 22, 2023 5:51 PM
To: tech-talk at aps.anl.gov
Subject: Using asyn as a TCP socket client in AD ioc

 

Hello all,

 

Context:

I have an AreaDetector ioc which i want to communicate with a simple TCP socket. Since its heavily based on ADSim, i figured i would want to test the basic functionalities in ADSimDetector before trying the implementation in the actual ioc. I have my ADSimdetector from areaDetector-R3-11.

Since ADDriver inherits from asynNDArrayDriver which inherits from asynPortDriver, i figured i could use asynPortDriver's inherited methods to instantiate the socket client and asyn interface instead of creating everything again from scratch in c++.
So im inside areaDetector-R3-11/ADSimDetector/simDetectorApp/src/simDetector.cpp:1021 - that is, inside the simDetector class constructor - trying in all sorts of ways to create an asyn client to a socket... and failing.

What i managed to do so far: create an asynPort with drvAsynIPPortConfigure("PORT", "127.0.1.1:<test_port>") in the st.cmd file and, inside the cpp file:

#include <asynOctetSyncIO>
//(...) next line is inside the constructor
pasynOctetSyncIO->connect("PORT", 0, &pasynUserSelf, NULL);

 

but:

1 - im not even sure this is was i want to do: i think i would prefer to create the port and TCP connection already inside the cpp code instead of depending on cmd file;

2 - i dont know how to use the write method. I tried pasynOctetSyncIO->write(NULL, pasynUserSelf, "TEST\n", strlen("TEST\n"), sizeof("TEST\n")); and similar lines but i get:

../simDetector.cpp:1025:35: error: cannot convert ‘asynUser*’ to ‘const char*’ in argument passing
 1025 |     pasynOctetSyncIO->write(NULL, pasynUserSelf, "TEST\n", strlen("TEST\n"), sizeof("TEST\n"));


In the doxygen pages (https://epics-modules.github.io/master/asyn/R4-30/asynDoxygenHTML/classasyn_octet_client.html), i could only find asynOctetClient->write instead of asynOctetSyncIO->write and they do seem different. In this documentation (https://epics-modules.github.io/master/asyn/R4-43/asynDriver.html#asynOctet) it isnt clear to me what is the expected *drvPvt...

Questions (finally):

1 - Can i instantiate my asynPort inside the cpp code to avoid using drvAsynIPPortConfigure?
2 - How can i write/read to the connected port?
3 - Is there a minimal working example which i can follow?


Im sorry if the doubts are trivial but i really have been lost in the documentation for some time now. Thanks in advance,

Marco

 

Aviso Legal: Esta mensagem e seus anexos podem conter informações confidenciais e/ou de uso restrito. Observe atentamente seu conteúdo e considere eventual consulta ao remetente antes de copiá-la, divulgá-la ou distribuí-la. Se você recebeu esta mensagem por engano, por favor avise o remetente e apague-a imediatamente.

Disclaimer: This email and its attachments may contain confidential and/or privileged information. Observe its content carefully and consider possible querying to the sender before copying, disclosing or distributing it. If you have received this email by mistake, please notify the sender and delete it immediately.


Replies:
Re: Using asyn as a TCP socket client in AD ioc Marco A. Barra Montevechi Filho via Tech-talk
References:
Using asyn as a TCP socket client in AD ioc Marco A. Barra Montevechi Filho via Tech-talk

Navigate by Date:
Prev: Using asyn as a TCP socket client in AD ioc Marco A. Barra Montevechi Filho via Tech-talk
Next: Alarm Logger Display William F Badgett Jr via Tech-talk
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  <20232024 
Navigate by Thread:
Prev: Using asyn as a TCP socket client in AD ioc Marco A. Barra Montevechi Filho via Tech-talk
Next: Re: Using asyn as a TCP socket client in AD ioc Marco A. Barra Montevechi Filho via Tech-talk
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  <20232024 
ANJ, 23 Feb 2023 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·