This project is a wrapper around my C++ library for the Waveshare 8 channel relay board. It is designed to be used with a Raspberry Pi. The dotnet library is written in C# and uses the C++ library in the backend to provide a simple interface for controlling the relay board. The C++ library is built as a PreBuildTask using CMake and is included in the output directory. It is not necessary to install the C++ library separately.
$ dotnet add package procsys.waveshare8chThis repository contains example code for controlling the Waveshare 8-Channel Relay module using C#. The goal of this project is to provide a simple and clear starting point for developers who want to integrate the relay module into their .NET applications.
These steps must be performed on your raspberry Pi.
Clone this repository: (optional)
git clone https://github.com/simoncahill/waveshare_8ch_relay_examples.git
cd waveshare_8ch_relay_examples/cpp
Ensure you have the tools required for building C++ libraries, or download a precompiled version from GitHub.
Compile the library for your Raspberry Pi model:
mkdir build && cd build
cmake .. -Dchannelselect_BUILD_LIBRARY=ON -Dchannelselect_RASPI5=ON
make
Install the library to your Raspberry Pi:
sudo make install
# or extract the library and copy it to your binary's install location
Download the NuGet package
dotnet add package procsys.waveshare8ch
The example code demonstrates how to initialize the relay module and control individual relays. Below is a brief overview:
RelayController class to set up communication with the relay module.TurnOnRelay(int relayNumber) or TurnOffRelay(int relayNumber) to control specific relays.using ChannelSelect;
class Program {
static void Main() {
Console.WriteLine($"Channel states: { ChannelSelect.GetChannelStates() }");
}
}
sudo on Linux).Contributions are welcome! Feel free to open issues or submit pull requests to improve the examples.
This project is licensed under the MIT License. See the LICENSE file for details.