Skip to content

HAL ​

Introduction ​

The iNexBot EtherCAT master station controller has a master jitter time of less than 20us. It can be used for the development of industrial automation control systems, especially suitable for scenarios with high real-time requirements such as robotics and servo motor control.

Version Information ​

Secondary Development VersionCompany
1.0.0INEXBOT

Version Iterations ​

VersionModified DateModified ByDescription
1.0.020250310EAInitial version

Overview ​

About This Document ​

This document aims to help users use the iNexBot libhal_sdk C++ library.

About the libhal_sdk Library ​

This library is the hardware abstraction layer for the iNexBot system, unifying the user interface and facilitating ease of use.

Development Environment Requirements ​

Operating SystemUbuntu 20.04 LTS
System Architecturex86_64
CompilerGCC version 9.4.0/GLIBC 2.31-0ubuntu9.2
GCC version 4.8.2/EGLIBC 2.19-0ubuntu6.15
Dependency LibrariesLibpthread, librt, libdl, libm

Function Library API Reference ​

Usage Overview ​

  1. Copy the libhal_sdk.a static library file to the project's lib directory

  2. Copy the header files from the include folder to the project's include directory

  3. Link the libhal_sdk.a library during compilation

Demo download

Class List ​

Class NameDescription
Device classBase class for all device objects.
DeviceManager classManager class for Device objects.
AnalogIO classAbstraction of analog IO devices.
CANDevice classAbstraction of CAN devices.
DigitalIO classAbstraction of digital IO.
EncoderDevice classAbstraction of encoder devices.
PwmDevice classAbstraction of PWM devices.
SerialDevice classAbstraction of Serial devices.
UpsDevice classAbstraction of UPS devices.

hal_sdk Usage Flowchart ​

hal_sdk overall usage flowchart showing the relationship between DeviceManager and device classes

Usage Example ​

demo.cpp ​

#include <hal/device_manager.h>
#include <hal/devices/digital_io.h>
#include <hal/devices/analog_io.h>
#include <hal/devices/can_device.h>
#include <hal/devices/pwm_device.h>
#include <hal/devices/encoder_device.h>
#include <hal/devices/ups_device.h>
#include <iostream>
#include <thread>
#include <chrono>


void print_device_info(const std::vector<std::string>& devices) {
    std::cout << "Devices:" << std::endl;
    for (const auto& name : devices) {
        std::cout << "- " << name << std::endl;
    }
    std::cout << std::endl;
}


int main() {
    auto& manager = hal::DeviceManager::instance();

    try {
        // 1. Demonstrate the device manager's query functionality
        std::cout << "\n=== Device Query ===" << std::endl;
        auto all_devices = manager.get_all_device_name_list();
        std::cout << "All devices:" << std::endl;
        print_device_info(all_devices);


        // Get list of specific device type
        auto dio_devices = manager.get_device_name_list(hal::DeviceType::DIGITAL_IO_);
        std::cout << "Digital IO devices:" << std::endl;
        print_device_info(dio_devices);


        // 2. Get and use devices through DeviceManager
        std::cout << "\n=== Device Usage Examples ===" << std::endl;

        // Use digital IO
        if (auto dio_dev = manager.get_device(hal::DeviceType::DIGITAL_IO_, "DIO_1")) {
            auto digital_io = std::dynamic_pointer_cast<hal::DigitalIO>(dio_dev);
            digital_io->set_output(2, true);
            std::cout << "DIO_1 channel 3: " << digital_io->get_input(3) << std::endl;
        }


        // Use CAN device
        if (auto can_dev = manager.get_device(hal::DeviceType::CAN_DEVICE_, "CAN_1")) {
            auto can_device = std::dynamic_pointer_cast<hal::CANDevice>(can_dev);
            can_device->open(0);
            can_device->set_parameters(0, 500000);
            unsigned char tx_data[8] = {0x11, 0x22, 0x33, 0x44};
            can_device->send(0, 0x123, tx_data, 4);
            unsigned int rx_id;
            unsigned char rx_data[16];
            unsigned int rx_len = can_device->receive(0, rx_id, rx_data);
            std::cout << "CAN_1 received length: " << rx_len << std::endl;
        }


        // 3. Device existence check
        std::cout << "\n=== Device Existence Check ===" << std::endl;
        std::cout << "DIO_1 exists: "
                  << manager.is_device_exist(hal::DeviceType::DIGITAL_IO_, "DIO_1") << std::endl;


    } catch (const std::exception& e) {
        std::cerr << "Error: " << e.what() << std::endl;
        return 1;
    }

    return 0;
}

Function Library API Detailed Reference ​

DeviceType Enum ​

