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
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:
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.