Refresh Method (sessionHandle)

LibUsbDotNet

LibUsbDotNet 2.2.8 Refresh Method (sessionHandle)
Library ReferenceMonoLibUsb.ProfileMonoUsbProfileListRefresh(MonoUsbSessionHandle)
LibUsbDotNet on SourceForge
Refreshes the MonoUsbProfile list.
Declaration Syntax
C# Visual Basic Visual C++
public int Refresh(
	MonoUsbSessionHandle sessionHandle
)
Public Function Refresh ( _
	sessionHandle As MonoUsbSessionHandle _
) As Integer
public:
int Refresh(
	MonoUsbSessionHandle^ sessionHandle
)
Parameters
sessionHandle (MonoUsbSessionHandle)
A valid MonoUsbSessionHandle.
Return Value
The number of devices in the outputted list, or ErrorNoMem on memory allocation failure.
Remarks

This is your entry point into finding a USB device to operate.

This return value of this function indicates the number of devices in the resultant list.

The MonoUsbProfileList has a crude form of built-in device notification that works on all platforms. By adding an event handler to the AddRemoveEvent changes in the device profile list are reported when Refresh(MonoUsbSessionHandle) is called.

Examples
CopyC#
using System;
using MonoLibUsb.Profile;
using Usb = MonoLibUsb.MonoUsbApi;

namespace MonoLibUsb.ShowInfo
{
    internal class ShowInfo
    {
        // The first time the Session property is used it creates a new session
        // handle instance in '__sessionHandle' and returns it. Subsequent 
        // request simply return '__sessionHandle'.
        private static MonoUsbSessionHandle __sessionHandle;
        public static MonoUsbSessionHandle Session
        {
            get
            {
                if (ReferenceEquals(__sessionHandle, null))
                    __sessionHandle = new MonoUsbSessionHandle();
                return __sessionHandle;
            }
        }
        public static void Main(string[] args)
        {
            int ret;
            MonoUsbProfileList profileList = null;

            // Initialize the context.
            if (Session.IsInvalid) 
                throw new Exception("Failed to initialize context.");

            MonoUsbApi.SetDebug(Session, 0);
            // Create a MonoUsbProfileList instance.
            profileList = new MonoUsbProfileList();

            // The list is initially empty.
            // Each time refresh is called the list contents are updated. 
            ret = profileList.Refresh(Session);
            if (ret < 0) throw new Exception("Failed to retrieve device list.");
            Console.WriteLine("{0} device(s) found.", ret);

            // Iterate through the profile list; write the device descriptor to
            // console output.
            foreach (MonoUsbProfile profile in profileList)
                Console.WriteLine(profile.DeviceDescriptor);

            // Since profile list, profiles, and sessions use safe handles the
            // code below is not required but it is considered good programming
            // to explicitly free and close these handle when they are no longer
            // in-use.
            profileList.Close();
            Session.Close();
        }
    }
}

Assembly: LibUsbDotNet (Module: LibUsbDotNet) Version: 2.2.8.104 (2.2.8.104)