enum class DeviceType {
    NULL_,
    ANALOG_IO_,
    CAN_DEVICE_,
    DIGITAL_IO_,
    ENCODER_DEVICE_,
    PWM_DEVICE_,
    SERIAL_DEVICE_,
    UPS_DEVICE_,
    CUSTOM_
};
Variable NameDescription
NULL_Null device
DIGITAL_IO_Digital input/output device
ANALOG_IO_Analog input/output device
CAN_DEVICE_CAN bus device
PWM_DEVICE_Pulse width modulation device
ENCODER_DEVICE_Encoder device
UPS_DEVICE_Uninterruptible power supply device
SERIAL_DEVICE_Serial port device
CUSTOM_Custom device

Device Class ​

This class is the base class for all device objects.

Device Class Definition ​

class Device {
public:
    Device(DeviceType device_type, const std::string& device_name);
    virtual ~Device() = default;

    bool valid() const { return valid_; }
    DeviceType get_device_type() const { return device_type_; }
    std::string get_device_name() const { return device_name_; }

protected:
    bool valid_{false};
    DeviceType device_type_;
    std::string device_name_;
};
}

Device Class Member Functions ​

Function NameFunction DescriptionClass Access Permission
DeviceConstructorPublic
get_device_typeGet device typepublic
get_device_nameGet device namepublic
validCheck if device is availablepublic

Device Class Member Variables ​

Variable NameVariable DescriptionClass Access Permission
valid_Whether availableprotected
device_type_Device typeprotected
device_name_Device nameprotected

Member Function Detailed Reference ​

Device ​

Function PrototypeDevice(DeviceType device_type, const std::string& device_name);
Function DescriptionConstructor, used to initialize the Device object.
Parameter DescriptionInput parameters: device_type: Device type, used to specify the device category. device_name: Device name, used to identify the device.
Return ValueNone
RemarksThis constructor is used to create a Device object and initialize its device type and name.

~Device ​

Function Prototypevirtual ~Device() = default;
Function DescriptionDestructor, used to destroy the Device object.
Parameter DescriptionNone
Return ValueNone
RemarksThis destructor is virtual, ensuring proper destruction of derived classes.

valid ​

Function Prototypebool valid() const;
Function DescriptionCheck if the Device object is valid.
Parameter DescriptionNone
Return ValueReturns a bool value; true indicates the Device object is valid, false indicates invalid.
RemarksThis function is used to determine whether the Device object's state is valid.

get_device_type ​

Function PrototypeDeviceType get_device_type() const;
Function DescriptionGet the device type of the Device object.
Parameter DescriptionNone
Return ValueReturns a DeviceType value, representing the Device object's device type.
RemarksThis function is used to get the Device object's device type.

get_device_name ​

Function Prototypestd::string get_device_name() const;
Function DescriptionGet the device name of the Device object.
Parameter DescriptionNone
Return ValueReturns a std::string value, representing the Device object's device name.
RemarksThis function is used to get the Device object's device name.

DeviceManager Class ​

This class is the manager class for Device objects.

Class Definition ​

class DeviceManager {
public:
    static DeviceManager &instance();


    int add_device(std::shared_ptr<Device> device);
    int remove_device(DeviceType device_type, const std::string& device_name);
    bool is_device_exist(DeviceType device_type, const std::string& device_name) const;

    std::vector<std::string> get_all_device_name_list() const;
    std::vector<std::string> get_device_name_list(DeviceType device_type) const;
    std::vector<std::shared_ptr<Device>> get_device_list(DeviceType device_type) const;
    std::shared_ptr<Device> get_device(DeviceType device_type, const std::string& device_name) const;


private:
    DeviceManager() = default;
    static void register_devices(DeviceManager &manager);
    std::unordered_map<std::string, std::shared_ptr<Device>> devices_;
};

Class Member Functions ​

Function NameFunction DescriptionClass Access Permission
instanceGet the singleton instance of the device managerpublic
add_deviceAdd a device to the device managerpublic
remove_deviceRemove a device from the device managerpublic
is_device_existCheck if a device existspublic
get_all_device_name_listGet the name list of all devicespublic
get_device_name_listGet the name list of all devices of a certain typepublic
get_device_listGet the object instances of all devices of a certain typepublic
get_deviceGet a specific devicepublic
DeviceManagerConstructorprivate
register_devicesRegister devicesprivate

Class Member Variables ​

Variable NameVariable DescriptionClass Access Permission
device_Stores all devices mounted to the device managerprivate

Member Function Detailed Reference ​

instance ​

Function Prototypestatic DeviceManager &instance();
Function DescriptionGet the singleton instance of the DeviceManager class.
Parameter DescriptionNone
Return ValueReturns a reference to the DeviceManager class's singleton instance.
RemarksThis function is used to get the unique instance of the DeviceManager class.

add_device ​

Function Prototypeint add_device(std::shared_ptr<Device> device);
Function DescriptionAdd a device to the device manager.
Parameter DescriptionInput parameter:
device: The device object to add
Return ValueReturns an int value; 0 indicates success, non-zero indicates failure.
RemarksThis function is used to add a new device to the device manager.

