OpenSRX 0.1.0
C++ library for interfacing with Keyence SR series barcode readers
Loading...
Searching...
No Matches
Getting Started

OpenSRX is a C++ library that lets you control Keyence SR-X series barcode readers programmatically. It supports two communication backends:

  • SocketInterface – TCP/IP over Ethernet (default port 9004)
  • SerialInterface – RS-232 serial link

Prerequisites

  • A C++17 compiler (GCC ≥ 9, Clang ≥ 10, MSVC ≥ 19.20)
  • CMake ≥ 3.16
  • An internet connection during the first build (dependencies are fetched automatically via CMake FetchContent)

Quick Start

git clone https://github.com/jwlodek/OpenSRX.git
cd OpenSRX
cmake -S . -B build
cmake --build build

After building, example binaries are at build/examples/ (e.g. VersionInfo, ReadCode, ImageReadback). All examples accept --ip/--port or --serial arguments — run with --help for usage details.

Umbrella Header

Include a single header to get the entire public API:

Umbrella header for the OpenSRX library.

Connecting to a Scanner

// Over Ethernet
OpenSRX::SocketInterface comm("192.168.100.100", 9004);
OpenSRX::Scanner scanner(comm);
std::cout << scanner.getModel() << std::endl; // e.g. "SR-X300"
std::cout << scanner.getFirmwareVersion() << std::endl; // e.g. "R2.04.00"
High-level interface to a KEYENCE SR-X series barcode scanner.
Definition Scanner.hpp:90
Communication interface using a TCP/IP socket.
Definition SocketInterface.hpp:17

Reading a Barcode

startReading() blocks until the scanner decodes a code (or throws on timeout):

OpenSRX::Code code = scanner.startReading();
std::cout << "Data: " << code.data << std::endl;
Result of a barcode read operation.
Definition Code.hpp:42
std::string data
The decoded barcode string.
Definition Code.hpp:43

Enable appending options for extra metadata:

OpenSRX::Code code = scanner.startReading();
if (code.boundingBox) {
auto& bb = *code.boundingBox;
std::cout << "Top-left: (" << bb.topLeft.x << ", " << bb.topLeft.y << ")\n";
}
if (code.center) {
std::cout << "Center: (" << code.center->x << ", " << code.center->y << ")\n";
}
@ ENABLE
Definition ParamValues.hpp:10
@ CODE_VERTEX_APPENDING
Definition OperationParam.hpp:121
@ CODE_CENTER_APPENDING
Definition OperationParam.hpp:122

Getting and Setting Parameters

Parameters are accessed with compile-time-typed templates:

// Bank parameters (require a bank number)
int exposure = scanner.getParam<OpenSRX::BankParam::EXPOSURE_TIME>(1);
scanner.setParam<OpenSRX::BankParam::EXPOSURE_TIME>(1, 500);
// Operation parameters
auto fmt = scanner.getParam<OpenSRX::OperationParam::IMAGE_FORMAT>();
// Communication parameters
std::string ip = scanner.getParam<OpenSRX::CommParam::FTP_REMOTE_IP>();
@ BMP
Definition ParamValues.hpp:232
@ EXPOSURE_TIME
Definition BankParam.hpp:24
@ IMAGE_FORMAT
Definition OperationParam.hpp:149
@ FTP_REMOTE_IP
Definition CommParam.hpp:91

Image Readback

Start an embedded FTP server, trigger a read, and receive the image:

scanner.startImageServer("192.168.100.50"); // your machine's IP
OpenSRX::Code code = scanner.startReading();
OpenSRX::Image img = scanner.waitForImage();
// img.width, img.height, img.channels, img.data
scanner.stopImageServer();
Raw decoded image data.
Definition Image.hpp:18

Using the Simulator

For development without hardware, use the Python simulator:

python scripts/simulator.py
# or: pixi run simulator

Then point examples at 127.0.0.1:9004:

./build/examples/ReadCode --ip 127.0.0.1 --port 9004