How to set the value of SANE device option?
In This Topic
Here is an example that demonstrates how to set the value of SANE device option:
/// <summary>
/// Sets value of SANE device option.
/// </summary>
public void SetValueOfSaneDeviceOption()
{
// create SANE device manager
using (Vintasoft.Sane.SaneLocalDeviceManager deviceManager = new Vintasoft.Sane.SaneLocalDeviceManager())
{
// open SANE device manager
deviceManager.Open();
// get count of SANE devices
int deviceCount = deviceManager.Devices.Count;
if (deviceCount == 0)
{
System.Console.WriteLine("Devices are not found.");
return;
}
// select the first SANE device
Vintasoft.Sane.SaneLocalDevice device = deviceManager.Devices[0];
// open SANE device
device.Open();
System.Console.WriteLine("Device name: " + device.Name);
// get SANE device option with name "source"
Vintasoft.Sane.SaneLocalDeviceOption sourceOption = device.Options.Find("source");
// if option is found
if (sourceOption != null)
{
// set new value for option
sourceOption.SetValue("Flatbed");
}
// close SANE device
device.Close();
// close SANE device manager
deviceManager.Close();
}
System.Console.ReadLine();
}
''' <summary>
''' Sets value of SANE device option.
''' </summary>
Public Sub SetValueOfSaneDeviceOption()
' create SANE device manager
Using deviceManager As New Vintasoft.Sane.SaneLocalDeviceManager()
' open SANE device manager
deviceManager.Open()
' get count of SANE devices
Dim deviceCount As Integer = deviceManager.Devices.Count
If deviceCount = 0 Then
System.Console.WriteLine("Devices are not found.")
Return
End If
' select the first SANE device
Dim device As Vintasoft.Sane.SaneLocalDevice = deviceManager.Devices(0)
' open SANE device
device.Open()
System.Console.WriteLine("Device name: " + device.Name)
' get SANE device option with name "source"
Dim sourceOption As Vintasoft.Sane.SaneLocalDeviceOption = device.Options.Find("source")
' if option is found
If sourceOption IsNot Nothing Then
' set new value for option
sourceOption.SetValue("Flatbed")
End If
' close SANE device
device.Close()
' close SANE device manager
deviceManager.Close()
End Using
System.Console.ReadLine()
End Sub