remove_device ​

Function Prototypeint remove_device(DeviceType device_type, const std::string& device_name);
Function DescriptionRemove a device from the device manager.
Parameter DescriptionInput parameters:
device_type: The device type.
device_name: The name of the device to remove.
Return ValueReturns an int value; 0 indicates success, non-zero indicates failure.
RemarksThis function is used to remove a device with the specified type and name from the device manager.

is_device_exist ​

Function Prototypebool is_device_exist(DeviceType device_type, const std::string& device_name) const;
Function DescriptionCheck if a device with the specified type and name exists in the device manager.
Parameter DescriptionInput parameters:
device_type: The device type.
device_name: The device name to check.
Return ValueReturns a bool value; true indicates exists, false indicates does not exist.
RemarksThis function is used to check if a device with the specified type and name exists in the device manager.

get_all_device_name_list ​

Function Prototypestd::vector<std::string> get_all_device_name_list() const;
Function DescriptionGet the name list of all devices in the device manager.
Parameter DescriptionNone
Return ValueReturns a string vector containing all device names.
RemarksThis function is used to get the name list of all devices in the device manager.

get_device_name_list ​

Function Prototypestd::vector<std::string> get_device_name_list(DeviceType device_type) const;
Function DescriptionGet the name list of devices of the specified type in the device manager.
Parameter DescriptionInput parameter:
device_type: The device type to get the name list for.
Return ValueReturns a string vector containing device names of the specified type.
RemarksThis function is used to get the name list of devices of the specified type in the device manager.

get_device_list ​

Function Prototypestd::vector<std::shared_ptr<Device>> get_device_list(DeviceType device_type) const;
Function DescriptionGet the list of devices of the specified type in the device manager.
Parameter DescriptionInput parameter:
device_type: The device type to get the list for.
Return ValueReturns a shared pointer vector containing device objects of the specified type.
RemarksThis function is used to get the list of devices of the specified type in the device manager.

get_device ​

Function Prototypestd::shared_ptr<Device> get_device(DeviceType device_type, const std::string& device_name) const;
Function DescriptionGet the device object with the specified type and name from the device manager.
Parameter DescriptionInput parameters:
device_type: The device type.
device_name: The device name to get.
Return ValueReturns a shared pointer to the device with the specified type and name. Returns nullptr if the device does not exist.
RemarksThis function is used to get the device object with the specified type and name from the device manager.

AnalogIO Class ​

This class is the abstraction of analog IO devices.

Class Definition ​

class AnalogIO : public Device {
public:
    AnalogIO(const std::string& name);
    virtual ~AnalogIO() = default;


    virtual void set_output(int channel, double value) = 0;
    virtual void set_outputs(const std::vector<int>& channels, const std::vector<double>& values) = 0;
    virtual double get_input(int channel) = 0;
    virtual std::vector<double> get_inputs(const std::vector<int>& channels) = 0;
    virtual int get_channel_count() const = 0;

    // Get the measurement range of a channel
    virtual std::pair<double, double> get_range(int channel) const = 0;
};

Class Member Functions ​

Function NameFunction DescriptionClass Access Permission
AnalogIOConstructor, initializes device namepublic
~AnalogIODestructorpublic
set_outputSet the value of a single output channelpublic
set_outputsSet the values of multiple output channelspublic
get_inputGet the value of a single input channelpublic
get_inputsGet the values of multiple input channelspublic
get_channel_countGet the channel countpublic
get_rangeGet the measurement range of a specified channelpublic

Class Member Variables ​

Variable NameVariable DescriptionClass Access Permission

AnalogIO Class Usage Flowchart ​

AnalogIO class usage flowchart showing get/set operations on analog channels

Member Function Detailed Reference ​

AnalogIO ​

Function PrototypeAnalogIO(const std::string& name);
Function DescriptionConstructor, used to initialize the AnalogIO object.
Parameter DescriptionInput parameter:
name: Device name, used to identify the device.
Return ValueNone
RemarksThis constructor is used to create an AnalogIO object and initialize its device type and name.

~AnalogIO ​

Function Prototypevirtual ~AnalogIO() = default;
Function DescriptionDestructor, used to destroy the Device object.
Parameter DescriptionNone
Return ValueNone
RemarksThis destructor is virtual, ensuring proper destruction of derived classes.

set_output ​

Function Prototypevoid set_output(int channel, double value);
Function DescriptionSet the analog output value of the specified channel.
Parameter DescriptionInput parameter
channel: The analog output channel number.
value: The analog output value to set.
Return ValueNone
RemarksThis is a pure virtual function, used to set the analog output value of the specified channel.

set_outputs ​

