readme.txt
author sl
Wed, 14 May 2014 07:53:47 +0200
changeset 1 29c8c6738077
permissions -rw-r--r--
Disabling signing to fix our build.
sl@0
     1
	///<summary>
sl@0
     2
	/// Project: GenericHid
sl@0
     3
	/// 
sl@0
     4
	/// ***********************************************************************
sl@0
     5
	/// Software License Agreement
sl@0
     6
	///
sl@0
     7
	/// Licensor grants any person obtaining a copy of this software ("You") 
sl@0
     8
	/// a worldwide, royalty-free, non-exclusive license, for the duration of 
sl@0
     9
	/// the copyright, free of charge, to store and execute the Software in a 
sl@0
    10
	/// computer system and to incorporate the Software or any portion of it 
sl@0
    11
	/// in computer programs You write.   
sl@0
    12
	/// 
sl@0
    13
	/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
sl@0
    14
	/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
sl@0
    15
	/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
sl@0
    16
	/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
sl@0
    17
	/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
sl@0
    18
	/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
sl@0
    19
	/// THE SOFTWARE.
sl@0
    20
	/// ***********************************************************************
sl@0
    21
	/// 
sl@0
    22
	/// Author             
sl@0
    23
	/// Jan Axelson        
sl@0
    24
	/// 
sl@0
    25
	/// This software was written using Visual Studio Express 2012 for Windows
sl@0
    26
	/// Desktop building for the .NET Framework v4.5.
sl@0
    27
	/// 
sl@0
    28
	/// Purpose: 
sl@0
    29
	/// Demonstrates USB communications with a generic HID-class device
sl@0
    30
	/// 
sl@0
    31
	/// Requirements:
sl@0
    32
	/// Windows Vista or later and an attached USB generic Human Interface Device (HID).
sl@0
    33
	/// (Does not run on Windows XP or earlier because .NET Framework 4.5 will not install on these OSes.) 
sl@0
    34
	/// 
sl@0
    35
	/// Description:
sl@0
    36
	/// Finds an attached device that matches the vendor and product IDs in the form's 
sl@0
    37
	/// text boxes.
sl@0
    38
	/// 
sl@0
    39
	/// Retrieves the device's capabilities.
sl@0
    40
	/// Sends and requests HID reports.
sl@0
    41
	/// 
sl@0
    42
	/// Uses the System.Management class and Windows Management Instrumentation (WMI) to detect 
sl@0
    43
	/// when a device is attached or removed.
sl@0
    44
	/// 
sl@0
    45
	/// A list box displays the data sent and received along with error and status messages.
sl@0
    46
	/// You can select data to send and 1-time or periodic transfers.
sl@0
    47
	/// 
sl@0
    48
	/// You can change the size of the host's Input report buffer and request to use control
sl@0
    49
	/// transfers only to exchange Input and Output reports.
sl@0
    50
	/// 
sl@0
    51
	/// To view additional debugging messages, in the Visual Studio development environment,
sl@0
    52
	/// from the main menu, select Build > Configuration Manager > Active Solution Configuration 
sl@0
    53
	/// and select Configuration > Debug and from the main menu, select View > Output.
sl@0
    54
	/// 
sl@0
    55
	/// The application uses asynchronous FileStreams to read Input reports and write Output 
sl@0
    56
	/// reports so the application's main thread doesn't have to wait for the device to retrieve a 
sl@0
    57
	/// report when the HID driver's buffer is empty or send a report when the device's endpoint is busy. 
sl@0
    58
	/// 
sl@0
    59
	/// For code that finds a device and opens handles to it, see the FindTheHid routine in frmMain.cs.
sl@0
    60
	/// For code that reads from the device, see GetInputReportViaInterruptTransfer, 
sl@0
    61
	/// GetInputReportViaControlTransfer, and GetFeatureReport in Hid.cs.
sl@0
    62
	/// For code that writes to the device, see SendInputReportViaInterruptTransfer, 
sl@0
    63
	/// SendInputReportViaControlTransfer, and SendFeatureReport in Hid.cs.
sl@0
    64
	/// 
sl@0
    65
	/// This project includes the following modules:
sl@0
    66
	/// 
sl@0
    67
	/// GenericHid.cs - runs the application.
sl@0
    68
	/// FrmMain.cs - routines specific to the form.
sl@0
    69
	/// Hid.cs - routines specific to HID communications.
sl@0
    70
	/// DeviceManagement.cs - routine for obtaining a handle to a device from its GUID.
sl@0
    71
	/// Debugging.cs - contains a routine for displaying API error messages.
sl@0
    72
	/// HidDeclarations.cs - Declarations for API functions used by Hid.cs.
