Repository navigation
Start without Npcap and report it #55
Description
User story
As an engineer installing Motion Master on a Windows laptop,
I want the server to start with any Npcap install, and to tell me when Npcap is missing,
so that I do not face a loader error before Motion Master can say anything.
Context
SOEM's Windows port sends and receives EtherCAT frames through Npcap. motion-master.exe links wpcap.dll and Packet.dll at load time (CMakeLists.txt:57-64, libs/comm/CMakeLists.txt:23-28). Npcap installs both DLLs in C:\Windows\System32\Npcap\, where the Windows loader does not look. Only the installer option "Install Npcap in WinPcap API-compatible Mode" also puts them in System32.
So on a host without Npcap, or with a default Npcap install, the exe does not start. Windows shows "The code execution cannot proceed because wpcap.dll was not found" before main runs. The README warns about this and tells the user to tick the option (README.md:71).
The unit tests already avoid the problem: libs/comm/tests/CMakeLists.txt:8-16 delay-loads both DLLs, so the tests run on a host without Npcap.
The Npcap developer guide gives the fix for an application that links wpcap.dll: mark it as delay-loaded, and call SetDllDirectory with System32\Npcap before the first call into it. With that, the DLL is found in both install modes. A missing DLL then surfaces only at the first call, as a structured exception from the delay-load helper. This repository uses no exceptions, so the server must check that the DLL loads before any code reaches it.
OBLAC Drives checks for Npcap before it starts the master and shows install instructions (oblac-drives-electron/main.ts:191-196, src/app/start/start.component.html:27-29).
Acceptance criteria
- On Windows, the
mm::npcaptarget delay-loadswpcap.dllandPacket.dll, so every target that links it gets the same behaviour. The separate delay-load lines inlibs/comm/tests/CMakeLists.txtare removed. - At startup, before any SOEM call, the server adds
<system directory>\Npcapto the DLL search path withSetDllDirectoryW, and loadswpcap.dllwithLoadLibraryW. The system directory comes fromGetSystemDirectoryW, not from a fixedC:\Windows. - When the DLL loads, the server logs the string of
pcap_lib_version(). - When the DLL does not load, the server logs a warning that names Npcap and its download page, and keeps running.
-
motion-master.exestarts and serves the HTTP API on a Windows host without Npcap. -
motion-master.exestarts and initialises a SOEM bus with a default Npcap install, with the WinPcap API-compatible option not ticked. - Without Npcap,
POST /api/initwith the SOEM driver fails with 503 and a message that Npcap is not installed. No code path calls intowpcap.dllorPacket.dllwhen the load failed. - Without Npcap, a SOEM driver named in the config file does not make the server exit. The server logs the reason and starts with no bus, so the Console can show what is wrong.
-
GET /api/system-infohas a newnpcapfield. On Windows it is{ installed, version }, withversionfrompcap_lib_version()or empty. On Linux and macOS it isnull. -
GET /api/adapterskeeps working without Npcap. It usesGetAdaptersAddressesand does not call pcap. - The Console Connection page shows a warning with a link to npcap.com when
npcap.installedis false. -
apps/motion_master/swagger.ymldocumentsnpcapand the 503, and the generated client is regenerated. - The README,
docs/INSTALLATION.mdand the comment in.github/workflows/release.yml:208-210say that any Npcap install works. The warning about the WinPcap API-compatible option is removed.
Implementation
- The check lives in
libs/comm, because that library owns SOEM and therefore the dependency on Npcap. One function returns the result, for examplestd::expected<std::string, std::string> loadPacketCaptureLibrary(), with the version or the reason.main.cccalls it once at startup and keeps the result. initDeviceManagerinapps/motion_master/main.ccrefuses the SOEM driver when the result is an error, before it constructsSoemFieldbusDriver.- On Linux and macOS the function is not compiled. Linux SOEM uses raw sockets, and macOS uses the system libpcap.
- Test it on a Windows host three times: with no Npcap, with a default install, and with the WinPcap API-compatible option ticked.
Out of scope
- Installing Npcap from Motion Master, or bundling it. The Npcap licence does not allow free redistribution.
- A check of the Npcap version. Any version that loads is accepted.
References
- Npcap developer guide, loading
wpcap.dllfromSystem32\Npcap: https://npcap.com/guide/npcap-devguide.html - Delay-load in the unit tests:
libs/comm/tests/CMakeLists.txt:8-16 - Current warning:
README.md:71
Activity