Function Prototypevoid set_outputs(const std::vector<int>& channels, const std::vector<double>& values);
Function DescriptionSet the analog output values of multiple channels.
Parameter DescriptionInput parameter
channels: A vector containing the analog output channel numbers to set.
values: A vector of analog output values corresponding to the channels vector.
Return ValueNone
RemarksThis is a pure virtual function, used to set the analog output values of multiple channels.

get_input ​

Function Prototypedouble get_input(int channel);
Function DescriptionGet the analog input value of the specified channel.
Parameter DescriptionInput parameter
channel: The analog input channel number.
Return ValueReturns a double value, representing the analog input value of the specified channel.
RemarksThis is a pure virtual function, used to get the analog input value of the specified channel.

get_inputs ​

Function Prototypestd::vector<double> get_inputs(const std::vector<int>& channels);
Function DescriptionGet the analog input values of multiple channels.
Parameter DescriptionInput parameter
channels: A vector containing the analog input channel numbers to get.
Return ValueReturns a std::vector<double> value, containing a vector of analog input values for the specified channels.
RemarksThis is a pure virtual function, used to get the analog input values of multiple channels.

get_channel_count ​

Function Prototypeint get_channel_count() const;
Function DescriptionGet the total channel count of the analog I/O device.
Parameter DescriptionNone
Return ValueReturns an int value, representing the total channel count of the analog I/O device.
RemarksThis is a pure virtual function, used to get the total channel count of the analog I/O device.

get_range ​

Function Prototypestd::pair<double, double> get_range(int channel) const;
Function DescriptionGet the measurement range of the specified channel.
Parameter DescriptionInput parameter:
channel: The analog I/O channel number.
Return ValueReturns a std::pair<double, double> value, representing the measurement range (minimum and maximum values) of the specified channel.
RemarksThis is a pure virtual function, used to get the measurement range of the specified channel.

CANDevice Class ​

This class is the abstraction of CAN devices.

Class Definition ​

class CANDevice : public Device {
public:
    CANDevice(const std::string& name);
    virtual ~CANDevice() = default;
    virtual void open(int channel) = 0;
    virtual void close(int channel) = 0;
    virtual void set_parameters(int channel, int baudrate) = 0;
    virtual void set_recv_filter_id(int channel, bool enable_recv_filter, unsigned int recv_filter_id) = 0;
    virtual void set_frame_format(int channel, Frame_Format format) = 0;
    virtual bool detect_supported_function(int channel, Support_Function function) const = 0;
    virtual void send(int channel, unsigned int txid, const unsigned char buff[8], unsigned int len, bool use_remote_frame = false) = 0;
    virtual unsigned int receive(int channel, unsigned int & rxid, unsigned char buff[16]) = 0;
    virtual int get_channel_count() const = 0;
};

Class Member Functions ​

Function NameFunction DescriptionClass Access Permission
CANDeviceConstructor, initializes device namepublic
~CANDeviceDestructorpublic
openOpen the specified channelpublic
closeClose the specified channelpublic
set_parametersSet parameters for the specified channel, mainly baud ratepublic
set_recv_filter_idSet receive filter IDpublic
set_frame_formatSet data frame formatpublic
detect_supported_functionDetect if the specified channel supports a certain functionpublic
sendSend data framepublic
receiveReceive data framepublic
get_channel_countGet the channel count of the devicepublic

Class Member Variables ​

Variable NameVariable DescriptionClass Access Permission

CANDevice Class Usage Flowchart ​

CANDevice class usage flowchart showing the open, set parameters, send, and receive workflow

Member Function Detailed Reference ​

CANDevice ​

Function PrototypeCANDevice(const std::string& name);
Function DescriptionConstructor, used to initialize the CANDevice object.
Parameter DescriptionInput parameter:
name: Device name, used to identify the device.
Return ValueNone
RemarksThis constructor is used to create a CANDevice object and initialize its device type and name.

~CANDevice ​

Function Prototypevirtual ~CANDevice() = default;
Function DescriptionDestructor, used to destroy the CANDevice object.
Parameter DescriptionNone
Return ValueNone
RemarksThis destructor is virtual, ensuring proper destruction of derived classes.

open ​

Function Prototypevoid open(int channel);
Function DescriptionOpen the CAN device on the specified channel.
Parameter DescriptionInput parameter:
channel: Specifies the CAN device channel number to open.
Return ValueNone
RemarksThis is a pure virtual function that must be implemented in derived classes. The CAN device must be opened before subsequent communication operations can be performed.

close ​

Function Prototypevoid close(int channel);
Function DescriptionClose the CAN device on the specified channel.
Parameter DescriptionInput parameter:
channel: Specifies the CAN device channel number to close.
Return ValueNone
RemarksThis is a pure virtual function that must be implemented in derived classes. Closing the CAN device releases related resources.

set_parameters ​