sl@0
    73
	/// FileIODeclarations.cs - Declarations for file-related API functions.
sl@0
    74
	/// DeviceManagementDeclarations.cs - Declarations for API functions used by DeviceManagement.cs.
sl@0
    75
	/// DebuggingDeclarations.cs - Declarations for API functions used by Debugging.cs.
sl@0
    76
	/// 
sl@0
    77
	/// Companion device firmware for several device CPUs is available from www.Lvr.com/hidpage.htm
sl@0
    78
	/// You can use any generic HID (not a system mouse or keyboard) that sends and receives reports.
sl@0
    79
	/// This application will not detect or communicate with non-HID-class devices.
sl@0
    80
	/// 
sl@0
    81
	/// For more information about HIDs and USB, and additional example device firmware to use
sl@0
    82
	/// with this application, visit Lakeview Research at http://Lvr.com 
sl@0
    83
	/// Send comments, bug reports, etc. to jan@Lvr.com or post on my PORTS forum: http://www.lvr.com/forum 
sl@0
    84
	/// 
sl@0
    85
	/// V6.2
sl@0
    86
	/// 11/12/13
sl@0
    87
	/// Disabled form buttons when a transfer is in progress.
sl@0
    88
	/// Other minor edits for clarity and readability.
sl@0
    89
	/// Will NOT run on Windows XP or earlier, see below.
sl@0
    90
	/// 
sl@0
    91
	/// V6.1
sl@0
    92
	/// 10/28/13
sl@0
    93
	/// Uses the .NET System.Management class to detect device arrival and removal with WMI instead of Win32 RegisterDeviceNotification.
sl@0
    94
	/// Other minor edits.
sl@0
    95
	/// Will NOT run on Windows XP or earlier, see below.
sl@0
    96
	///  
sl@0
    97
	/// V6.0
sl@0
    98
	/// 2/8/13
sl@0
    99
	/// This version will NOT run on Windows XP or earlier because the code uses .NET Framework 4.5 to support asynchronous FileStreams.
sl@0
   100
	/// The .NET Framework 4.5 redistributable is compatible with Windows 8, Windows 7 SP1, Windows Server 2008 R2 SP1, 
sl@0
   101
	/// Windows Server 2008 SP2, Windows Vista SP2, and Windows Vista SP3.
sl@0
   102
	/// For compatibility, replaced ToInt32 with ToInt64 here:
sl@0
   103
	/// IntPtr pDevicePathName = new IntPtr(detailDataBuffer.ToInt64() + 4);
sl@0
   104
	/// and here:
sl@0
   105
	/// if ((deviceNotificationHandle.ToInt64() == IntPtr.Zero.ToInt64()))
sl@0
   106
	/// For compatibility if the charset isn't English, added System.Globalization.CultureInfo.InvariantCulture here:
sl@0
   107
	/// if ((String.Compare(DeviceNameString, mydevicePathName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))
sl@0
   108
	/// Replaced all Microsoft.VisualBasic namespace code with other .NET equivalents.
sl@0
   109
	/// Revised user interface for more flexibility.
sl@0
   110
	/// Moved interrupt-transfer and other HID-specific code to Hid.cs.
sl@0
   111
	/// Used JetBrains ReSharper to clean up the code: http://www.jetbrains.com/resharper/
sl@0
   112
	/// 
sl@0
   113
	/// V5.0
sl@0
   114
	/// 3/30/11
sl@0
   115
	/// Replaced ReadFile and WriteFile with FileStreams. Thanks to Joe Dunne and John on my Ports forum for tips on this.
sl@0
   116
	/// Simplified Hid.cs.
sl@0
   117
	/// Replaced the form timer with a system timer.
sl@0
   118
	/// 
sl@0
   119
	/// V4.6
sl@0
   120
	/// 1/12/10
sl@0
   121
	/// Supports Vendor IDs and Product IDs up to FFFFh.
sl@0
   122
	///
sl@0
   123
	/// V4.52
sl@0
   124
	/// 11/10/09
sl@0
   125
	/// Changed HIDD_ATTRIBUTES to use UInt16
sl@0
   126
	/// 
sl@0
   127
	/// V4.51
sl@0
   128
	/// 2/11/09
sl@0
   129
	/// Moved Free_ and similar to Finally blocks to ensure they execute.
sl@0
   130
	/// 
sl@0
   131
	/// V4.5
sl@0
   132
	/// 2/9/09
sl@0
   133
	/// Changes to support 64-bit systems, memory management, and other corrections. 
sl@0
   134
	/// Big thanks to Peter Nielsen.
sl@0
   135
	///  
sl@0
   136
	/// </summary>