{"id":28136777,"url":"https://github.com/sourcehawk/microepsilon-capancdt-reader","last_synced_at":"2025-07-02T20:06:03.507Z","repository":{"id":290806952,"uuid":"975585361","full_name":"sourcehawk/microepsilon-capancdt-reader","owner":"sourcehawk","description":"A c++ client library to read data from proximity sensors connected to micro epsilon's capa NCDT control units","archived":false,"fork":false,"pushed_at":"2025-05-02T23:50:21.000Z","size":63,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-14T16:21:29.163Z","etag":null,"topics":["capancdt","capancdt6100","capancdt6110","capancdt61x0","capancdt61x4","capancdt6200","capancdt6228","capancdt6500","client","cpp","cpplibrary","industrial-automation","industrial-iot","iot","microepsilon","proximity-sensor","sensor-integration"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sourcehawk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-30T14:55:46.000Z","updated_at":"2025-05-05T11:52:03.000Z","dependencies_parsed_at":"2025-04-30T17:38:47.880Z","dependency_job_id":"7cd01db4-8653-4bad-bd1e-8a184bb6ddba","html_url":"https://github.com/sourcehawk/microepsilon-capancdt-reader","commit_stats":null,"previous_names":["sourcehawk/microepsilon-capancdt-reader"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sourcehawk/microepsilon-capancdt-reader","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sourcehawk%2Fmicroepsilon-capancdt-reader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sourcehawk%2Fmicroepsilon-capancdt-reader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sourcehawk%2Fmicroepsilon-capancdt-reader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sourcehawk%2Fmicroepsilon-capancdt-reader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sourcehawk","download_url":"https://codeload.github.com/sourcehawk/microepsilon-capancdt-reader/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sourcehawk%2Fmicroepsilon-capancdt-reader/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263208053,"owners_count":23430675,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["capancdt","capancdt6100","capancdt6110","capancdt61x0","capancdt61x4","capancdt6200","capancdt6228","capancdt6500","client","cpp","cpplibrary","industrial-automation","industrial-iot","iot","microepsilon","proximity-sensor","sensor-integration"],"created_at":"2025-05-14T16:20:05.991Z","updated_at":"2025-07-02T20:06:03.482Z","avatar_url":"https://github.com/sourcehawk.png","language":"C++","readme":"[![codecov](https://codecov.io/gh/sourcehawk/microepsilon-capancdt-reader/graph/badge.svg?token=2BXAU5R0RQ)](https://codecov.io/gh/sourcehawk/microepsilon-capancdt-reader)\n\n# Micro Epsilon capa NCDT reader\n\nThis is a simple c++ client library created to read data from supported proximity sensors connected to [Micro Epsilon's capa NCDT](https://www.micro-epsilon.com/distance-sensors/capacitive-sensors/) control units. The control unit communication is done over a network connection using TCP/IP.\n\nIt was specifically developed to read data from the capa NCDT 6200 control units, but it should work with other capa NCDT control units if they adhere to the same messaging protocol.\n\nTo ensure your control unit is supported, please refer to the [Micro Epsilon manuals](https://www.micro-epsilon.com/distance-sensors/capacitive-sensors/capancdt-6200/) and compare the messaging protocol with the one that NCDT 6200 uses.\n\n## Features\n\n- Read data from supported proximity sensors\n- Support for multiple channels, allowing simultaneous readings from multiple sensors\n- Configurable read rate\n- Simple and easy-to-use API\n\n## Compatibility\n\nThe code is compatible with C++11 and later versions. It has been tested on Linux systems and may need modifications to work on other platforms such as Windows or macOS. More specifically, the socket connection code may need to be adapted for non-POSIX system, but that should be as simple as including the correct headers and using the correct socket functions.\n\nThe CI tests are running on Ubuntu 22.04 and 24.04, but the code has also been compiled and executed on ubuntu 18.04.\n\n## Installation\n\n1. Clone the repository:\n\n   ```bash\n   git clone git@github.com:sourcehawk/microepsilon-capancdt-reader.git\n   ```\n\n2. Navigate to the project directory:\n\n   ```bash\n   cd microepsilon_capancdt_reader\n   ```\n\n3. Build the project:\n\n   ```bash\n   cmake -S . -B build\n   cd build\n   make\n   ```\n\n4. Install the library:\n\n   ```bash\n   sudo make install\n   ```\n\n## Usage\n\nBefore using the library, install it by following the [installation instructions](#installation) and then add the package to you CMake project:\n\n```cmake\ncmake_minimum_required(VERSION 3.10)\nproject(your_project)\n\n# find the package\nfind_package(capancdt_proximity_sensor REQUIRED)\n\n# your executable\nadd_executable(my_app src/main.cpp)\n\n# link the library to your executable\ntarget_link_libraries(my_app\n  PRIVATE capancdt_proximity_sensor::capancdt_proximity_sensor_lib\n)\n```\n\nUsing the library is straightforward. The below example demonstrates how to read data from a proximity sensor connected to a capa NCDT control unit.\n\nEnsure you provide the correct measuring range of the sensor you are using according to it's specifications. For instance the CS02 sensor has a measuring range of 0-2mm, hence the measuring range is 2000 in micrometers.\n\nThe channel number is the number of the channel your sensor is connected to on the control unit, starting from 1. The capaNCDT 6200 control unit for instance supports up to 4 channels, all of which can be used simultaneously.\n\nFor more information on the library interface, please refer to the [header files](include/capancdt/).\n\n```cpp\n#include \u003ciostream\u003e\n#include \u003cstring\u003e\n#include \u003cthread\u003e\n#include \u003cchrono\u003e\n#include \u003ccapancdt/proximity_sensor.h\u003e\n\nusing namespace proximity_sensor;\n\nint main(int argc, char **argv)\n {\n    if (argc \u003c 4) {\n        std::cerr \u003c\u003c \"Usage: \" \u003c\u003c argv[0] \u003c\u003c \" \u003cip\u003e \u003cport\u003e \u003crate\u003e \u003cchannel\u003e \u003crange\u003e\" \u003c\u003c std::endl;\n        return 1;\n    }\n\n    std::string ip = std::string(argv[1]);\n    int port = std::stoi(argv[2]);\n    double rate = std::stod(argv[3]);\n    int channel = std::stoi(argv[4]);\n    double range = std::stod(argv[5]);\n\n    ProximityConnection* conn = new ProximitySocketConnection(ip, port);\n    ProximitySensor* proximity_sensor = new ProximitySensor(conn, rate, 2.0);\n\n    proximity_sensor-\u003estart();\n    std::this_thread::sleep_for(std::chrono::milliseconds(1000));\n\n    ProximitySensorStatus status = proximity_sensor-\u003eget_proximity_sensor_status();\n    if (!status.running()) {\n        std::cerr \u003c\u003c \"Failed to start the sensor: \" \u003c\u003c status.message \u003c\u003c std::endl;\n        return 1;\n    }\n\n    auto period = std::chrono::duration\u003cdouble\u003e(1.0 / rate);\n\n    while (true)\n    {\n        std::cout \u003c\u003c proximity_sensor-\u003eget_distance(channel, range) \u003c\u003c std::endl;\n        std::this_thread::sleep_for(period);\n    }\n\n    return 0;\n}\n```\n\n## Mocking sensors in development\n\nThe library provides a mock implementation of the `ProximityConnection` class that can be used for testing and development purposes. This allows you to simulate the behavior of a real sensor without needing to connect to an actual device.\n\nIn this snippet, we create a mock connection, construct a mock message, and encode it to the mock data buffer to be returned by the mock connection on recv calls.\n\n```cpp\nProximityConnection* conn;\n\nif (mock) {\n    ProximityMockConnection* mock_conn = new ProximityMockConnection();\n\n    // Create a mock message header\n    ProximitySensorMessageHeader mock_header {};\n    memcpy(mock_header.preamble, MESSAGE_HEADER_PREAMBLE_C, sizeof(mock_header.preamble));\n    mock_header.order               = 69;\n    mock_header.serial              = 12345;\n    mock_header.channels            = 0x0000'0000'0000'0001u \u003c\u003c ((channel-1)*2);\n    mock_header.status              = 0;\n    mock_header.frame_count         = 1;\n    mock_header.bytes_per_frame     = 4;\n    mock_header.start_sample_number = 1;\n\n    // Create a buffer to hold the encoded message\n    size_t payload_size = mock_header.payload_size();\n    char* messages = new char[payload_size];\n\n    // Create a mock message with the header\n    auto header_ptr = std::make_unique\u003cProximitySensorMessageHeader\u003e(mock_header);\n    ProximitySensorMessage mock_message = ProximitySensorMessage(std::move(header_ptr));\n    mock_message.set_channel_value(1, ChannelValue(\n        mock_header.start_sample_number,\n        // This is the value that will be returned by the mock sensor\n        ChannelValue::from_micrometers(2000.0, range)\n    ));\n\n    // Encode the mock message to the messages buffer\n    mock_message.encode(messages, payload_size);\n    // Set the mock data to return on recv calls\n    mock_conn-\u003eset_recv_data(messages, payload_size);\n    // Assign the mock connection to the abstract connection\n    conn = mock_conn;\n} else {\n    conn = new ProximitySocketConnection(ip, port);\n}\n\nProximitySensor* proximity_sensor = new ProximitySensor(conn, rate, 2.0);\n```\n\n## Provided verification binary\n\nThe library provides a standalone binary that can be used to read data from the capa NCDT control unit and output the measurements to the console. After installing the library, the binary can be found in the `bin` directory (f.x `/usr/local/bin/`). The binary is called `capancdt_read_sensor` and can be used as follows:\n\n```bash\n./capancdt_read_sensor \u003cip\u003e \u003cport\u003e \u003crate\u003e \u003cchannel\u003e \u003crange\u003e\n```\n\nWhere:\n\n- `\u003cip\u003e`: The IP address of the capa NCDT control unit.\n- `\u003cport\u003e`: The port number of the capa NCDT control unit.\n- `\u003crate\u003e`: The read rate in Hz (e.g., 10.0 for 10 Hz).\n- `\u003cchannel\u003e`: The channel number of the sensor (1, 2, 3, 4...).\n- `\u003crange\u003e`: The measuring range of the sensor in micrometers (e.g., 2000 for a 0-2mm sensor).\n\n## Development\n\nInstall GTest and lcov for testing. On ubuntu you can do this with:\n\n```bash\nsudo apt-get install libgtest-dev lcov\n```\n\nYou may need to build GTest:\n\n```bash\ncd /usr/src/googletest\nsudo cmake .\nsudo make\nsudo make install\n```\n\nBuild the project:\n\n```bash\ncmake -S . -B build \\\n  -DENABLE_COVERAGE=ON \\\n  -DBUILD_TESTING=ON \\\n  -DCMAKE_BUILD_TYPE=Debug\n\ncmake --build build --parallel\n```\n\nTesting:\n\n\u003e cd build \u0026\u0026 make test\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsourcehawk%2Fmicroepsilon-capancdt-reader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsourcehawk%2Fmicroepsilon-capancdt-reader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsourcehawk%2Fmicroepsilon-capancdt-reader/lists"}