Function Prototypevoid set_parameters(int channel, int baudrate);
Function DescriptionSet the baud rate of the CAN device on the specified channel.
Parameter DescriptionInput parameters:
channel: Specifies the CAN device channel number to set the baud rate for.
baudrate: The baud rate value to set.
Return ValueNone
RemarksThis is a pure virtual function that must be implemented in derived classes. Setting the baud rate ensures consistent communication speed between CAN devices.

set_recv_filter_id ​

Function Prototypevoid set_recv_filter_id(int channel, bool enable_recv_filter, unsigned int recv_filter_id);
Function DescriptionSet the receive filter ID of the CAN device on the specified channel.
Parameter DescriptionInput parameters:
channel: Specifies the CAN device channel number to set the receive filter ID for.
enable_recv_filter: Whether to enable the receive filter.
recv_filter_id: The receive filter ID value to set.
Return ValueNone
RemarksThis is a pure virtual function that must be implemented in derived classes. Setting the receive filter ID can filter out unwanted CAN messages.

set_frame_format ​

Function Prototypevoid set_frame_format(int channel, Frame_Format format);
Function DescriptionSet the frame format of the CAN device on the specified channel.
Parameter DescriptionInput parameters:
channel: Specifies the CAN device channel number to set the frame format for.
format: The frame format type to set.
Return ValueNone
RemarksThis is a pure virtual function that must be implemented in derived classes. Setting the frame format ensures consistent message format between CAN devices.

detect_supported_function ​

Function Prototypebool detect_supported_function(int channel, Support_Function function) const;
Function DescriptionDetect if the CAN device on the specified channel supports the specified function.
Parameter DescriptionInput parameters:
channel: Specifies the CAN device channel number to detect the function for.
function: The function type to detect.
Return ValueReturns a bool value; true indicates the function is supported, false indicates not supported.
RemarksThis is a pure virtual function that must be implemented in derived classes. Detecting functionality ensures the CAN device supports the function before use.

send ​

Function Prototypevoid send(int channel, unsigned int txid, const unsigned char buff[8], unsigned int len, bool use_remote_frame = false);
Function DescriptionSend a CAN message on the specified channel.
Parameter DescriptionInput parameters:
channel: Specifies the CAN device channel number to send the message on.
txid: The ID of the message to send.
buff: The data buffer for the message to send.
len: The data length of the message to send.
use_remote_frame: Whether to send a remote frame, default is false.
Return ValueNone
RemarksThis is a pure virtual function that must be implemented in derived classes. Sending messages is one of the basic CAN communication operations.

receive ​

Function Prototypeunsigned int receive(int channel, unsigned int & rxid, unsigned char buff[16]);
Function DescriptionReceive a CAN message on the specified channel.
Parameter DescriptionInput parameter:
channel: Specifies the CAN device channel number to receive the message on.
Output parameters
rxid: The ID of the received message.
buff: The data buffer for the received message.
Return ValueReturns an unsigned int value, representing the length of the received message.
RemarksThis is a pure virtual function that must be implemented in derived classes. Receiving messages is one of the basic CAN communication operations.

get_channel_count ​

Function Prototypeint get_channel_count() const;
Function DescriptionGet the channel count of the CAN device.
Parameter DescriptionNone
Return ValueReturns an int value, representing the channel count of the CAN device.
RemarksThis is a pure virtual function that must be implemented in derived classes. Getting the channel count provides information about the CAN device's hardware configuration.

DigitalIO Class ​

This class is the abstraction of digital IO.

Class Definition ​

class DigitalIO : public Device {
public:
    DigitalIO(const std::string& name);
    virtual ~DigitalIO() = default;


    virtual void set_output(int channel, bool state) = 0;
    virtual void set_outputs(const std::vector<int>& channels, const std::vector<bool>& states) = 0;
    virtual bool get_input(int channel) = 0;
    virtual std::vector<bool> get_inputs(const std::vector<int>& channels) = 0;
    virtual int get_channel_count() const = 0;
};

Class Member Functions ​

Function NameFunction DescriptionClass Access Permission
DigitalIOConstructor, initializes device namepublic
~DigitalIODestructorpublic
set_outputSet the output state of the specified channelpublic
set_outputsSet the output states of multiple channelspublic
get_inputGet the input state of the specified channelpublic
get_inputsGet the input states of multiple channelspublic
get_channel_countGet the channel count of the devicepublic

Class Member Variables ​

Variable NameVariable DescriptionClass Access Permission

DigitalIO Class Usage Flowchart ​

DigitalIO class usage flowchart showing batch and single channel read/write operations

Member Function Detailed Reference ​

DigitalIO ​

Function PrototypeDigitalIO(const std::string& name);
Function DescriptionConstructor, used to initialize the DigitalIO object.
Parameter DescriptionInput parameter:
name: Device name, used to identify the device.
Return ValueNone
RemarksThis constructor is used to create a DigitalIO object and initialize its device type and name.

