C/C++ driver for communicating with a Bloomy Controls Fault Insertion Units over RS-485.
Features
- Modern, native C++20 library
- Supports Windows and Linux
- Implements all commands and queries supported by the FIU
- Exceptionless error handling (see below)
- C wrapper (include/bci/fiu/CInterface.h) for use in C and other languages
- Easy inclusion in CMake projects
- Note
- Exceptions are not handled internally unless it is necessary to do so. Any exceptions thrown by this library are considered critical exceptional situations, such as a failure to allocate memory.
Example Usage (C++)
This example connects to an FIU, queries the firmware version, and then sets a single channel's state, followed by all channels at once.
#include <format>
#include <iostream>
int main(void) {
auto ret = client.
Open(
"COM4");
if (ret != ec::kSuccess) {
<< '\n';
return 1;
}
if (ret != ec::kSuccess) {
<< '\n';
return 1;
}
if (resp) {
auto [major, minor] = *resp;
std::cout << std::format("Firmware version: {:d}.{:d}\n", major, minor);
} else {
std::cerr << "Failed to get firmware version: "
return 1;
}
if (ret != ec::kSuccess) {
std::cerr << "Failed to set channel states: "
return 1;
}
if (ret != ec::kSuccess) {
std::cerr << "Failed to set all channel states: "
return 1;
}
}
Declares FIU client functionality.
Serial client for communicating with the Bloomy Controls Fault Insertion Unit (FIU).
Definition FiuClient.h:42
FIU_API Result< FirmwareVersion > GetFirmwareVersion() const
Get the firmware version loaded onto the FIU.
FIU_API ErrorCode SetAllChannelStates(ChannelState state) const
Set the state of all channels.
FIU_API ErrorCode SetChannelState(unsigned int channel, ChannelState state) const
Set the state of a channel.
FIU_API ErrorCode SetBoxID(std::uint8_t box_id) noexcept
Set the target box ID.
FIU_API ErrorCode Open(const std::string &port)
Open a serial port to connect to the FIU.
FIU_API const char * ErrorMessage(ErrorCode ec) noexcept
Get a string describing an error code.
@ kVoltageMeasurement
Voltage measurement mode.
Definition CommonTypes.h:30
@ kDisconnected
Disconnected.
Definition CommonTypes.h:28
ErrorCode
Error codes returned by the driver.
Definition CommonTypes.h:36
Example Usage (C)
This example performs the same operations as the C++ example above using the C interface.
#include <stdio.h>
static void FormatErr(const char* msg, int ec) {
}
int main(void) {
int ret = 1;
int ec;
if (ec < 0) {
FormatErr("failed to initialize client", ec);
goto cleanup;
}
if (ec < 0) {
FormatErr("failed to set box ID", ec);
goto cleanup;
}
if (ec < 0) {
FormatErr("failed to open port", ec);
goto cleanup;
}
if (ec < 0) {
FormatErr("failed to get firmware version", ec);
goto cleanup;
}
printf(
"Firmware version: %u.%u\n", fw_version.
major, fw_version.
minor);
if (ec < 0) {
FormatErr("failed to set channel state", ec);
goto cleanup;
}
if (ec < 0) {
FormatErr("failed to set all channel states", ec);
goto cleanup;
}
ret = 0;
cleanup:
return ret;
}
C-style interfaced to the library.
#define FIU_CHAN_STATE_VMEAS
Voltage measurement mode.
Definition CInterface.h:92
#define FIU_CHAN_STATE_DISCONNECTED
Channel disconnected.
Definition CInterface.h:88
void * FiuClientHandle
FIU client handle.
Definition CInterface.h:106
FIU_API int FiuClient_Open(FiuClientHandle handle, const char *port)
Open a serial connection to the FIU.
FIU_API int FiuClient_GetFirmwareVersion(FiuClientHandle handle, FiuFirmwareVersion *version_out)
Get the firmware version loaded onto the FIU.
FIU_API int FiuClient_SetChannelState(FiuClientHandle handle, unsigned int channel, uint8_t state)
Set the state of a channel.
FIU_API int FiuClient_SetBoxID(FiuClientHandle handle, uint8_t box_id)
Set the target box ID.
FIU_API const char * FiuClient_ErrorMessage(int error)
Get a message describing an error code returned by the library.
FIU_API int FiuClient_SetAllChannelStates(FiuClientHandle handle, uint8_t state)
Set the state of all channels.
FIU_API int FiuClient_Init(FiuClientHandle *handle_out)
Initialize an FIU client.
FIU_API void FiuClient_Destroy(FiuClientHandle *handle)
Destroy an FIU client.
FIU firmware version.
Definition CInterface.h:100
uint8_t major
Minor version.
Definition CInterface.h:101
uint8_t minor
Major version.
Definition CInterface.h:102
Building
To build the driver as a shared library (.DLL or .so), first configure CMake, then execute the build system. This project can also be built with Visual Studio.
cmake -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON
cmake --build build
Adding to a CMake Project
In your CMakeLists.txt, fetch and link with the driver:
FetchContent_Declare(fiu-cpp
GIT_REPOSITORY https://github.com/BloomyControls/fiu-cpp.git
GIT_TAG v1.0.0
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(fiu-cpp)
target_link_libraries(my_program PRIVATE bci::fiu)
If you have already installed the driver to a standard location on your system, you can use find_package instead:
find_package(fiu-cpp 1.0.0 REQUIRED)
target_link_libraries(my_program PRIVATE bci::fiu)
Dependencies
This library does not have any runtime dependencies aside from the standard C/C++ runtime libraries on your system. However, it does have some build dependencies. If these are installed on your system, CMake will find and use them if your installed versions are compatible. Otherwise, it will automatically fetch and build them as part of the build. The build dependencies are:
These are linked statically, regardless of the build configuration.
License
Copyright (c) 2026, Bloomy Controls, Inc. All rights reserved.
This software is distributed under the BSD-3-clause license. See the LICENSE file or https://opensource.org/license/BSD-3-Clause for details.