A few years back, I designed a coupler spring made of shape-memory alloy that could be activated via DCC, but I never put it into practice. I did see that someone else had, but I can't find the site. You might look into that instead of using an electromagnet.