~DigitalIO ​

Function Prototypevirtual ~DigitalIO() = default;
Function DescriptionDestructor, used to destroy the DigitalIO object.
Parameter DescriptionNone
Return ValueNone
RemarksThis destructor is virtual, ensuring proper destruction of derived classes.

set_output ​

Function Prototypevoid set_output(int channel, bool state);
Function DescriptionSet the output state of the specified digital IO channel.
Parameter DescriptionInput parameter
channel: Specifies the digital IO channel number to set.
state: Specifies the output state of the digital IO channel; true indicates high level, false indicates low level.
Return ValueNone
RemarksThis function is a pure virtual function that must be implemented in derived classes, used to set the output state of the specified digital IO channel.

set_outputs ​

Function Prototypevoid set_outputs(const std::vector<int>& channels, const std::vector<bool>& states);
Function DescriptionBatch set the output states of digital IO channels.
Parameter DescriptionInput parameter
channels: A vector containing the digital IO channel numbers to set.
states: A vector containing the output states of each digital IO channel; true indicates high level, false indicates low level.
Return ValueNone
RemarksThis function is a pure virtual function that must be implemented in derived classes, used to batch set the output states of digital IO channels.

get_input ​

Function Prototypebool get_input(int channel);
Function DescriptionGet the input state of the specified digital IO channel.
Parameter DescriptionInput parameter
channel: Specifies the digital IO channel number to get.
Return ValueReturns a bool value; true indicates high level, false indicates low level.
RemarksThis function is a pure virtual function that must be implemented in derived classes, used to get the input state of the specified digital IO channel.

get_inputs ​

Function Prototypestd::vector<bool> get_inputs(const std::vector<int>& channels);
Function DescriptionBatch get the input states of digital IO channels.
Parameter DescriptionInput parameter
channels: A vector containing the digital IO channel numbers to get.
Return ValueReturns a std::vector<bool> value; each element in the vector represents the input state of the corresponding digital IO channel; true indicates high level, false indicates low level.
RemarksThis function is a pure virtual function that must be implemented in derived classes, used to batch get the input states of digital IO channels.

get_channel_count ​

Function Prototypeint get_channel_count() const;
Function DescriptionGet the total number of digital IO channels.
Parameter DescriptionNone
Return ValueReturns an int value, representing the total number of digital IO channels.
RemarksThis function is a pure virtual function that must be implemented in derived classes, used to get the total number of digital IO channels.

EncoderDevice Class ​

This class is the abstraction of encoder devices.

Class Definition ​

class EncoderDevice : public Device {
public:
    EncoderDevice(const std::string& name);
    virtual ~EncoderDevice() = default;


    virtual int64_t get_encoder_value() const = 0;
    virtual std::pair<int64_t, int64_t> get_encoder_range() const = 0;
    virtual int get_encoder_direction() const = 0;  // 1: forward rotation -1: reverse rotation
};

Class Member Functions ​

Function NameFunction DescriptionClass Access Permission
EncoderDeviceConstructor, initializes device namepublic
~EncoderDeviceDestructorpublic
get_encoder_valueGet the current encoder valuepublic
get_encoder_rangeGet the encoder value rangepublic
get_encoder_directionGet the encoder rotation directionpublic

Class Member Variables ​

Variable NameVariable DescriptionClass Access Permission

EncoderDevice Class Usage Flowchart ​

EncoderDevice class usage flowchart showing value, range, and direction queries

Member Function Detailed Reference ​

EncoderDevice ​

Function PrototypeEncoderDevice(const std::string& name);
Function DescriptionConstructor, used to initialize the EncoderDevice object.
Parameter DescriptionInput parameter
name: Device name, used to identify the device.
Return ValueNone
RemarksThis constructor is used to create an EncoderDevice object and initialize its device type and name.

~EncoderDevice ​

Function Prototypevirtual ~EncoderDevice() = default;
Function DescriptionDestructor, used to destroy the EncoderDevice object.
Parameter DescriptionNone
Return ValueNone
RemarksThis destructor is virtual, ensuring proper destruction of derived classes.

get_encoder_value ​

Function Prototypevirtual int64_t EncoderDevice::get_encoder_value() const;
Function DescriptionGet the encoder value.
Parameter DescriptionNone
Return ValueReturns an int64_t value, representing the current encoder value.
RemarksThis is a pure virtual function that must be implemented in derived classes.

get_encoder_range ​

Function Prototypevirtual std::pair<int64_t, int64_t> EncoderDevice::get_encoder_range() const;
Function DescriptionGet the encoder range.
Parameter DescriptionNone
Return ValueReturns a std::pair<int64_t, int64_t> value; the first element of the pair represents the encoder's minimum value, and the second element represents the encoder's maximum value.
RemarksThis is a pure virtual function that must be implemented in derived classes.

get_encoder_direction ​

