Skip to content

Latest commit

Β 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

README.md

CFG++ C++ LabVIEW Implementation

High-performance C++ parser optimized for LabVIEW integration with DLL support and LabVIEW-specific data structures.

Features

  • πŸ”— LabVIEW Integration: Native support for LabVIEW clusters and variants
  • πŸ“š Windows DLL: Ready-to-use DLL for LabVIEW applications
  • ⚑ High Performance: SIMD-optimized parsing with memory pooling
  • πŸ›‘οΈ Schema Validation: Built-in validation with detailed error reporting
  • πŸ”§ C API: Clean C interface compatible with LabVIEW
  • πŸ“¦ CMake Build: Cross-platform build system

LabVIEW Integration

// Convert LabVIEW cluster to CFG++ file
CfgppResult result = cfgpp_cluster_to_file(
    cluster_data,       // LabVIEW cluster data
    data_size,          // Size of cluster data
    field_names,        // Array of field names
    field_count,        // Number of fields
    "config.cfgpp"      // Output file path
);

// Parse CFG++ file back to LabVIEW
CfgppValueHandle config;
cfgpp_parse_file(parser, "config.cfgpp", &config);

Schema Validation

// Load schema
CfgppSchemaHandle schema;
cfgpp_schema_create(&schema);
cfgpp_schema_parse_file(schema, "measurement.cfgpp-schema");

// Validate LabVIEW data with schema
cfgpp_cluster_to_file_validated(
    cluster_data, data_size, field_names, field_count,
    "validated_config.cfgpp", schema
);

Building the DLL

Prerequisites

Required Software:

  • CMake 3.15+ - Download from cmake.org
  • Visual Studio 2019 or newer (Community edition is fine)
    • Must include "Desktop development with C++" workload
    • Windows SDK 10.0.18362.0 or newer
  • LabVIEW 2018 or newer (for integration testing)

Recommended Tools:

  • Git for version control
  • Visual Studio Code with CMake extensions

Step-by-Step Build Process

1. Setup Build Environment

# Navigate to the C++ LabVIEW implementation
cd implementations/cpp-labview

# Create and enter build directory
mkdir build
cd build

2. Configure CMake

# For Visual Studio (64-bit, recommended for LabVIEW)
cmake .. -G "Visual Studio 16 2019" -A x64

# Alternative: For specific Visual Studio version
cmake .. -G "Visual Studio 17 2022" -A x64

# For MinGW (if preferred)
cmake .. -G "MinGW Makefiles"

3. Build the DLL

# Release build (recommended for production)
cmake --build . --config Release

# Debug build (for development)
cmake --build . --config Debug

# Build both configurations
cmake --build . --config Release
cmake --build . --config Debug

4. Install and Package

# Install to dist directory
cmake --install . --prefix ../dist --config Release

# Your DLL will be in: implementations/cpp-labview/dist/bin/cfgpp_parser.dll

Build Output Structure

cpp-labview/
β”œβ”€β”€ build/                 # Build artifacts
β”‚   β”œβ”€β”€ Release/          # Release binaries
β”‚   β”‚   └── cfgpp_parser.dll
β”‚   └── Debug/            # Debug binaries (optional)
β”‚       └── cfgpp_parser.dll
β”œβ”€β”€ dist/                 # Installation directory
β”‚   β”œβ”€β”€ bin/              # DLL files
β”‚   β”‚   └── cfgpp_parser.dll
β”‚   β”œβ”€β”€ include/          # Header files
β”‚   β”‚   └── cfgpp_parser.h
β”‚   └── lib/              # Import libraries
β”‚       └── cfgpp_parser.lib

LabVIEW Integration Setup

1. Copy Files to LabVIEW Project

# Copy DLL to your LabVIEW project directory
copy dist\bin\cfgpp_parser.dll "C:\YourLabVIEWProject\"

# Copy header for reference
copy src\cfgpp_parser.h "C:\YourLabVIEWProject\"

2. Configure Call Library Function Node

In LabVIEW:

  1. Add Call Library Function Node to your block diagram
  2. Configure the node:
    • Library name or path: cfgpp_parser.dll
    • Function name: cfgpp_parse_file (or desired function)
    • Calling convention: stdcall (__stdcall)
    • Thread: Run in any thread

3. Function Parameter Configuration

