C# (Windows) CAN Bus Examples

Complete C# Windows code examples for UIROBOT products — CAN bus control via UirSDK3 for UIM342 motors and UIM1616 I/O modules. Supports UIM2513 serial and UIM2523 Ethernet gateways.

# C# Windows CAN Bus Examples This page provides **C# Windows** example projects for controlling UIROBOT products using the **UirSDK3** and **CAN30SDK** libraries. These demonstrations support both serial (UIM2513) and Ethernet (UIM2523) gateway connections. --- ## Quick Selection | Connection Method | Compatible Products | Docs | |-----------------|-------------------|------| | **C# SDK (32-bit) → CAN Bus** | UIM342 (multi-axis) | [AN250928] | | **C# SDK (64-bit) → CAN Bus** | UIM342 (multi-axis) | [AN250929] | | **C# SDK (32-bit) → CAN Bus** | UIM1616 I/O module | [AN251031] | | **C# SDK (64-bit) → CAN Bus** | UIM1616 I/O module | [AN251112] | --- ## Background The C# demonstration programs use **UirSDK3** and **CAN30SDK** to control UIROBOT devices via CAN bus networks. These projects demonstrate how to control UIM342 motors and UIM1616 I/O modules through UIM2513 (serial) or UIM2523 (Ethernet) gateways. ### Key Features - Supports both serial (UIM2513) and Ethernet (UIM2523) communication - Multi-axis synchronous motion control (UIM342) - Real-time status monitoring and feedback - Sensor-triggered homing functionality (UIM342) - Complete error handling mechanism --- ## Required Hardware | Item | Qty | Description | |------|:---:|-------------| | UIM342 Series Motor | 1+ | CAN bus smart motor (for AN250928/AN250929) | | UIM1616 Module | 1 | CAN bus I/O module (for AN251031/AN251112) | | UIM2513 Gateway | 1 | RS232-to-CAN gateway (serial mode) | | UIM2523 Gateway | 1 | Ethernet-to-CAN gateway (IP: 192.168.1.254) | | MMC904 | 1 | Mini-PC (IP: 192.168.1.16, optional) | | 24V DC Power Supply | 1 | For motors, gateways, and I/O modules | | Windows PC | 1 | For development (Visual Studio) | --- ## Wiring ``` Windows PC (Visual Studio C#) +-----------------------------------+ | UirSDK3 + CAN30SDK | | - UIM2513 (Serial COM) | | - UIM2523 (Ethernet 192.168.1.x) | +-------++---------------++---------+ || || Serial|| Ethernet || || +-------v--------+ +----v----------+ | UIM2513 | | UIM2523 | | RS232-to-CAN | | Ethernet-to-CAN| | Serial Gateway | | (192.168.1.254)| +-------+-------+ +-------+--------+ | | +---------+---------+ | CAN Bus (twisted pair) | +-------v--------+ | UIM342 Motor | | or UIM1616 I/O | +-----------------+ ``` --- ## Software Installation ### Step 1 — Install Visual Studio 1. Visit: [visualstudio.microsoft.com](https://visualstudio.microsoft.com/) 2. Download and install **Visual Studio** (Community edition is free) 3. During installation, select **.NET desktop development** workload ### Step 2 — Download Sample Code | Application Note | Download | |-----------------|----------| | AN250928 — UIM342 32-bit | [Download ZIP](https://www.uirobot.com/uploads/files/Win32_C%23_libUirSdkWin32_UIM342_AN250928.zip) | | AN250929 — UIM342 64-bit | [Download ZIP](https://www.uirobot.com/uploads/files/83be717bbdca18680064accc0c34ca87.zip) | | AN251031 — UIM1616 32-bit | [Download ZIP](https://www.uirobot.com/uploads/files/Win32_C%23_libUirSdkWin32_UIM1616_AN251031.zip) | | AN251112 — UIM1616 64-bit | [Download ZIP](https://www.uirobot.com/uploads/files/Win64_C%23_libUirSdkWin64_UIM1616_AN251112.zip) | --- ## Section 1: UIM342 Motor Control (AN250928 / AN250929) ### Open the Project 1. Unzip the downloaded ZIP file 2. Open the Visual Studio solution (`.sln`) file: - 32-bit: `Win32_C#_libUirSdkWin32_UIM342.sln` - 64-bit: `Win64_C#_libUirSdkWin64_UIM342.sln` ### Compile 1. In Visual Studio, select the appropriate platform (x86 for 32-bit, x64 for 64-bit) 2. Click **Build → Build Solution** (or press Ctrl+Shift+B) 3. After successful compilation, the required DLL files are automatically copied to the output directory ### Run 1. Ensure gateway devices are properly connected 2. Check network configuration (IP address / serial port) 3. Run the executable from Visual Studio (F5) or from the output folder ### Select Gateway Type The program supports multiple gateway types. Select the appropriate one during runtime: - **UIM2513**: RS232 serial connection - **UIM2523**: Ethernet connection (IP: 192.168.1.254) - **MMC904**: Embedded controller connection (IP: 192.168.1.16) --- ## Section 2: UIM1616 I/O Module Control (AN251031 / AN251112) ### Open the Project 1. Unzip the downloaded ZIP file 2. Open the Visual Studio solution (`.sln`) file: - 32-bit: `Win32_C#_libUirSdkWin32_UIM1616.sln` - 64-bit: `Win64_C#_libUirSdkWin64_UIM1616.sln` ### Compile 1. Select the appropriate platform (x86 for 32-bit, x64 for 64-bit) 2. **Build → Build Solution** 3. DLL files are automatically copied to the output directory ### Run 1. Ensure gateway devices are properly connected 2. Check network configuration (IP address / serial port) 3. Confirm UIM1616 Module ID is set correctly 4. Run the executable ### Select Gateway Type Same as UIM342 — select UIM2513 (serial) or UIM2523 (Ethernet) during runtime. --- ## Step-by-Step Setup ### Step 1 — Connect Hardware 1. Connect the gateway (UIM2513 or UIM2523) to your PC and CAN bus network 2. Wire CANH/CANL between the gateway and target devices (UIM342 or UIM1616) 3. Connect 24V DC power supply 4. **Double-check all wiring before powering on** ### Step 2 — Install Visual Studio Install Visual Studio with **.NET desktop development** workload. ### Step 3 — Download and Open Sample Code 1. Download the appropriate ZIP file for your architecture 2. Extract and open the `.sln` file in Visual Studio ### Step 4 — Compile Build the solution. DLLs are automatically copied to the output directory. ### Step 5 — Run and Select Gateway Run the program and select the gateway type when prompted. The program will establish communication with the target device via the selected gateway. --- ## Additional Tips - **Architecture**: Choose the correct version (32-bit or 64-bit) matching your Windows OS and application requirements - **Gateway Selection**: Use UIM2513 for serial connection, UIM2523 for Ethernet connection - **Node IDs**: Ensure each device on the CAN bus has a unique Node ID - **Network**: For Ethernet mode, all devices must be on the same subnet (192.168.1.xxx) - **DLL Dependencies**: The required DLL files are automatically copied during the build process --- ## Download All Sample Codes | Application Note | Description | Download Link | |-----------------|-------------|---------------| | AN250928 | UIM342 32-bit C# control | [Download ZIP](https://www.uirobot.com/uploads/files/Win32_C%23_libUirSdkWin32_UIM342_AN250928.zip) | | AN250929 | UIM342 64-bit C# control | [Download ZIP](https://www.uirobot.com/uploads/files/83be717bbdca18680064accc0c34ca87.zip) | | AN251031 | UIM1616 32-bit C# control | [Download ZIP](https://www.uirobot.com/uploads/files/Win32_C%23_libUirSdkWin32_UIM1616_AN251031.zip) | | AN251112 | UIM1616 64-bit C# control | [Download ZIP](https://www.uirobot.com/uploads/files/Win64_C%23_libUirSdkWin64_UIM1616_AN251112.zip) | --- ## Video Tutorial :::video[UIROBOT C++ and C# Usage Guide for Visual Studio 2022](https://www.youtube.com/watch?v=yBTrlSD8ITI) ::: --- ## Related Documents - [UIROBOT Code Examples Overview](/docs/code-examples-overview) - [UIM342 CAN Bus Motor Controller](/docs/uim342) - [UIM1616 CAN Bus I/O Module](/docs/uim1616) - [UIM2513 CAN Bus Gateway](/docs/uim2513) - [UIM2523 Ethernet to CAN Gateway](/docs/uim2523) - [Quick Start Guide](/docs/quick-start) --- *Last updated: 2026-06-25 | Based on Application Notes AN250928, AN250929, AN251031, AN251112*