Skip to content

Start without Npcap and report it #55

Open

Description

@markosankovic

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::npcap target delay-loads wpcap.dll and Packet.dll, so every target that links it gets the same behaviour. The separate delay-load lines in libs/comm/tests/CMakeLists.txt are removed.
  • At startup, before any SOEM call, the server adds <system directory>\Npcap to the DLL search path with SetDllDirectoryW, and loads wpcap.dll with LoadLibraryW. The system directory comes from GetSystemDirectoryW, not from a fixed C:\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.exe starts and serves the HTTP API on a Windows host without Npcap.
  • motion-master.exe starts and initialises a SOEM bus with a default Npcap install, with the WinPcap API-compatible option not ticked.
  • Without Npcap, POST /api/init with the SOEM driver fails with 503 and a message that Npcap is not installed. No code path calls into wpcap.dll or Packet.dll when 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-info has a new npcap field. On Windows it is { installed, version }, with version from pcap_lib_version() or empty. On Linux and macOS it is null.
  • GET /api/adapters keeps working without Npcap. It uses GetAdaptersAddresses and does not call pcap.
  • The Console Connection page shows a warning with a link to npcap.com when npcap.installed is false.
  • apps/motion_master/swagger.yml documents npcap and the 503, and the generated client is regenerated.
  • The README, docs/INSTALLATION.md and the comment in .github/workflows/release.yml:208-210 say 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 example std::expected<std::string, std::string> loadPacketCaptureLibrary(), with the version or the reason. main.cc calls it once at startup and keeps the result.
  • initDeviceManager in apps/motion_master/main.cc refuses the SOEM driver when the result is an error, before it constructs SoemFieldbusDriver.
  • 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions