Hi!
I have kind of a simple question that has persisted for a long time about managing connections with asyn. For several reasons, I want my module to manage the connection and disconnection to the device.
For a minimalistic example, I created a python socket server with code copied from the internet that I append at the end of this e-mail. With an st.cmd file that has:
drvAsynIPPortConfigure("LOCALHOST", "127.0.0.1:65432", 0, 0, 0)
My python server prints:
Connected by ('127.0.0.1', 39696)
And returns the terminal once the client disconnects.
I then tried starting my asyn port with no autoconnect option:
drvAsynIPPortConfigure("LOCALHOST", "127.0.0.1:65432", 0, 1, 0)
And the python server doesn't print anything. In my module code, I passed the port name as an argument to the ADDriver constructor and tried to connect with it trough the code:
printf("###########");
asynUser* pAsynUser_;
pasynOctetSyncIO->connect(name, 0, &pAsynUser_, NULL);
pasynManager->disconnect(pAsynUser_);
printf("###########");
But when I execute the IOC i get nothing in my python port. My ioc terminal prints:
(...)
drvAsynIPPortConfigure("LOCALHOST", "127.0.0.1:65432", 0, 1, 0)
MyDriverConfig("MYPORT", "LOCALHOST", 1000, 1000, 1, 0, 0)
###########
###########
(...)
I am still struggling with this because I clearly don't fully understand the differences between asynManager, asynUser, SyncIO, etc...
I looked at the examples in the asyn module and in ADmythen module, but they all use asyn AutoConnect (or maybe I missed something). They are good for showing how to write and read trough the code, but I wasn't able to understand how to disconnect and conenct
to the port's IP.
Can someone explain what am I doing wrong?
Thanks in advance :)
--------------------------------------
Python server:
# echo-server.py
import socket
HOST = "127.0.0.1" # Standard loopback interface address (localhost)
PORT = 65432 # Port to listen on (non-privileged ports are > 1023)
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((HOST, PORT))
s.listen()
conn, addr = s.accept()
with conn:
print(f"Connected by {addr}")
while True:
data = "">
if not data:
break
conn.sendall(data)