AxsunOCTControl_LW 2.0.0
A light-weight & cross-platform alternative to the .NET-based AxsunOCTControl.dll.
Loading...
Searching...
No Matches
AxsunOCTControl_LW_ExampleConsoleApp.cs

This example source code and the AOCLW.cs wrapper file show how to integrate the AxsunOCTControl_LW API in a C# client application via DllImport and P/Invoke.

using System;
using System.Threading; // for Sleep()
using AxsunOCTControl_LWdotnet; // for AOCLW class; including wrapper functions and related enums
namespace AxsunOCTControl_LW_ExampleConsoleApp_DotNet
{
public class Axsun {
public AOCLW cntrl = new AOCLW(false); // init the cntrl member variable when an object of Axsun class is constructed
public void PrintConnectedDevices()
{
// only call thread-safe AxsunOCTControl_LW functions here,
// and catch all thrown exceptions from here,
// since this function is invoked in a concurrent thread via callback
// count devices
var count = cntrl.GetNumberOfOCTDevicesPresent();
Console.WriteLine("Connected device count: " + count.ToString());
// print system type, connection interface, FW & FPGA version, serial number
for (uint i = 0; i < count; ++i)
{
try
{
var system_type = cntrl.GetSystemType(i);
Console.Write(system_type.ToString() +
" (" + cntrl.GetConnectionType(i).ToString() +
")\tFW: v" + cntrl.GetFirmwareVersion(i) +
"\tSN: " + cntrl.GetSerialNum(i));
if (system_type == AOCLW.AxDeviceType.EDAQ || system_type == AOCLW.AxDeviceType.AZMYTH_LASER)
Console.Write("\t FPGA: v" + cntrl.GetFPGAVersion(i));
Console.WriteLine();
}
catch (AOCLW.AxException ex)
{
Console.WriteLine("Error in connect callback: " + ex.msg_ + " (" + ex.err_.ToString() + ")");
}
}
Console.WriteLine();
}
}
class AxsunOCTControl_LW_ExampleConsoleApp
{
static void Main(string[] args)
{
try
{
// create instance of our Axsun class
Axsun axsun = new Axsun();
// print library version
Console.WriteLine("Using AxsunOCTControl_LW.dll v" + axsun.cntrl.GetControlVersion());
// register a delegate for device connect & disconnect events
Console.WriteLine("Registering connect/disconnect callback function...");
axsun.cntrl.OCTDeviceConnectOrDisconnectEvent += new AOCLW.OCTDeviceConnectOrDisconnectHandler(axsun.PrintConnectedDevices);
// open USB interface
Console.WriteLine("Starting USB interface...");
axsun.cntrl.StartUSBControlInterface();
// open network interface (needed for Ethernet DAQ connections only)
Console.WriteLine("Starting network interface...");
axsun.cntrl.StartNetworkControlInterface();
// enter loop which prompts user for desired command
var running = true;
while (running)
{
Console.Write("Type a character and press enter to execute a command ('?' for command list).\n >> ");
var which_command = Console.ReadLine();
try {
switch (which_command)
{
case "?":
Console.WriteLine("\n***** COMMAND LIST *****");
Console.WriteLine("D\tLASER: StopScan(...); // Disable Laser Emission");
Console.WriteLine("E\tLASER: StartScan(...); // Enable Laser Emission");
Console.WriteLine("0\tLASER: SwitchConfiguration(0); // Set Laser Drive Config 0");
Console.WriteLine("1\tLASER: SwitchConfiguration(1); // Set Laser Drive Config 1");
Console.WriteLine("G\tLASER: GetConfiguration(...); // Get Laser Drive Config");
Console.WriteLine("R\tLASER: GetLaserErrors(...); // Get Laser Error States");
// ... ADD MORE AS NEEDED ...
Console.WriteLine("\nI\tGet info on connected devices.");
Console.WriteLine("?\tList command options.");
Console.WriteLine("Q\tQuit this program.\n");
break;
case "I":
case "i":
axsun.PrintConnectedDevices();
break;
case "d":
case "D":
// Disable laser emission
Console.WriteLine("StopScan() ... disable laser emission.");
axsun.cntrl.StopScan(0);
break;
case "E":
case "e":
// Enable laser emission
Console.WriteLine("StartScan() ... enable laser emission.");
axsun.cntrl.StartScan(0);
break;
case "0":
// Set laser config 0
Console.WriteLine("SwitchConfiguration() to config 0.");
axsun.cntrl.SwitchConfiguration(0, 0);
break;
case "1":
// Set laser config 1
Console.WriteLine("SwitchConfiguration() to config 1.");
axsun.cntrl.SwitchConfiguration(1, 0);
break;
case "g":
case "G":
// Get laser config 1
Console.WriteLine("Current configuration is: " + axsun.cntrl.GetConfiguration(0).ToString());
break;
case "r":
case "R":
// Get laser config 1
Console.WriteLine("Current error state is: " + axsun.cntrl.GetLaserErrors(0).ToString());
break;
case "q":
case "Q":
Console.WriteLine("Quitting...");
running = false;
break;
default:
Console.WriteLine("Command not recognized. Enter '?' to list options.");
break;
}
}
catch (AOCLW.AxException ex)
{
Console.WriteLine("Error: " + ex.msg_ + " (" + ex.err_.ToString() + ")");
}
}
}
catch (AOCLW.AxException ex)
{
Console.WriteLine("Error in AxsunOCTControl_LW setup phase: " + ex.msg_ + " (" + ex.err_.ToString() + ")");
Console.WriteLine("Quitting...");
}
Thread.Sleep(1000); // pause before closing window
}
}
}
Definition AOCLW.cs:12