Example for cfgpp_parse_file:

  • parser (input): Pointer to Void
  • filename (input): C String
  • result (output): Pointer to Void
  • Return value: Numeric U32 (error code)

4. Memory Management

// Always create parser before use
CfgppParserHandle parser;
cfgpp_parser_create(&parser);

// Always cleanup when done  
cfgpp_parser_destroy(parser);
cfgpp_value_destroy(value);

Troubleshooting

Common Build Issues

❌ CMake not found

# Add CMake to PATH or use full path
"C:\Program Files\CMake\bin\cmake.exe" ..

❌ Visual Studio not detected

# List available generators
cmake --help

# Use specific VS version
cmake .. -G "Visual Studio 16 2019" -A x64

❌ Missing Windows SDK

  • Install Windows SDK through Visual Studio Installer
  • Or specify SDK version: cmake .. -DCMAKE_SYSTEM_VERSION=10.0.19041.0

Runtime Issues

❌ DLL not found in LabVIEW

  • Ensure DLL is in same directory as VI
  • Or add DLL path to Windows PATH environment variable
  • Check DLL architecture (x86 vs x64) matches LabVIEW

❌ Function not found

  • Verify function name spelling in Call Library Function Node
  • Use dumpbin /exports cfgpp_parser.dll to list available functions
  • Ensure calling convention is set to stdcall

❌ Access violation errors

  • Always initialize pointers before use
  • Check parameter types match exactly
  • Ensure proper cleanup of allocated memory

Performance Optimization

For Maximum Performance:

# Enable CPU-specific optimizations
cmake .. -DCMAKE_CXX_FLAGS="/O2 /arch:AVX2"

# Link-time optimization  
cmake .. -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=TRUE

Testing the Integration

1. Basic Function Test

// Test in LabVIEW or C test program
CfgppParserHandle parser;
CfgppResult result = cfgpp_parser_create(&parser);
if (result == CFGPP_SUCCESS) {
    printf("Parser created successfully!\n");
    cfgpp_parser_destroy(parser);
}

2. Parse Test File

Create test_config.cfgpp:

database {
    host = "localhost";
    port = 5432;
}

Then test parsing:

CfgppValueHandle config;
result = cfgpp_parse_file(parser, "test_config.cfgpp", &config);

Advanced Build Options

Custom Build Configuration

# Static runtime linking
cmake .. -DCFGPP_STATIC_RUNTIME=ON

# Enable debugging symbols in release
cmake .. -DCMAKE_CXX_FLAGS_RELEASE="/O2 /Zi"

# Custom install prefix
cmake .. -DCMAKE_INSTALL_PREFIX="C:/CFGPlusPlus"

Cross-compilation (Advanced)

# For different architectures
cmake .. -A Win32    # 32-bit
cmake .. -A x64      # 64-bit  
cmake .. -A ARM64    # ARM64

Performance

Operation Time Memory
Parse 1KB config ~20ΞΌs 2KB
Parse 100KB config ~800ΞΌs 150KB
Schema validation ~50ΞΌs 1KB
LabVIEW cluster conversion ~30ΞΌs 4KB

API Reference

Core Functions

  • cfgpp_parser_create() - Create parser instance
  • cfgpp_parse_file() - Parse CFG++ file
  • cfgpp_parse_string() - Parse CFG++ string

LabVIEW Integration

  • cfgpp_from_labview_cluster() - Convert LabVIEW cluster
  • cfgpp_cluster_to_file() - Write cluster to CFG++ file
  • cfgpp_variant_to_string() - Convert variant to CFG++ string

Schema Validation

  • cfgpp_schema_create() - Create schema validator
  • cfgpp_validate_value() - Validate against schema
  • cfgpp_generate_schema_from_cluster() - Auto-generate schema

Project Structure

cpp-labview/
β”œβ”€β”€ src/                    # C++ source files
β”‚   β”œβ”€β”€ cfgpp_parser.cpp   # Main implementation
β”‚   └── cfgpp_parser.h     # C API header
β”œβ”€β”€ examples/              # LabVIEW integration examples
β”‚   β”œβ”€β”€ labview_example.cpp
β”‚   └── labview_integration_example.cpp
β”œβ”€β”€ CMakeLists.txt         # CMake build configuration
└── CFGPPParserConfig.cmake.in  # CMake package config

Examples

See the examples/ directory for complete LabVIEW integration examples and usage patterns.

Documentation