Skip to main content

Run Sample


Introduction

This document demonstrates how to use the CSVizionSDK C# SDK with practical examples. You can download the complete sample code from the official repository.


Running the Sample Project

Before building the sample, open the project's .csproj file and make sure it includes the correct references and configurations.

Verify .csproj Settings

Open the .csproj file in your sample project and confirm it has the proper setup. Here’s an example configuration:

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- Target framework version -->
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<!-- Reference the CSVizionSDK NuGet package -->
<PackageReference Include="CSVizionSDK" Version="VERSION" />
</ItemGroup>
</Project>

Replace VERSION with the correct version of the CSVizionSDK package.

Ensure that the target framework matches the one supported by the package, such as:

  • net8.0 (recommended)
  • net6.0
  • or netstandard2.0 for library projects.

Build and Run the Sample

Follow the steps below to build and run the sample:

  1. Open a terminal (Command Prompt or PowerShell).

  2. Navigate to the sample project directory:

    cd vizionsdk-csharp/samples
  3. Build the project:

    dotnet build
  4. Run the sample:

    dotnet run

Once executed, the sample application will run using the CSVizionSDK library.

Example Usage

Below are some example usages of the CSVizionSDK functions as demonstrated in the sample project.

1. Start the Device

Using StringVector to store the availabled camera devices and start the device at index 0:

StringVector devList = new StringVector();
int cam_num = CSVizionSDK.VxDiscoverCameraDevices(devList);
Console.WriteLine($"Devices: {cam_num}");

for (int i = 0; i < devList.Count; i++)
{
Console.WriteLine($"[{i}] {devList[i]}");
}

VxCamera cam = CSVizionSDK.VxInitialCameraDevice(0);
int ret = CSVizionSDK.VxOpen(cam);
Console.WriteLine($"Open camera: {ret}");

2. Retrieve Device Information

Get the device name and interface type:

// Get the camera device name
string devName = "";
int ret = CSVizionSDK.VxGetDeviceName(cam, ref devName);
Console.WriteLine($"GetDeviceName: {ret} / {devName}");

// Get the interface type name
VX_CAMERA_INTERFACE_TYPE type;
ret = CSVizionSDK.VxGetDeviceInterfaceType(cam, out type);
Console.WriteLine($"Get interface type: {ret} / {type}");

3. Adjust Device Brightness

Retrieve and set the brightness of the device:

// Get UVC image processing brightness
long min, max, step, def;
int ret = CSVizionSDK.VxGetUVCImageProcessingRange(cam, VX_UVC_IMAGE_PROPERTIES.UVC_IMAGE_BRIGHTNESS, out min, out max, out step, out def);
Console.WriteLine($"GetUVCImageProcessingRange: {ret}/{min}/{max}/{step}/{def}");

// Set the brightness to 12
ret = CSVizionSDK.VxSetUVCImageProcessing(cam, VX_UVC_IMAGE_PROPERTIES.UVC_IMAGE_BRIGHTNESS, 12, 0);
Console.WriteLine($"SetUVCImageProcessing: {ret}");