|
OpenSRX 0.1.0
C++ library for interfacing with Keyence SR series barcode readers
|
High-level interface to a KEYENCE SR-X series barcode scanner. More...
#include <Scanner.hpp>
Classes | |
| struct | SavedImageDests |
| Previous SAVE_DEST values saved by startImageServer, restored on stop. More... | |
Public Member Functions | |
| Scanner (ICommInterface &comm) | |
| Connect to a scanner on the given communication interface. | |
| ~Scanner ()=default | |
| Code | startReading () |
| Start a blocking read operation. | |
| Code | startReading (int bank) |
| Start a blocking read operation on a specific bank. | |
| void | stopReading () |
| Cancel an in-progress read operation. | |
| void | startQuickSetupCodeReading () |
| Enter quick-setup code reading mode (RCON). | |
| void | finishQuickSetupCodeReading () |
| Exit quick-setup code reading mode (RCOFF). | |
| std::string | checkQuickSetupCodeResult () |
| Check the result of a quick-setup code reading. | |
| void | readingRateTest () |
| Start a reading rate test on all banks. | |
| void | readingRateTest (int bank) |
| Start a reading rate test on a specific bank. | |
| void | readTimeTest () |
| Start a read time test on all banks. | |
| void | readTimeTest (int bank) |
| Start a read time test on a specific bank. | |
| void | quitTestMode () |
| Quit test mode (reading rate or read time). | |
| bool | getInputTerminalState (int terminalNumber) |
| Get the state of an input terminal. | |
| void | turnOnOutputTerminal (int terminalNumber) |
| Turn on a specific output terminal. | |
| void | turnOffOutputTerminal (int terminalNumber) |
| Turn off a specific output terminal. | |
| void | turnOnAllOutputTerminals () |
| Turn on all output terminals. | |
| void | turnOffAllOutputTerminals () |
| Turn off all output terminals. | |
| void | reset () |
| Reset the scanner. | |
| void | clearSendBuffer () |
| Clear the scanner's send buffer. | |
| std::string | captureImage (int bank) |
| Capture an image and return the remote file path. | |
| void | adjustFocus () |
| Run auto-focus adjustment (blocks until complete). | |
| std::tuple< bool, TuningAdvice, TuningFailureReason > | startTuning (int bank) |
| Start tuning on a specific bank (blocks until complete). | |
| void | stopTuning () |
| Cancel an in-progress tuning operation. | |
| std::string | getModel () const |
| Get the scanner model string (e.g. "SR-X300"). | |
| std::string | getFirmwareVersion () const |
| Get the scanner firmware version string. | |
| std::string | getMacAddress () const |
| Get the scanner MAC address string. | |
| void | enablePointer () |
| Enable the laser aiming pointer. | |
| void | disablePointer () |
| Disable the laser aiming pointer. | |
| void | setTime (const Timestamp ×tamp) |
| Set the scanner's internal clock. | |
| Timestamp | getTime () |
| Read the scanner's internal clock. | |
| CommandStatus | getCommandStatus () |
| Query the scanner's command processing status. | |
| ErrorStatus | getErrorStatus () |
| Query the scanner's error status. | |
| BusyStatus | getBusyStatus () |
| Query the scanner's busy status. | |
| void | copyBankConfiguration (int sourceBank, int targetBank) |
| Copy configuration from one bank to another. | |
| void | saveSettings () |
| Save all current settings to non-volatile memory. | |
| void | loadSavedSettings () |
| Load settings from non-volatile memory. | |
| void | resetToFactorySettings () |
| Reset all settings to factory defaults. | |
| void | saveBackupSettings (int backupNumber) |
| Save settings to a backup slot. | |
| void | loadBackupSettings (int backupNumber) |
| Load settings from a backup slot. | |
| void | clearFTPCommsError () |
| Clear the FTP communication error flag. | |
| void | clearPLCLinkError () |
| Clear the PLC link error flag. | |
| void | startImageServer (const std::string &localIP, ImageSaveConfig saveConfig={}, uint16_t port=0, const std::string &username="opensrx", const std::string &password="opensrx") |
| Start an embedded FTP server and configure the scanner to send images to it. | |
| void | stopImageServer () |
| Image | waitForImage () |
| Block until the scanner delivers an image via FTP, decode it, and return the raw pixel data. | |
| bool | tryGetImage (Image &image) |
| Return the next image if one is available, without blocking. | |
| std::deque< Image > | getImages () |
| Return all images currently queued. | |
| void | setImageCallback (std::function< void(const Image &)> cb) |
| Set a callback invoked on the watcher thread each time a new image is decoded. | |
| ImageServer * | getImageServer () |
| Access the underlying ImageServer (nullptr if not started). | |
| template<BankParam P> | |
| auto | getParam (int bank) -> ParamCppT< paramType(P)> |
| Read a bank parameter. | |
| template<BankParam P> | |
| void | setParam (int bank, const ParamCppT< paramType(P)> &value) |
| Write a bank parameter. | |
| template<TuningParam P> | |
| auto | getParam () -> ParamCppT< paramType(P)> |
| Read a tuning parameter. | |
| template<TuningParam P> | |
| void | setParam (const ParamCppT< paramType(P)> &value) |
| Write a tuning parameter. | |
| template<OperationParam P> | |
| auto | getParam () -> ParamCppT< paramType(P)> |
| Read an operation parameter. | |
| template<OperationParam P> | |
| void | setParam (const ParamCppT< paramType(P)> &value) |
| Write an operation parameter. | |
| template<CommParam P> | |
| auto | getParam () -> ParamCppT< paramType(P)> |
| Read a communication parameter. | |
| template<CommParam P> | |
| void | setParam (const ParamCppT< paramType(P)> &value) |
| Write a communication parameter. | |
Private Member Functions | |
| Code | parseReadResult (const std::string &raw) |
| Parse a raw read-result string into a Code struct. | |
| std::string | checkResponse (const std::string &response) |
| Parse and validate a scanner response string. | |
Private Attributes | |
| ICommInterface & | comm |
| Communication interface to the scanner. | |
| std::string | model |
| Scanner model string. | |
| std::string | firmwareVersion |
| Scanner firmware version string. | |
| std::string | macAddress |
| Scanner MAC address string. | |
| std::unique_ptr< ImageServer > | imageServer |
| Embedded FTP image server (if started). | |
| std::unique_ptr< SavedImageDests > | savedImageDests |
Friends | |
| class | TestScanner |
High-level interface to a KEYENCE SR-X series barcode scanner.
Wraps an ICommInterface and exposes typed methods for every scanner command: reading, tuning, I/O control, status queries, settings management, and parameter get/set. Also provides an integrated FTP image server for receiving captured images.
| OpenSRX::Scanner::Scanner | ( | ICommInterface & | comm | ) |
Connect to a scanner on the given communication interface.
Sends the KEYENCE handshake and EMAC commands to obtain the model, firmware version, and MAC address.
| comm | A previously-opened communication interface. |
| std::runtime_error | on handshake failure. |
|
default |
| void OpenSRX::Scanner::adjustFocus | ( | ) |
Run auto-focus adjustment (blocks until complete).
| std::string OpenSRX::Scanner::captureImage | ( | int | bank | ) |
Capture an image and return the remote file path.
| bank | Bank number (1–16). |
| std::string OpenSRX::Scanner::checkQuickSetupCodeResult | ( | ) |
Check the result of a quick-setup code reading.
|
private |
Parse and validate a scanner response string.
Extracts the value from an "OK,CMD,value" response, or throws on an "ER,CMD,code" error response.
| response | The raw response string from the scanner. |
| std::invalid_argument,std::out_of_range,std::runtime_error | depending on the error code. |
| void OpenSRX::Scanner::clearFTPCommsError | ( | ) |
Clear the FTP communication error flag.
| void OpenSRX::Scanner::clearPLCLinkError | ( | ) |
Clear the PLC link error flag.
| void OpenSRX::Scanner::clearSendBuffer | ( | ) |
Clear the scanner's send buffer.
| void OpenSRX::Scanner::copyBankConfiguration | ( | int | sourceBank, |
| int | targetBank ) |
Copy configuration from one bank to another.
| sourceBank | Source bank number (1–16). |
| targetBank | Target bank number (1–16). |
| void OpenSRX::Scanner::disablePointer | ( | ) |
Disable the laser aiming pointer.
| void OpenSRX::Scanner::enablePointer | ( | ) |
Enable the laser aiming pointer.
| void OpenSRX::Scanner::finishQuickSetupCodeReading | ( | ) |
Exit quick-setup code reading mode (RCOFF).
| BusyStatus OpenSRX::Scanner::getBusyStatus | ( | ) |
Query the scanner's busy status.
| CommandStatus OpenSRX::Scanner::getCommandStatus | ( | ) |
Query the scanner's command processing status.
| ErrorStatus OpenSRX::Scanner::getErrorStatus | ( | ) |
Query the scanner's error status.
|
inline |
Get the scanner firmware version string.
| std::deque< Image > OpenSRX::Scanner::getImages | ( | ) |
Return all images currently queued.
|
inline |
Access the underlying ImageServer (nullptr if not started).
| bool OpenSRX::Scanner::getInputTerminalState | ( | int | terminalNumber | ) |
Get the state of an input terminal.
| terminalNumber | Input terminal number. |
|
inline |
Get the scanner MAC address string.
|
inline |
Get the scanner model string (e.g. "SR-X300").
|
inline |
Read a tuning parameter.
| P | The TuningParam enumerator. |
|
inline |
Read an operation parameter.
| P | The OperationParam enumerator. |
Read a communication parameter.
| P | The CommParam enumerator. |
Read a bank parameter.
| P | The BankParam enumerator (determines the return type). |
| bank | Bank number (1–16). |
| Timestamp OpenSRX::Scanner::getTime | ( | ) |
Read the scanner's internal clock.
| void OpenSRX::Scanner::loadBackupSettings | ( | int | backupNumber | ) |
Load settings from a backup slot.
| backupNumber | Backup slot number. |
| void OpenSRX::Scanner::loadSavedSettings | ( | ) |
Load settings from non-volatile memory.
|
private |
Parse a raw read-result string into a Code struct.
Splits the result by the inter-delimiter and populates optional fields based on which OperationParam appending settings are enabled.
| raw | The raw string returned by LON (barcode + appended fields). |
| void OpenSRX::Scanner::quitTestMode | ( | ) |
Quit test mode (reading rate or read time).
| void OpenSRX::Scanner::readingRateTest | ( | ) |
Start a reading rate test on all banks.
| void OpenSRX::Scanner::readingRateTest | ( | int | bank | ) |
Start a reading rate test on a specific bank.
| bank | Bank number (1–16). |
| void OpenSRX::Scanner::readTimeTest | ( | ) |
Start a read time test on all banks.
| void OpenSRX::Scanner::readTimeTest | ( | int | bank | ) |
Start a read time test on a specific bank.
| bank | Bank number (1–16). |
| void OpenSRX::Scanner::reset | ( | ) |
Reset the scanner.
| void OpenSRX::Scanner::resetToFactorySettings | ( | ) |
Reset all settings to factory defaults.
| void OpenSRX::Scanner::saveBackupSettings | ( | int | backupNumber | ) |
Save settings to a backup slot.
| backupNumber | Backup slot number. |
| void OpenSRX::Scanner::saveSettings | ( | ) |
Save all current settings to non-volatile memory.
| void OpenSRX::Scanner::setImageCallback | ( | std::function< void(const Image &)> | cb | ) |
Set a callback invoked on the watcher thread each time a new image is decoded.
|
inline |
Write a tuning parameter.
| P | The TuningParam enumerator. |
| value | The value to set. |
|
inline |
Write an operation parameter.
| P | The OperationParam enumerator. |
| value | The value to set. |
|
inline |
Write a communication parameter.
| P | The CommParam enumerator. |
| value | The value to set. |
|
inline |
Write a bank parameter.
| P | The BankParam enumerator (determines the value type). |
| bank | Bank number (1–16). |
| value | The value to set. |
| void OpenSRX::Scanner::setTime | ( | const Timestamp & | timestamp | ) |
Set the scanner's internal clock.
| timestamp | The date/time to set. |
| void OpenSRX::Scanner::startImageServer | ( | const std::string & | localIP, |
| ImageSaveConfig | saveConfig = {}, | ||
| uint16_t | port = 0, | ||
| const std::string & | username = "opensrx", | ||
| const std::string & | password = "opensrx" ) |
Start an embedded FTP server and configure the scanner to send images to it.
The server listens on a free port by default. The scanner's FTP IP, username, password, and port parameters are written automatically. Image saving destinations selected in saveConfig are set to SEND_BY_FTP; they are restored to their previous values when stopImageServer() is called.
| localIP | The IP address of this machine as reachable from the scanner (e.g. "192.168.1.100"). |
| saveConfig | Which image types to send via FTP (default: read OK only). |
| port | FTP port (0 = OS picks a free port). |
| username | FTP username. |
| password | FTP password. |
| void OpenSRX::Scanner::startQuickSetupCodeReading | ( | ) |
Enter quick-setup code reading mode (RCON).
| Code OpenSRX::Scanner::startReading | ( | ) |
Start a blocking read operation.
Blocks until a code is read or the read times out. Uses an unlocked send so that stopReading() can be called from another thread.
| std::runtime_error | on read timeout or failure. |
| Code OpenSRX::Scanner::startReading | ( | int | bank | ) |
Start a blocking read operation on a specific bank.
| bank | Bank number (1–16). |
| std::runtime_error | on read timeout or failure. |
| std::tuple< bool, TuningAdvice, TuningFailureReason > OpenSRX::Scanner::startTuning | ( | int | bank | ) |
Start tuning on a specific bank (blocks until complete).
Uses an unlocked send so that stopTuning() can be called from another thread.
| bank | Bank number (1–16). |
| void OpenSRX::Scanner::stopImageServer | ( | ) |
Stop the embedded FTP image server.
| void OpenSRX::Scanner::stopReading | ( | ) |
Cancel an in-progress read operation.
| void OpenSRX::Scanner::stopTuning | ( | ) |
Cancel an in-progress tuning operation.
| bool OpenSRX::Scanner::tryGetImage | ( | Image & | image | ) |
Return the next image if one is available, without blocking.
| [out] | image | Filled on success. |
| void OpenSRX::Scanner::turnOffAllOutputTerminals | ( | ) |
Turn off all output terminals.
| void OpenSRX::Scanner::turnOffOutputTerminal | ( | int | terminalNumber | ) |
Turn off a specific output terminal.
| terminalNumber | Output terminal number. |
| void OpenSRX::Scanner::turnOnAllOutputTerminals | ( | ) |
Turn on all output terminals.
| void OpenSRX::Scanner::turnOnOutputTerminal | ( | int | terminalNumber | ) |
Turn on a specific output terminal.
| terminalNumber | Output terminal number. |
| Image OpenSRX::Scanner::waitForImage | ( | ) |
Block until the scanner delivers an image via FTP, decode it, and return the raw pixel data.
Requires startImageServer() to have been called first.
|
friend |
|
private |
Communication interface to the scanner.
|
private |
Scanner firmware version string.
|
private |
Embedded FTP image server (if started).
|
private |
Scanner MAC address string.
|
private |
Scanner model string.
|
private |