Beckhoff / ADS

Beckhoff protocol to communicate with TwinCAT devices.
MIT License
502 stars 194 forks source link

Perform AdsSyncReadWriteReqEx2 during Notification #100

Closed mriepl closed 4 years ago

mriepl commented 4 years ago

Hello,

i had tried to perform an AdsSyncReadWriteReqEx2 call in the notification callback function. At first i got the ADS Error -1 (Warning: Port: 30000 already in use) and i found this issue (https://github.com/Beckhoff/ADS/issues/20)

now i tried to open also a new port with AdsPortOpenEx (got Port 30001) in the callback function to perform the AdsSyncReadWriteReqEx2 request but this also dont work and i got an ADS Error 1861 ADSERR_CLIENT_SYNCTIMEOUT.

is it possible to do any read/write requests in the notification callback function?

pbruenn commented 4 years ago

Well, I would strongly advice against it. The callback is called in the context of a thread which blocks the receive buffer from being emptied. So running a long operation such as Network requests might overflow the buffer and you might miss future notifications. I suggest you keep your callback pretty short on execution time and just use it to handover work to a worker thread.