Recently I have to use EtherCAT for my program and decided to use SOEM. I managed to translate the code and use it. I think it is a good idea to use IO cancelation ergonomics when using SOEM.
In using SOEM, you have to keep sending and receiving processdata to the slaves otherwise the connection might be terminated once your connection is in operational state.
My approach is to spawn this process into another thread to avoid connection termination. I thought that I can use concurrent() for this thread, so that it also react to any cancelation from another thread. But, I just realized there is no cancelation point in the processdata thread, so whenever other thread trigger cancel(), the processdata thread is not responding to the cancelation.
By writing this topic, I am just curious is there any way to give the processdata a way to react to any cancelation from another thread?
The processdata thread will looks something like this:
pub fn process(ctx: *soem.ecx_contexttt) !void {
while (true) {
if (soem.ecx_send_processdata(ctx) != expected_WKC and
soem.ecx_receive_processdata(ctx, soem.EC_TIMEOUTRET) != expected_WKC)
{
return error.InvalidWorkCounter;
}
}
}