Hardware Communications Guide
This comprehensive guide covers all methods for communicating with hardware devices in INDI drivers. Whether you’re connecting to a serial device, network equipment, USB hardware, GPIO pins, or I2C sensors, this guide will help you choose and implement the right communication method.
Quick Reference: Choosing Your Communication Method
| Communication Type | Use When | Library/API | Example Devices | Documentation |
|---|---|---|---|---|
| Serial | RS-232 or USB-Serial devices | Connection::Serial plugin | Mounts, focusers, cameras | Serial Guide |
| TCP | Network devices using TCP | Connection::TCP plugin | Network cameras, cloud mounts | TCP Guide |
| UDP | Network devices using UDP | Connection::UDP plugin | Discovery services, streaming | UDP Guide |
| I2C | I2C bus devices | Connection::I2C plugin | Temperature sensors, ADCs, displays | I2C Guide |
| USB Bulk | Direct USB control with bulk transfers | libusb | DSLR shutters, custom USB devices | USB Guide |
| HID | USB Human Interface Devices | hidapi | Filter wheels, focusers, keypads | HID Guide |
| GPIO | Raspberry Pi / Linux GPIO pins | libgpiod | Relays, switches, sensors, PWM | GPIO Guide |
| Modbus | Industrial devices (PLCs, relays, sensors) | nanomodbus (built-in) | Relay boards, automation equipment | Modbus Guide |
| Web Protocols | REST APIs, HTTP services, JSON data | cpp-httplib, nlohmann/json | Cloud devices, IoT, web APIs | Web Protocols Guide |
Communication Methods Overview
Connection Plugins
Connection plugins provide a standardized, modular framework for common communication protocols:
- Connection Plugins Overview - Introduction to the plugin framework
- Serial Connection - RS-232 and USB-Serial communication
- TCP Connection - Network devices using TCP/IP
- UDP Connection - Network devices using UDP datagrams
- I2C Connection - I2C bus devices on Linux systems
Advantages:
- Modular and reusable across drivers
- Standardized user interface
- Built-in connection management
- Configuration persistence
Direct Hardware Communication
For specialized hardware that doesn’t fit the plugin model:
- USB Communication - Direct USB bulk transfers with libusb
- HID Communication - Human Interface Devices with hidapi
- GPIO Communication - Digital I/O and PWM with libgpiod
Advantages:
- Full control over hardware interactions
- Support for specialized protocols
- Direct access to device features
- Platform-specific optimizations
Application Layer Protocols
For modern web-based devices and industrial automation equipment:
- Web Protocols - HTTP clients/servers and JSON handling
- Modbus - Industrial automation protocol (RTU and TCP)
Advantages:
- Industry-standard protocols with wide device support
- Structured data models and well-defined operations
- Built-in libraries (nanomodbus included, cpp-httplib available)
- Suitable for both consumer IoT and industrial applications
- Extensible to other protocols (WebSocket, MQTT, etc.)
Important: The TCP Connection Plugin is designed for raw binary/text communication protocols. For HTTP/REST APIs, use the Web Protocols Guide. For Modbus-enabled industrial devices, use the Modbus Guide.
Additional Resources
- Creating Custom Plugins - Build your own connection plugin
- Best Practices - Guidelines and platform considerations
- Troubleshooting - Common issues and solutions
- System Setup - Permissions, udev rules, and configuration
Getting Started
- Choose your communication method using the quick reference table above
- Read the specific guide for your chosen method
- Review the examples from actual INDI drivers
- Set up system permissions following the System Setup guide
- Refer to Best Practices for implementation guidelines
Example Drivers
For complete working examples, see:
- Serial/TCP/UDP: Most INDI drivers in the main repository
- USB:
indi-gphoto/dsusbdriver.cpp- DSLR shutter control - HID:
indi-sx/sxwheel.cpp- Starlight Xpress filter wheel - GPIO:
indi-gpio/indi_gpio.cpp- Raspberry Pi GPIO driver - I2C:
indi/libs/indibase/connectionplugins/connectioni2c.cpp- I2C plugin - Modbus:
indi/drivers/io/waveshare_modbus_relay.cpp- Modbus TCP relay control - Web Protocols:
- HTTP Client:
indi/drivers/auxiliary/ipx800v4.cpp- REST API consumer - HTTP Server:
indi/drivers/alpaca/indi_alpaca_server.cpp- REST API provider - JSON Handling:
indi/drivers/auxiliary/alto.cpp- JSON parsing examples
- HTTP Client:
Need Help?
- Review the Troubleshooting Guide for common issues
- Check the INDI API Documentation
- Visit the INDI Support Forum
- See the Driver Development Guide for general driver information