コード例 #1
0
 /// <summary>
 /// Get a string describing the last error which occurred.
 /// </summary>
 /// <param name="device">A device handle returned from hid_open()</param>
 /// <returns>This function returns a string containing the last error which occurred or NULL if none has occurred.</returns>
 public static IntPtr hid_error(IntPtr device)
 {
     if (m_OsType == OsType.Win32)
     {
         return(HidApiWin32.hid_error(device));
     }
     else if (m_OsType == OsType.Win64)
     {
         return(HidApiWin64.hid_error(device));
     }
     else
     {
         throw new NotSupportedException(CANNOT_RESOLVE_OS_TYPE_MESSAGE);
     }
 }
コード例 #2
0
 /// <summary>
 /// Finalize the HIDAPI library.
 /// This function frees all of the static data associated with HIDAPI.
 /// It should be called at the end of execution to avoid memory leaks.
 /// </summary>
 /// <returns>This function returns 0 on success and -1 on error.</returns>
 public static int hid_exit()
 {
     if (m_OsType == OsType.Win32)
     {
         return(HidApiWin32.hid_exit());
     }
     else if (m_OsType == OsType.Win64)
     {
         return(HidApiWin64.hid_exit());
     }
     else
     {
         throw new NotSupportedException(CANNOT_RESOLVE_OS_TYPE_MESSAGE);
     }
 }
コード例 #3
0
 /// <summary>
 /// Get The Product String from a HID device.
 /// </summary>
 /// <param name="device">A device handle returned from hid_open()</param>
 /// <param name="str">A wide string buffer to put the data into</param>
 /// <param name="length">The length of the buffer in multiples of wchar_t</param>
 /// <returns>This function returns 0 on success and -1 on error</returns>
 public static int hid_get_product_string(IntPtr device, StringBuilder str, uint length)
 {
     if (m_OsType == OsType.Win32)
     {
         return(HidApiWin32.hid_get_product_string(device, str, length));
     }
     else if (m_OsType == OsType.Win64)
     {
         return(HidApiWin64.hid_get_product_string(device, str, length));
     }
     else
     {
         throw new NotSupportedException(CANNOT_RESOLVE_OS_TYPE_MESSAGE);
     }
 }
コード例 #4
0
 /// <summary>
 /// Get a string from a HID device, based on its string index.
 /// </summary>
 /// <param name="device">A device handle returned from hid_open()</param>
 /// <param name="string_index">The index of the string to get</param>
 /// <param name="str">A wide string buffer to put the data into</param>
 /// <param name="maxlen">The length of the buffer in multiples of wchar_t</param>
 /// <returns>This function returns 0 on success and -1 on error.</returns>
 public static int hid_get_indexed_string(IntPtr device, int string_index, StringBuilder str, uint maxlen)
 {
     if (m_OsType == OsType.Win32)
     {
         return(HidApiWin32.hid_get_indexed_string(device, string_index, str, maxlen));
     }
     else if (m_OsType == OsType.Win64)
     {
         return(HidApiWin64.hid_get_indexed_string(device, string_index, str, maxlen));
     }
     else
     {
         throw new NotSupportedException(CANNOT_RESOLVE_OS_TYPE_MESSAGE);
     }
 }
コード例 #5
0
 /// <summary>
 /// Get a feature report from a HID device.
 /// Set the first byte of data[] to the Report ID of the report to be read.
 /// Make sure to allow space for this extra byte in data[].
 /// Upon return, the first byte will still contain the Report ID, and the report data will start in data[1].
 /// </summary>
 /// <param name="device">A device handle returned from hid_open()</param>
 /// <param name="data">
 /// A buffer to put the read data into, including the Report ID.
 /// Set the first byte of data[] to the Report ID of the report to be read, or set it to zero if your device does not use numbered reports
 /// </param>
 /// <param name="length">The number of bytes to read, including an extra byte for the report ID. The buffer can be longer than the actual report</param>
 /// <returns>This function returns the number of bytes read plus one for the report ID (which is still in the first byte), or -1 on error</returns>
 public static int hid_get_feature_report(IntPtr device, byte[] data, uint length)
 {
     if (m_OsType == OsType.Win32)
     {
         return(HidApiWin32.hid_get_feature_report(device, data, length));
     }
     else if (m_OsType == OsType.Win64)
     {
         return(HidApiWin64.hid_get_feature_report(device, data, length));
     }
     else
     {
         throw new NotSupportedException(CANNOT_RESOLVE_OS_TYPE_MESSAGE);
     }
 }
コード例 #6
0
 /// <summary>
 /// Close a HID device.
 /// </summary>
 /// <param name="device">A device handle returned from hid_open()</param>
 public static void hid_close(IntPtr device)
 {
     if (m_OsType == OsType.Win32)
     {
         HidApiWin32.hid_close(device);
     }
     else if (m_OsType == OsType.Win64)
     {
         HidApiWin64.hid_close(device);
     }
     else
     {
         throw new NotSupportedException(CANNOT_RESOLVE_OS_TYPE_MESSAGE);
     }
 }
