Skip to main content

How to use GPIO library in VCSharp


this is a legacy library and thus not supported by Toradex anymore. We recommend that you use the new libraries for all Toradex modules. Please see the Toradex CE Libraries and Code Samples for up-to-date information.

This article aims to help the developer in using Toradex GPIO library in Visual C#. The following steps illustrate how to build a complete project which requires calling Toradex Win32 DLLs in Visual C#.


With the EOL of Windows Embedded Compact, we recommend using Torizon for new projects. It is possible to develop and maintain a future-proof Linux-based system using your Windows development environment with Visual Studio Code.

For information on how to work with .NET on Torizon, Toradex' Easy-to-Use Industrial Linux Platform. Please see the .NET Core Application Development on Visual Studio Code page.

Steps to follow

1. Follow this tutorial up to step 7 to create a new project in Visual C#.

2. The sequential process for this demo:

  • using System.Runtime.InteropServices; is used to provide inter-operability services in Visual C#. This is done to use the Toradex C Win32 DLLs.
  • DllImport is used to import the Toradex Win32 DLL for the project. This has to be called for every C function that will be used in the project.
  • Every C function to be used in the project has to be declared preceded by public static extern (return type)
  • For Toradex new library TdxAllLibraries.cs import all function to be used in Visual c# project.

8. Download and Install .NET Compact Framework directly to the FlashDisk of the device from here.

9. Navigate to Solution Explorer in visual studio > Right Click on Solution > Properties > Devices.

10. Uncheck "Deploy the Latest version of the .NET Compact Framework (including Service Packs)".

11. If using Toradex old library Add GpioLib.dll into project by choosing Add > Existing item.. from solution properties. If using Toradex new library Add TdxAllLibraries.cs and TdxAllLibraries.dll into project by choosing Add > Existing item..**

12. To deploy dll alongwith project executable, right click on dll > Properties and set Copy to Output Directory to Copy always. Alternatively, you can manually copy the dll to the project folder in which .exe will be deployed after step 13.

13. To build and deploy the project, follow steps 12 to 16 from here.

For more information, please refer to the MSDN document on Calling Win32 DLLs in C#

Demo application

Enter sodimm number to be used as Input or Output.

Gpio demo output configuration

Gpio demo input configuration

Download project

ProjectModule compatibilityLanguageLibrary Version
GPIOPXA / TegraC#Toradex CE Library (Old)
GPIOVFxx / iMX6C#Toradex CE Library (New)

Send Feedback!