Function Prototypevirtual int EncoderDevice::get_encoder_direction() const;
Function DescriptionGet the encoder direction.
Parameter DescriptionNone
Return ValueReturns an int value; 1 indicates forward rotation, -1 indicates reverse rotation.
RemarksThis is a pure virtual function that must be implemented in derived classes. This function is used to get the encoder's rotation direction.

PwmDevice Class ​

This class is the abstraction of PWM devices.

Class Definition ​

class PwmDevice : public Device {
public:
    PwmDevice(const std::string& name);
    virtual ~PwmDevice() = default;


    virtual void start_pwm() = 0;
    virtual void stop_pwm() = 0;
    virtual void set_freq(double freq) = 0;
    virtual void set_duty(double duty) = 0;
    virtual double get_freq() const = 0;
    virtual double get_duty() const = 0;
};

Class Member Functions ​

Function NameFunction DescriptionClass Access Permission
PwmDeviceConstructor, initializes device namepublic
~PwmDeviceDestructorpublic
start_pwmStart PWM outputpublic
stop_pwmStop PWM outputpublic
set_freqSet PWM output frequencypublic
set_dutySet PWM output duty cyclepublic
get_freqGet PWM output frequencypublic
get_dutyGet PWM output duty cyclepublic

Class Member Variables ​

Variable NameVariable DescriptionClass Access Permission

PwmDevice Class Usage Flowchart ​

PwmDevice class usage flowchart showing start, stop, frequency, and duty cycle operations

Member Function Detailed Reference ​

PwmDevice ​

Function PrototypePwmDevice(const std::string& name);
Function DescriptionConstructor, used to initialize the PwmDevice object.
Parameter DescriptionInput parameter:
name: Device name, used to identify the device.
Return ValueNone
RemarksThis constructor is used to create a PwmDevice object and initialize its device type and name.

~PwmDevice ​

Function Prototypevirtual ~PwmDevice() = default;
Function DescriptionDestructor, used to destroy the PwmDevice object.
Parameter DescriptionNone
Return ValueNone
RemarksThis destructor is virtual, ensuring proper destruction of derived classes.

start_pwm ​

Function Prototypevoid start_pwm();
Function DescriptionStart the PWM (Pulse Width Modulation) device.
Parameter DescriptionNone
Return ValueNone
RemarksThis function is a pure virtual function that must be implemented in derived classes. Used to start the PWM device.

stop_pwm ​

Function Prototypevoid stop_pwm();
Function DescriptionStop the PWM (Pulse Width Modulation) device.
Parameter DescriptionNone
Return ValueNone
RemarksThis function is a pure virtual function that must be implemented in derived classes. Used to stop the PWM device.

set_freq ​

Function Prototypevoid set_freq(double freq);
Function DescriptionSet the frequency of the PWM (Pulse Width Modulation) device.
Parameter DescriptionInput parameter:
freq: The PWM frequency value to set.
Return ValueNone
RemarksThis function is a pure virtual function that must be implemented in derived classes. Used to set the frequency of the PWM device.

set_duty ​

Function Prototypevoid set_duty(double duty);
Function DescriptionSet the duty cycle of the PWM (Pulse Width Modulation) device.
Parameter DescriptionInput parameter:
duty: The PWM duty cycle value to set.
Return ValueNone
RemarksThis function is a pure virtual function that must be implemented in derived classes. Used to set the duty cycle of the PWM device.

get_freq ​

Function Prototypedouble get_freq() const;
Function DescriptionGet the current frequency of the PWM (Pulse Width Modulation) device.
Parameter DescriptionNone
Return ValueReturns a double value, representing the current frequency of the PWM device.
RemarksThis function is a pure virtual function that must be implemented in derived classes. Used to get the current frequency of the PWM device.

get_duty ​

Function Prototypedouble get_duty() const;
Function DescriptionGet the current duty cycle of the PWM (Pulse Width Modulation) device.
Parameter DescriptionNone
Return ValueReturns a double value, representing the current duty cycle of the PWM device.
RemarksThis function is a pure virtual function that must be implemented in derived classes. Used to get the current duty cycle of the PWM device.

SerialDevice Class ​

This class is the abstraction of serial devices.

Class Definition ​

class SerialDevice : public Device { // Remove ": public Device" if not needed
public:
    SerialDevice(const std::string& name);
    virtual ~SerialDevice() = default;
    virtual void open(int channel) = 0;
    virtual void close(int channel) = 0;
    virtual void set_parameters(int channel, int baudrate, char parity, int stop_bits) = 0;
    virtual int send(int channel, const std::vector<char>& data, size_t bytes_to_send) = 0;
    virtual int receive(int channel, std::vector<char>& buffer, size_t& bytes_received) = 0;
    virtual int get_channel_count() const = 0;
};

SerialDevice Class Usage Flowchart ​