コード例 #7
0
 /// <summary>
 /// Set the device handle to be non-blocking.
 /// In non-blocking mode calls to hid_read() will return immediately with a value of 0 if there is no data to be read.
 /// In blocking mode, hid_read() will wait(block) until there is data to read before returning.
 /// Nonblocking can be turned on and off at any time
 /// </summary>
 /// <param name="device">A device handle returned from hid_open()</param>
 /// <param name="nonblock">Enable(1) or not(0) the nonblocking reads</param>
 /// <returns>This function returns 0 on success and -1 on error</returns>
 public int hid_set_nonblocking(IntPtr device, int nonblock)
 {
     if (m_OsType == OsType.Win32)
     {
         return(HidApiWin32.hid_set_nonblocking(device, nonblock));
     }
     else if (m_OsType == OsType.Win64)
     {
         return(HidApiWin64.hid_set_nonblocking(device, nonblock));
     }
     else
     {
         throw new NotSupportedException(CANNOT_RESOLVE_OS_TYPE_MESSAGE);
     }
 }
コード例 #8
0
 /// <summary>
 /// Read an Input report from a HID device with timeout.
 /// Input reports are returned to the host through the INTERRUPT IN endpoint.
 /// The first byte will contain the Report number if the device uses numbered reports.
 /// </summary>
 /// <param name="device">A device handle returned from hid_open().</param>
 /// <param name="data">A buffer to put the read data into</param>
 /// <param name="length">The number of bytes to read. For devices with multiple reports, make sure to read an extra byte for the report number</param>
 /// <param name="milliseconds">Timeout in milliseconds or -1 for blocking wait</param>
 /// <returns>
 /// This function returns the actual number of bytes read and -1 on error.
 /// If no packet was available to be read within the timeout period, this function returns 0
 /// </returns>
 public static int hid_read_timeout(IntPtr device, byte[] data, uint length, int milliseconds)
 {
     if (m_OsType == OsType.Win32)
     {
         return(HidApiWin32.hid_read_timeout(device, data, length, milliseconds));
     }
     else if (m_OsType == OsType.Win64)
     {
         return(HidApiWin64.hid_read_timeout(device, data, length, milliseconds));
     }
     else
     {
         throw new NotSupportedException(CANNOT_RESOLVE_OS_TYPE_MESSAGE);
     }
 }
コード例 #9
0
 /// <summary>
 /// Open a HID device by its path name.
 /// The path name be determined by calling hid_enumerate(), or a platform-specific path name can be used(eg: /dev/hidraw0 on Linux)
 /// </summary>
 /// <param name="path">The path name of the device to open</param>
 /// <returns>This function returns a pointer to a hid_device object on success or NULL on failure</returns>
 public static IntPtr hid_open_path(IntPtr path)
 {
     if (m_OsType == OsType.Win32)
     {
         return(HidApiWin32.hid_open_path(path));
     }
     else if (m_OsType == OsType.Win64)
     {
         return(HidApiWin64.hid_open_path(path));
     }
     else
     {
         throw new NotSupportedException(CANNOT_RESOLVE_OS_TYPE_MESSAGE);
     }
 }
コード例 #10
0
 /// <summary>
 /// Open a HID device using a Vendor ID (VID), Product ID (PID) and optionally a serial number.
 /// If serial_number is NULL, the first device with the specified VID and PID is opened.
 /// </summary>
 /// <param name="vendor_id">The Vendor ID (VID) of the device to open</param>
 /// <param name="product_id">The Product ID (PID) of the device to open</param>
 /// <param name="serial_number">The Serial Number of the device to open (Optionally NULL)</param>
 /// <returns>This function returns a pointer to a hid_device object on success or NULL on failure</returns>
 public static IntPtr hid_open(ushort vendor_id, ushort product_id, string serial_number)
 {
     if (m_OsType == OsType.Win32)
     {
         return(HidApiWin32.hid_open(vendor_id, product_id, serial_number));
     }
     else if (m_OsType == OsType.Win64)
     {
         return(HidApiWin64.hid_open(vendor_id, product_id, serial_number));
     }
     else
     {
         throw new NotSupportedException(CANNOT_RESOLVE_OS_TYPE_MESSAGE);
     }
 }
コード例 #11
0
 /// <summary>
 /// Enumerate the HID Devices.
 /// This function returns a linked list of all the HID devices attached to the system which match vendor_id and product_id.
 /// If vendor_id is set to 0 then any vendor matches. If product_id is set to 0 then any product matches.
 /// If vendor_id and product_id are both set to 0, then all HID devices will be returned.
 /// </summary>
 /// <param name="vendor_id">The Vendor ID (VID) of the types of device to open.</param>
 /// <param name="product_id">The Product ID (PID) of the types of device to open.</param>
 /// <returns>
 /// This function returns a pointer to a linked list of type struct hid_device,
 /// containing information about the HID devices attached to the system, or NULL in the case of failure.
 /// Free this linked list by calling hid_free_enumeration().
 /// </returns>
 public static IntPtr hid_enumerate(ushort vendor_id, ushort product_id)
 {
     if (m_OsType == OsType.Win32)
     {
         return(HidApiWin32.hid_enumerate(vendor_id, product_id));
     }
     else if (m_OsType == OsType.Win64)
     {
         return(HidApiWin64.hid_enumerate(vendor_id, product_id));
     }
     else
     {
         throw new NotSupportedException(CANNOT_RESOLVE_OS_TYPE_MESSAGE);
     }
 }