C#

This topic introduces how to build the Mech-Eye API C# samples with Visual Studio on Windows.

Sample List

The following samples are currently provided:

  • TriggerWithSoftwareAndFixedRate: Trigger data acquisition with the software + fixed rate method, and then retrieve and save the acquired data.

  • TriggerWithExternalDeviceAndFixedRate: Trigger data acquisition with the external + fixed rate method, and then retrieve and save the acquired data.

  • TriggerWithSoftwareAndEncoder: Trigger data acquisition with the software + encoder method, and then retrieve and save the acquired data.

  • TriggerWithExternalDeviceAndEncoder: Trigger data acquisition with the external + encoder method, and then retrieve and save the acquired data.

  • TriggerMultipleProfilersSimultaneously: Trigger multiple laser profilers to acquire data asynchronously, and then retrieve and save the acquired data.

  • ManageUserSets: Manage parameter groups, such as obtaining the names of all parameter groups, adding a parameter group, switching the parameter group, and saving parameter settings to the parameter group.

  • RegisterProfilerEvent: Define and register the callback function for monitoring the laser profiler connection status.

  • UseVirtualDevice: Acquire the profile data stored in a virtual device, generate the intensity image and depth map, and save the images.

For different methods of triggering the laser profiler to acquire data, refer to Methods for Triggering Data Acquisition.

Prerequisites

In order to use the C# samples of Mech-Eye API, the following prerequisites must be satisfied:

Obtain Samples

C# samples are included in the installation path of Mech-Eye SDK or can be obtained from GitHub by cloning. The samples in the installation path are the version at the time of Mech-Eye SDK release. The version on GitHub may contain the latest changes.

  • The samples in the installation path are located in xxx/Mech-Eye SDK-2.3.2/API/samples/csharp/profiler.

  • The samples cloned from GitHub are located in xxx/mecheye_csharp_samples/profiler.

Install Required Software

In order to use the C# samples of Mech-Eye API, Mech-Eye SDK and Visual Studio must be installed.

Install the Latest Version of Mech-Eye SDK

Please install or upgrade Mech-Eye SDK according to Mech-Eye SDK Installation Guide.

Install Visual Studio (Version 2019 or Above)

  1. Download the Visual Studio installer.

  2. When installing, select the following workloads and individual component, and then click Install.

    • Workloads in the Desktop & Mobile category:

      • .NET desktop development

      • Desktop development with C++

      • Universal Windows Platform development

    • Individual component: .NET Framework 4.8 targeting pack

C# Mech-Eye API is developed based on .NET Framework 4.8. If .NET Framework 4.8 is not installed, the samples cannot be built.

Install Emgu CV

Some samples contain functions that depend on the OpenCV software libraries. If you need to use the samples listed below, you must install Emgu CV (the .NET wrapper for OpenCV) through NuGet Package Manager in Visual Studio.

For detailed instructions, refer to the guide provided by Microsoft.

  • TriggerWithSoftwareAndFixedRate

  • TriggerWithExternalDeviceAndFixedRate

  • TriggerWithSoftwareAndEncoder

  • TriggerWithExternalDeviceAndEncoder

  • TriggerMultipleProfilersSimultaneously

  • UseVirtualDevice

Build and Run Samples

After building the samples in Visual Studio, select the appropriate way to run the samples.

Build Samples in Visual Studio

  1. Double-click MechEyeCSharpSamples.sln in the profiler folder.

  2. In Visual Studio toolbar, change the solution configuration from Debug to Release.

  3. In the menu bar, select Build  Build Solution. An executable file (.exe) is generated for each sample. The executable files are saved to the Build folder, located in the profiler folder.

Run Samples

You can run the samples in Visual Studio after building them, or run the samples by double-clicking the executable files.

Run a Sample in Visual Studio

  1. In the Solution Explorer panel, right-click a sample, and select Set as Startup Project.

  2. Click Local Windows Debugger in the toolbar to run the sample.

    While the sample is running, input the index of the laser profiler to which you want to connect according to the instruction, and press Enter to connect to the laser profiler.

  3. If image and/or point cloud files are saved by the sample, you can find the files in the Build folder.

Run the Executable File of a Sample

  1. Enter the Build folder in the profiler folder.

  2. Run the executable file with the same name as the sample.

    While the sample is running, input the index of the laser profiler to which you want to connect according to the instruction, and press Enter to connect to the laser profiler.

  3. If image and/or point cloud files are saved by the sample, you can find the files in the Build folder.