VintaSoft Twain .NET SDK 14.1: Руководство для .NET разработчика
Vintasoft.Sane Namespace / SaneLocalDevice Class / Options Property
Синтаксис Example Требования Смотрите также
В этом разделе
    Options Свойство (SaneLocalDevice)
    В этом разделе
    Возвращает параметры этого SANE устройства.
    Синтаксис
    Пример

    Вот C#/VB.NET код, который демонстрирует, как отображать информацию обо всех опциях SANE устройства.

    
    ''' <summary>
    ''' Displays information about all options of SANE device.
    ''' </summary>
    Public Sub DisplayInformationAboutAllOptionsOfSaneDevice()
            ' 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)
    
                    ' for each option of SANE device
                    For Each [option] As Vintasoft.Sane.SaneLocalDeviceOption In device.Options
                            System.Console.WriteLine(String.Format("- Option Name='{0}', Title='{1}', Description='{2}', Type={3}, Unit={4}, ValueSize={5}, CanSet={6}, CanBeAutomatic={7}, IsActive={8}, Capabilities={9}", [option].Name, [option].Title, [option].Description, [option].Type, [option].Unit, _
                                    [option].ValueSize, [option].CanSet, [option].CanBeAutomatic, [option].IsActive, [option].Capabilities))
    
                            Dim value As Object
                            Try
                                    value = [option].GetValue()
                                    System.Console.WriteLine(String.Format("  DefaultValue={0}", value))
                            Catch ex As System.Exception
                                    System.Console.WriteLine("  Cannot get the default value: " & ex.Message)
                                    Continue For
                            End Try
    
                            Select Case [option].Type
                                    Case Vintasoft.Sane.SaneType.[Integer]
                                            Dim supportedIntValues As Object = [option].GetSupportedValues()
                                            If supportedIntValues Is Nothing Then
                                                    System.Console.WriteLine("  Supported values are not limited.")
                                            Else
                                                    If TypeOf supportedIntValues Is Vintasoft.Sane.SaneIntArray Then
                                                            Dim array As Vintasoft.Sane.SaneIntArray = DirectCast(supportedIntValues, Vintasoft.Sane.SaneIntArray)
    
                                                            System.Console.Write("  Supported values: ")
                                                            For i As Integer = 0 To array.Values.Length - 1
                                                                    System.Console.Write(array.Values(i) + " ")
                                                            Next
                                                            System.Console.WriteLine()
                                                    Else
                                                            Dim range As Vintasoft.Sane.SaneIntRange = TryCast(supportedIntValues, Vintasoft.Sane.SaneIntRange)
    
                                                            System.Console.WriteLine((("  Supported range: Min=" + range.Min & ", Max=") + range.Max & ", Step=") + range.[Step])
                                                    End If
                                            End If
                                            Exit Select
    
                                    Case Vintasoft.Sane.SaneType.Fixed
                                            Dim supportedFixedValues As Object = [option].GetSupportedValues()
                                            If supportedFixedValues Is Nothing Then
                                                    System.Console.WriteLine("  Supported values are not limited.")
                                            Else
                                                    If TypeOf supportedFixedValues Is Vintasoft.Sane.SaneFixedArray Then
                                                            Dim array As Vintasoft.Sane.SaneFixedArray = DirectCast(supportedFixedValues, Vintasoft.Sane.SaneFixedArray)
    
                                                            System.Console.Write("  Supported values: ")
                                                            For i As Integer = 0 To array.Values.Length - 1
                                                                    System.Console.Write(array.Values(i) + " ")
                                                            Next
                                                            System.Console.WriteLine()
                                                    Else
                                                            Dim range As Vintasoft.Sane.SaneFixedRange = TryCast(supportedFixedValues, Vintasoft.Sane.SaneFixedRange)
    
                                                            System.Console.WriteLine((("  Supported range: Min=" + range.Min & ", Max=") + range.Max & ", Step=") + range.[Step])
                                                    End If
                                            End If
                                            Exit Select
    
                                    Case Vintasoft.Sane.SaneType.[String]
                                            Dim supportedStringValues As Object = [option].GetSupportedValues()
                                            If supportedStringValues Is Nothing Then
                                                    System.Console.WriteLine("  Supported values are not limited.")
                                            Else
                                                    Dim array As Vintasoft.Sane.SaneStringArray = TryCast(supportedStringValues, Vintasoft.Sane.SaneStringArray)
                                                    If array IsNot Nothing Then
                                                            System.Console.Write("  Supported values: ")
                                                            For i As Integer = 0 To array.Values.Length - 1
                                                                    System.Console.Write(String.Format("'{0}' ", array.Values(i)))
                                                            Next
                                                            System.Console.WriteLine()
                                                    End If
                                            End If
                                            Exit Select
                            End Select
                    Next
    
    
                    ' close SANE device
                    device.Close()
    
                    ' close SANE device manager
                    deviceManager.Close()
            End Using
    
            System.Console.ReadLine()
    End Sub
    
    
    
    /// <summary>
    /// Displays information about all options of SANE device.
    /// </summary>
    public void DisplayInformationAboutAllOptionsOfSaneDevice()
    {
        // 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);
    
            // for each option of SANE device
            foreach (Vintasoft.Sane.SaneLocalDeviceOption option in device.Options)
            {
                System.Console.WriteLine(
                    string.Format("- Option Name='{0}', Title='{1}', Description='{2}', Type={3}, Unit={4}, ValueSize={5}, CanSet={6}, CanBeAutomatic={7}, IsActive={8}, Capabilities={9}",
                    option.Name,
                    option.Title,
                    option.Description,
                    option.Type,
                    option.Unit,
                    option.ValueSize,
                    option.CanSet,
                    option.CanBeAutomatic,
                    option.IsActive,
                    option.Capabilities));
    
                object value;
                try
                {
                    value = option.GetValue();
                    System.Console.WriteLine(string.Format("  DefaultValue={0}", value));
                }
                catch (System.Exception ex)
                {
                    System.Console.WriteLine("  Cannot get the default value: " + ex.Message);
                    continue;
                }
    
                switch (option.Type)
                {
                    case Vintasoft.Sane.SaneType.Integer:
                        object supportedIntValues = option.GetSupportedValues();
                        if (supportedIntValues == null)
                        {
                            System.Console.WriteLine("  Supported values are not limited.");
                        }
                        else
                        {
                            if (supportedIntValues is Vintasoft.Sane.SaneIntArray)
                            {
                                Vintasoft.Sane.SaneIntArray array = (Vintasoft.Sane.SaneIntArray)supportedIntValues;
    
                                System.Console.Write("  Supported values: ");
                                for (int i = 0; i < array.Values.Length; i++)
                                {
                                    System.Console.Write(array.Values[i] + " ");
                                }
                                System.Console.WriteLine();
                            }
                            else
                            {
                                Vintasoft.Sane.SaneIntRange range = supportedIntValues as Vintasoft.Sane.SaneIntRange;
    
                                System.Console.WriteLine("  Supported range: Min=" + range.Min + ", Max=" + range.Max + ", Step=" + range.Step);
                            }
                        }
                        break;
    
                    case Vintasoft.Sane.SaneType.Fixed:
                        object supportedFixedValues = option.GetSupportedValues();
                        if (supportedFixedValues == null)
                        {
                            System.Console.WriteLine("  Supported values are not limited.");
                        }
                        else
                        {
                            if (supportedFixedValues is Vintasoft.Sane.SaneFixedArray)
                            {
                                Vintasoft.Sane.SaneFixedArray array = (Vintasoft.Sane.SaneFixedArray)supportedFixedValues;
    
                                System.Console.Write("  Supported values: ");
                                for (int i = 0; i < array.Values.Length; i++)
                                {
                                    System.Console.Write(array.Values[i] + " ");
                                }
                                System.Console.WriteLine();
                            }
                            else
                            {
                                Vintasoft.Sane.SaneFixedRange range = supportedFixedValues as Vintasoft.Sane.SaneFixedRange;
    
                                System.Console.WriteLine("  Supported range: Min=" + range.Min + ", Max=" + range.Max + ", Step=" + range.Step);
                            }
                        }
                        break;
    
                    case Vintasoft.Sane.SaneType.String:
                        object supportedStringValues = option.GetSupportedValues();
                        if (supportedStringValues == null)
                        {
                            System.Console.WriteLine("  Supported values are not limited.");
                        }
                        else
                        {
                            Vintasoft.Sane.SaneStringArray array = supportedStringValues as Vintasoft.Sane.SaneStringArray;
                            if (array != null)
                            {
                                System.Console.Write("  Supported values: ");
                                for (int i = 0; i < array.Values.Length; i++)
                                {
                                    System.Console.Write(string.Format("'{0}' ", array.Values[i]));
                                }
                                System.Console.WriteLine();
                            }
                        }
                        break;
                }
            }
    
    
            // close SANE device
            device.Close();
    
            // close SANE device manager
            deviceManager.Close();
        }
    
        System.Console.ReadLine();
    }
    
    

    Требования

    Целевые платформы: .NET 8; .NET 7; .NET 6

    Смотрите также