SerialDevice class usage flowchart showing open, configure, send, and receive operations

Member Function Detailed Reference ​

SerialDevice ​

Function PrototypeSerialDevice(const std::string& name);
Function DescriptionConstructor, used to initialize the SerialDevice object.
Parameter DescriptionInput parameter:
name: Device name, used to identify the device.
Return ValueNone
RemarksThis constructor is used to create a SerialDevice object and initialize its device type and name.

~SerialDevice ​

Function Prototypevirtual ~SerialDevice() = default;
Function DescriptionDestructor, used to destroy the CANDevice object.
Parameter DescriptionNone
Return ValueNone
RemarksThis destructor is virtual, ensuring proper destruction of derived classes.

open ​

Function Prototypevoid open(int channel);
Function DescriptionOpen the Serial device on the specified channel.
Parameter DescriptionInput parameter:
channel: Specifies the Serial device channel number to open.
Return ValueNone
RemarksThis is a pure virtual function that must be implemented in derived classes. The device must be opened before subsequent communication operations can be performed.

close ​

Function Prototypevoid close(int channel);
Function DescriptionClose the Serial device on the specified channel.
Parameter DescriptionInput parameter:
channel: Specifies the Serial device channel number to close.
Return ValueNone
RemarksThis is a pure virtual function that must be implemented in derived classes. Closing the device releases related resources.

set_parameters ​

Function Prototypevoid set_parameters(int channel, int baudrate, char parity, int stop_bits) ;
Function DescriptionSet the baud rate, parity bit, and stop bits of the Serial device on the specified channel.
Parameter DescriptionInput parameters:
channel: Specifies the Serial device channel number to set the baud rate for.
baudrate: The baud rate value to set.
parity: Specifies the parity bit type; "N" for no parity, "E" for even parity, "O" for odd parity
stop_bits: Stop bits
Return ValueNone
Remarks

send ​

Function Prototypeint send(int channel, const std::vector<char>& data, size_t bytes_to_send);
Function DescriptionSend a Serial message on the specified channel.
Parameter DescriptionInput parameters:
channel: Specifies the device channel number to send the message on.
data: The data to send.
bytes_to_send: The data length of the message to send.
Return ValueNone
RemarksNone

receive ​

Function Prototypeint receive(int channel, std::vector<char>& buffer, size_t& bytes_received);
Function DescriptionReceive a Serial message on the specified channel.
Parameter DescriptionInput parameter:
channel: Specifies the device channel number to receive the message on.
Output parameter
buffer: Buffer for the received message
bytes_received: Length of the received message
Return ValueReturns an unsigned int value, representing the length of the received message.
RemarksNone

get_channel_count ​

Function Prototypeint get_channel_count() const;
Function DescriptionGet the channel count of the Serial device.
Parameter DescriptionNone
Return ValueReturns an int value, representing the channel count of the Serial device.
RemarksThis is a pure virtual function that must be implemented in derived classes. Getting the channel count provides information about the Serial device's hardware configuration.

UpsDevice Class ​

This class is the abstraction of UPS devices.

Class Definition ​

class UpsDevice : public Device {
public:
    UpsDevice(const std::string& name);
    virtual ~UpsDevice() = default;


    virtual bool get_ups_status() const = 0;  // true: triggered false: not triggered
};

Class Member Functions ​

Function NameFunction DescriptionClass Access Permission
UpsDeviceConstructor, initializes device namepublic
~UpsDeviceDestructorpublic
get_ups_statusGet UPS status, returns trigger state (true: triggered, false: not triggered)public

Class Member Variables ​

Variable NameVariable DescriptionClass Access Permission

UpsDevice Class Usage Flowchart ​

UpsDevice class usage flowchart showing the status query path

Member Function Detailed Reference ​

UpsDevice ​

Function PrototypeUpsDevice(const std::string& name);
Function DescriptionConstructor, used to initialize the UpsDevice object.
Parameter DescriptionInput parameter:
name: Device name, used to identify the device.
Return ValueNone
RemarksThis constructor is used to create an UpsDevice object and initialize its device type and name.

~UpsDevice ​

Function Prototypevirtual ~UpsDevice() = default;
Function DescriptionDestructor, used to destroy the UpsDevice object.
Parameter DescriptionNone
Return ValueNone
RemarksThis destructor is virtual, ensuring proper destruction of derived classes.

get_ups_status ​

Function Prototypevirtual bool get_ups_status() const = 0;
Function DescriptionGet the status of the UPS device.
Parameter DescriptionNone
Return ValueReturns a bool value; true indicates triggered, false indicates not triggered.
RemarksThis is a pure virtual function that must be implemented in derived classes. This function is used to get the status of the UPS device.
🤖 AI assistants / automation: start with the Agent Development Guide and Pre-generation Checklist (Chinese); machine-readable entry: /llms.txt; plain-text version: swap .html for .md in the URL