Adding log s to display all our HID devices.
1.1 --- a/FrmMain.cs Wed May 14 07:53:47 2014 +0200
1.2 +++ b/FrmMain.cs Wed May 14 07:57:55 2014 +0200
1.3 @@ -13,16 +13,16 @@
1.4 {
1.5 ///<summary>
1.6 /// Project: GenericHid
1.7 - ///
1.8 + ///
1.9 /// ***********************************************************************
1.10 /// Software License Agreement
1.11 ///
1.12 - /// Licensor grants any person obtaining a copy of this software ("You")
1.13 - /// a worldwide, royalty-free, non-exclusive license, for the duration of
1.14 - /// the copyright, free of charge, to store and execute the Software in a
1.15 - /// computer system and to incorporate the Software or any portion of it
1.16 - /// in computer programs You write.
1.17 - ///
1.18 + /// Licensor grants any person obtaining a copy of this software ("You")
1.19 + /// a worldwide, royalty-free, non-exclusive license, for the duration of
1.20 + /// the copyright, free of charge, to store and execute the Software in a
1.21 + /// computer system and to incorporate the Software or any portion of it
1.22 + /// in computer programs You write.
1.23 + ///
1.24 /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1.25 /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1.26 /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1.27 @@ -31,52 +31,52 @@
1.28 /// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1.29 /// THE SOFTWARE.
1.30 /// ***********************************************************************
1.31 - ///
1.32 - /// Author
1.33 - /// Jan Axelson
1.34 - ///
1.35 + ///
1.36 + /// Author
1.37 + /// Jan Axelson
1.38 + ///
1.39 /// This software was written using Visual Studio Express 2012 for Windows
1.40 /// Desktop building for the .NET Framework v4.5.
1.41 - ///
1.42 - /// Purpose:
1.43 + ///
1.44 + /// Purpose:
1.45 /// Demonstrates USB communications with a generic HID-class device
1.46 - ///
1.47 + ///
1.48 /// Requirements:
1.49 /// Windows Vista or later and an attached USB generic Human Interface Device (HID).
1.50 - /// (Does not run on Windows XP or earlier because .NET Framework 4.5 will not install on these OSes.)
1.51 - ///
1.52 + /// (Does not run on Windows XP or earlier because .NET Framework 4.5 will not install on these OSes.)
1.53 + ///
1.54 /// Description:
1.55 - /// Finds an attached device that matches the vendor and product IDs in the form's
1.56 + /// Finds an attached device that matches the vendor and product IDs in the form's
1.57 /// text boxes.
1.58 - ///
1.59 + ///
1.60 /// Retrieves the device's capabilities.
1.61 /// Sends and requests HID reports.
1.62 - ///
1.63 - /// Uses the System.Management class and Windows Management Instrumentation (WMI) to detect
1.64 + ///
1.65 + /// Uses the System.Management class and Windows Management Instrumentation (WMI) to detect
1.66 /// when a device is attached or removed.
1.67 - ///
1.68 + ///
1.69 /// A list box displays the data sent and received along with error and status messages.
1.70 /// You can select data to send and 1-time or periodic transfers.
1.71 - ///
1.72 + ///
1.73 /// You can change the size of the host's Input report buffer and request to use control
1.74 /// transfers only to exchange Input and Output reports.
1.75 - ///
1.76 + ///
1.77 /// To view additional debugging messages, in the Visual Studio development environment,
1.78 - /// from the main menu, select Build > Configuration Manager > Active Solution Configuration
1.79 + /// from the main menu, select Build > Configuration Manager > Active Solution Configuration
1.80 /// and select Configuration > Debug and from the main menu, select View > Output.
1.81 - ///
1.82 - /// The application uses asynchronous FileStreams to read Input reports and write Output
1.83 - /// reports so the application's main thread doesn't have to wait for the device to retrieve a
1.84 - /// report when the HID driver's buffer is empty or send a report when the device's endpoint is busy.
1.85 - ///
1.86 + ///
1.87 + /// The application uses asynchronous FileStreams to read Input reports and write Output
1.88 + /// reports so the application's main thread doesn't have to wait for the device to retrieve a
1.89 + /// report when the HID driver's buffer is empty or send a report when the device's endpoint is busy.
1.90 + ///
1.91 /// For code that finds a device and opens handles to it, see the FindTheHid routine in frmMain.cs.
1.92 - /// For code that reads from the device, see GetInputReportViaInterruptTransfer,
1.93 + /// For code that reads from the device, see GetInputReportViaInterruptTransfer,
1.94 /// GetInputReportViaControlTransfer, and GetFeatureReport in Hid.cs.
1.95 - /// For code that writes to the device, see SendInputReportViaInterruptTransfer,
1.96 + /// For code that writes to the device, see SendInputReportViaInterruptTransfer,
1.97 /// SendInputReportViaControlTransfer, and SendFeatureReport in Hid.cs.
1.98 - ///
1.99 + ///
1.100 /// This project includes the following modules:
1.101 - ///
1.102 + ///
1.103 /// GenericHid.cs - runs the application.
1.104 /// FrmMain.cs - routines specific to the form.
1.105 /// Hid.cs - routines specific to HID communications.
1.106 @@ -86,31 +86,31 @@
1.107 /// FileIODeclarations.cs - Declarations for file-related API functions.
1.108 /// DeviceManagementDeclarations.cs - Declarations for API functions used by DeviceManagement.cs.
1.109 /// DebuggingDeclarations.cs - Declarations for API functions used by Debugging.cs.
1.110 - ///
1.111 + ///
1.112 /// Companion device firmware for several device CPUs is available from www.Lvr.com/hidpage.htm
1.113 /// You can use any generic HID (not a system mouse or keyboard) that sends and receives reports.
1.114 /// This application will not detect or communicate with non-HID-class devices.
1.115 - ///
1.116 + ///
1.117 /// For more information about HIDs and USB, and additional example device firmware to use
1.118 - /// with this application, visit Lakeview Research at http://Lvr.com
1.119 - /// Send comments, bug reports, etc. to jan@Lvr.com or post on my PORTS forum: http://www.lvr.com/forum
1.120 - ///
1.121 + /// with this application, visit Lakeview Research at http://Lvr.com
1.122 + /// Send comments, bug reports, etc. to jan@Lvr.com or post on my PORTS forum: http://www.lvr.com/forum
1.123 + ///
1.124 /// V6.2
1.125 /// 11/12/13
1.126 /// Disabled form buttons when a transfer is in progress.
1.127 /// Other minor edits for clarity and readability.
1.128 /// Will NOT run on Windows XP or earlier, see below.
1.129 - ///
1.130 + ///
1.131 /// V6.1
1.132 /// 10/28/13
1.133 /// Uses the .NET System.Management class to detect device arrival and removal with WMI instead of Win32 RegisterDeviceNotification.
1.134 /// Other minor edits.
1.135 /// Will NOT run on Windows XP or earlier, see below.
1.136 - ///
1.137 + ///
1.138 /// V6.0
1.139 /// 2/8/13
1.140 /// This version will NOT run on Windows XP or earlier because the code uses .NET Framework 4.5 to support asynchronous FileStreams.
1.141 - /// The .NET Framework 4.5 redistributable is compatible with Windows 8, Windows 7 SP1, Windows Server 2008 R2 SP1,
1.142 + /// The .NET Framework 4.5 redistributable is compatible with Windows 8, Windows 7 SP1, Windows Server 2008 R2 SP1,
1.143 /// Windows Server 2008 SP2, Windows Vista SP2, and Windows Vista SP3.
1.144 /// For compatibility, replaced ToInt32 with ToInt64 here:
1.145 /// IntPtr pDevicePathName = new IntPtr(detailDataBuffer.ToInt64() + 4);
1.146 @@ -122,13 +122,13 @@
1.147 /// Revised user interface for more flexibility.
1.148 /// Moved interrupt-transfer and other HID-specific code to Hid.cs.
1.149 /// Used JetBrains ReSharper to clean up the code: http://www.jetbrains.com/resharper/
1.150 - ///
1.151 + ///
1.152 /// V5.0
1.153 /// 3/30/11
1.154 /// Replaced ReadFile and WriteFile with FileStreams. Thanks to Joe Dunne and John on my Ports forum for tips on this.
1.155 /// Simplified Hid.cs.
1.156 /// Replaced the form timer with a system timer.
1.157 - ///
1.158 + ///
1.159 /// V4.6
1.160 /// 1/12/10
1.161 /// Supports Vendor IDs and Product IDs up to FFFFh.
1.162 @@ -136,16 +136,16 @@
1.163 /// V4.52
1.164 /// 11/10/09
1.165 /// Changed HIDD_ATTRIBUTES to use UInt16
1.166 - ///
1.167 + ///
1.168 /// V4.51
1.169 /// 2/11/09
1.170 /// Moved Free_ and similar to Finally blocks to ensure they execute.
1.171 - ///
1.172 + ///
1.173 /// V4.5
1.174 /// 2/9/09
1.175 - /// Changes to support 64-bit systems, memory management, and other corrections.
1.176 + /// Changes to support 64-bit systems, memory management, and other corrections.
1.177 /// Big thanks to Peter Nielsen.
1.178 - ///
1.179 + ///
1.180 /// </summary>
1.181
1.182 internal class FrmMain
1.183 @@ -183,7 +183,7 @@
1.184 public System.Windows.Forms.ListBox LstResults;
1.185 // NOTE: The following procedure is required by the Windows Form Designer
1.186 // It can be modified using the Windows Form Designer.
1.187 - // Do not modify it using the code editor.
1.188 + // Do not modify it using the code editor.
1.189 internal System.Windows.Forms.GroupBox fraInputReportBufferSize;
1.190 internal System.Windows.Forms.TextBox txtInputReportBufferSize;
1.191 internal System.Windows.Forms.Button cmdInputReportBufferSize;
1.192 @@ -249,9 +249,9 @@
1.193 this.fraControlTransfers.SuspendLayout();
1.194 this.fraSendAndGetContinuous.SuspendLayout();
1.195 this.SuspendLayout();
1.196 - //
1.197 + //
1.198 // fraBytesReceived
1.199 - //
1.200 + //
1.201 this.FraBytesReceived.BackColor = System.Drawing.SystemColors.Control;
1.202 this.FraBytesReceived.Controls.Add(this.TxtBytesReceived);
1.203 this.FraBytesReceived.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
1.204 @@ -263,9 +263,9 @@
1.205 this.FraBytesReceived.TabIndex = 4;
1.206 this.FraBytesReceived.TabStop = false;
1.207 this.FraBytesReceived.Text = "Bytes Received";
1.208 - //
1.209 + //
1.210 // txtBytesReceived
1.211 - //
1.212 + //
1.213 this.TxtBytesReceived.AcceptsReturn = true;
1.214 this.TxtBytesReceived.BackColor = System.Drawing.SystemColors.Window;
1.215 this.TxtBytesReceived.Cursor = System.Windows.Forms.Cursors.IBeam;
1.216 @@ -278,9 +278,9 @@
1.217 this.TxtBytesReceived.RightToLeft = System.Windows.Forms.RightToLeft.No;
1.218 this.TxtBytesReceived.Size = new System.Drawing.Size(72, 96);
1.219 this.TxtBytesReceived.TabIndex = 5;
1.220 - //
1.221 + //
1.222 // fraBytesToSend
1.223 - //
1.224 + //
1.225 this.FraBytesToSend.BackColor = System.Drawing.SystemColors.Control;
1.226 this.FraBytesToSend.Controls.Add(this.ChkAutoincrement);
1.227 this.FraBytesToSend.Controls.Add(this.CboByte1);
1.228 @@ -294,9 +294,9 @@
1.229 this.FraBytesToSend.TabIndex = 1;
1.230 this.FraBytesToSend.TabStop = false;
1.231 this.FraBytesToSend.Text = "Bytes to Send";
1.232 - //
1.233 + //
1.234 // chkAutoincrement
1.235 - //
1.236 + //
1.237 this.ChkAutoincrement.BackColor = System.Drawing.SystemColors.Control;
1.238 this.ChkAutoincrement.Cursor = System.Windows.Forms.Cursors.Default;
1.239 this.ChkAutoincrement.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
1.240 @@ -308,9 +308,9 @@
1.241 this.ChkAutoincrement.TabIndex = 6;
1.242 this.ChkAutoincrement.Text = "Autoincrement values";
1.243 this.ChkAutoincrement.UseVisualStyleBackColor = false;
1.244 - //
1.245 + //
1.246 // cboByte1
1.247 - //
1.248 + //
1.249 this.CboByte1.BackColor = System.Drawing.SystemColors.Window;
1.250 this.CboByte1.Cursor = System.Windows.Forms.Cursors.Default;
1.251 this.CboByte1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
1.252 @@ -321,9 +321,9 @@
1.253 this.CboByte1.RightToLeft = System.Windows.Forms.RightToLeft.No;
1.254 this.CboByte1.Size = new System.Drawing.Size(101, 22);
1.255 this.CboByte1.TabIndex = 3;
1.256 - //
1.257 + //
1.258 // cboByte0
1.259 - //
1.260 + //
1.261 this.CboByte0.BackColor = System.Drawing.SystemColors.Window;
1.262 this.CboByte0.Cursor = System.Windows.Forms.Cursors.Default;
1.263 this.CboByte0.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
1.264 @@ -334,9 +334,9 @@
1.265 this.CboByte0.RightToLeft = System.Windows.Forms.RightToLeft.No;
1.266 this.CboByte0.Size = new System.Drawing.Size(101, 22);
1.267 this.CboByte0.TabIndex = 2;
1.268 - //
1.269 + //
1.270 // lstResults
1.271 - //
1.272 + //
1.273 this.LstResults.BackColor = System.Drawing.SystemColors.Window;
1.274 this.LstResults.Cursor = System.Windows.Forms.Cursors.Default;
1.275 this.LstResults.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
1.276 @@ -348,9 +348,9 @@
1.277 this.LstResults.RightToLeft = System.Windows.Forms.RightToLeft.No;
1.278 this.LstResults.Size = new System.Drawing.Size(760, 326);
1.279 this.LstResults.TabIndex = 0;
1.280 - //
1.281 + //
1.282 // fraInputReportBufferSize
1.283 - //
1.284 + //
1.285 this.fraInputReportBufferSize.Controls.Add(this.cmdInputReportBufferSize);
1.286 this.fraInputReportBufferSize.Controls.Add(this.txtInputReportBufferSize);
1.287 this.fraInputReportBufferSize.Location = new System.Drawing.Point(248, 16);
1.288 @@ -359,25 +359,25 @@
1.289 this.fraInputReportBufferSize.TabIndex = 9;
1.290 this.fraInputReportBufferSize.TabStop = false;
1.291 this.fraInputReportBufferSize.Text = "Input Report Buffer Size";
1.292 - //
1.293 + //
1.294 // cmdInputReportBufferSize
1.295 - //
1.296 + //
1.297 this.cmdInputReportBufferSize.Location = new System.Drawing.Point(96, 32);
1.298 this.cmdInputReportBufferSize.Name = "cmdInputReportBufferSize";
1.299 this.cmdInputReportBufferSize.Size = new System.Drawing.Size(96, 56);
1.300 this.cmdInputReportBufferSize.TabIndex = 1;
1.301 this.cmdInputReportBufferSize.Text = "Change Buffer Size";
1.302 this.cmdInputReportBufferSize.Click += new System.EventHandler(this.cmdInputReportBufferSize_Click);
1.303 - //
1.304 + //
1.305 // txtInputReportBufferSize
1.306 - //
1.307 + //
1.308 this.txtInputReportBufferSize.Location = new System.Drawing.Point(16, 40);
1.309 this.txtInputReportBufferSize.Name = "txtInputReportBufferSize";
1.310 this.txtInputReportBufferSize.Size = new System.Drawing.Size(56, 20);
1.311 this.txtInputReportBufferSize.TabIndex = 0;
1.312 - //
1.313 + //
1.314 // fraDeviceIdentifiers
1.315 - //
1.316 + //
1.317 this.fraDeviceIdentifiers.Controls.Add(this.txtProductID);
1.318 this.fraDeviceIdentifiers.Controls.Add(this.lblProductID);
1.319 this.fraDeviceIdentifiers.Controls.Add(this.txtVendorID);
1.320 @@ -388,52 +388,52 @@
1.321 this.fraDeviceIdentifiers.TabIndex = 10;
1.322 this.fraDeviceIdentifiers.TabStop = false;
1.323 this.fraDeviceIdentifiers.Text = "Device Identifiers";
1.324 - //
1.325 + //
1.326 // txtProductID
1.327 - //
1.328 + //
1.329 this.txtProductID.Location = new System.Drawing.Point(120, 56);
1.330 this.txtProductID.Name = "txtProductID";
1.331 this.txtProductID.Size = new System.Drawing.Size(72, 20);
1.332 this.txtProductID.TabIndex = 3;
1.333 this.txtProductID.Text = "1299";
1.334 this.txtProductID.TextChanged += new System.EventHandler(this.txtProductID_TextChanged);
1.335 - //
1.336 + //
1.337 // lblProductID
1.338 - //
1.339 + //
1.340 this.lblProductID.Location = new System.Drawing.Point(16, 56);
1.341 this.lblProductID.Name = "lblProductID";
1.342 this.lblProductID.Size = new System.Drawing.Size(112, 23);
1.343 this.lblProductID.TabIndex = 2;
1.344 this.lblProductID.Text = "Product ID (hex):";
1.345 - //
1.346 + //
1.347 // txtVendorID
1.348 - //
1.349 + //
1.350 this.txtVendorID.Location = new System.Drawing.Point(120, 24);
1.351 this.txtVendorID.Name = "txtVendorID";
1.352 this.txtVendorID.Size = new System.Drawing.Size(72, 20);
1.353 this.txtVendorID.TabIndex = 1;
1.354 this.txtVendorID.Text = "0925";
1.355 this.txtVendorID.TextChanged += new System.EventHandler(this.txtVendorID_TextChanged);
1.356 - //
1.357 + //
1.358 // lblVendorID
1.359 - //
1.360 + //
1.361 this.lblVendorID.Location = new System.Drawing.Point(16, 24);
1.362 this.lblVendorID.Name = "lblVendorID";
1.363 this.lblVendorID.Size = new System.Drawing.Size(112, 23);
1.364 this.lblVendorID.TabIndex = 0;
1.365 this.lblVendorID.Text = "Vendor ID (hex):";
1.366 - //
1.367 + //
1.368 // cmdFindDevice
1.369 - //
1.370 + //
1.371 this.cmdFindDevice.Location = new System.Drawing.Point(483, 37);
1.372 this.cmdFindDevice.Name = "cmdFindDevice";
1.373 this.cmdFindDevice.Size = new System.Drawing.Size(136, 55);
1.374 this.cmdFindDevice.TabIndex = 11;
1.375 this.cmdFindDevice.Text = "Find My Device";
1.376 this.cmdFindDevice.Click += new System.EventHandler(this.cmdFindDevice_Click);
1.377 - //
1.378 + //
1.379 // cmdSendOutputReportInterrupt
1.380 - //
1.381 + //
1.382 this.cmdSendOutputReportInterrupt.Location = new System.Drawing.Point(10, 27);
1.383 this.cmdSendOutputReportInterrupt.Name = "cmdSendOutputReportInterrupt";
1.384 this.cmdSendOutputReportInterrupt.Size = new System.Drawing.Size(118, 50);
1.385 @@ -441,9 +441,9 @@
1.386 this.cmdSendOutputReportInterrupt.Text = "Send Output Report";
1.387 this.cmdSendOutputReportInterrupt.UseVisualStyleBackColor = true;
1.388 this.cmdSendOutputReportInterrupt.Click += new System.EventHandler(this.cmdSendOutputReportInterrupt_Click);
1.389 - //
1.390 + //
1.391 // cmdGetInputReportInterrupt
1.392 - //
1.393 + //
1.394 this.cmdGetInputReportInterrupt.Location = new System.Drawing.Point(10, 83);
1.395 this.cmdGetInputReportInterrupt.Name = "cmdGetInputReportInterrupt";
1.396 this.cmdGetInputReportInterrupt.Size = new System.Drawing.Size(118, 50);
1.397 @@ -451,9 +451,9 @@
1.398 this.cmdGetInputReportInterrupt.Text = "Get Input Report";
1.399 this.cmdGetInputReportInterrupt.UseVisualStyleBackColor = true;
1.400 this.cmdGetInputReportInterrupt.Click += new System.EventHandler(this.cmdGetInputReportInterrupt_Click);
1.401 - //
1.402 + //
1.403 // fraInterruptTransfers
1.404 - //
1.405 + //
1.406 this.fraInterruptTransfers.BackColor = System.Drawing.SystemColors.Control;
1.407 this.fraInterruptTransfers.Controls.Add(this.cmdSendOutputReportInterrupt);
1.408 this.fraInterruptTransfers.Controls.Add(this.cmdGetInputReportInterrupt);
1.409 @@ -466,9 +466,9 @@
1.410 this.fraInterruptTransfers.TabIndex = 14;
1.411 this.fraInterruptTransfers.TabStop = false;
1.412 this.fraInterruptTransfers.Text = "Interrupt Transfers";
1.413 - //
1.414 + //
1.415 // cmdPeriodicTransfers
1.416 - //
1.417 + //
1.418 this.cmdPeriodicTransfers.Location = new System.Drawing.Point(153, 36);
1.419 this.cmdPeriodicTransfers.Name = "cmdPeriodicTransfers";
1.420 this.cmdPeriodicTransfers.Size = new System.Drawing.Size(118, 51);
1.421 @@ -476,9 +476,9 @@
1.422 this.cmdPeriodicTransfers.Text = "Start";
1.423 this.cmdPeriodicTransfers.UseVisualStyleBackColor = true;
1.424 this.cmdPeriodicTransfers.Click += new System.EventHandler(this.cmdPeriodicTransfers_Click);
1.425 - //
1.426 + //
1.427 // cmdSendOutputReportControl
1.428 - //
1.429 + //
1.430 this.cmdSendOutputReportControl.Location = new System.Drawing.Point(10, 27);
1.431 this.cmdSendOutputReportControl.Name = "cmdSendOutputReportControl";
1.432 this.cmdSendOutputReportControl.Size = new System.Drawing.Size(118, 50);
1.433 @@ -486,9 +486,9 @@
1.434 this.cmdSendOutputReportControl.Text = "Send Output Report";
1.435 this.cmdSendOutputReportControl.UseVisualStyleBackColor = true;
1.436 this.cmdSendOutputReportControl.Click += new System.EventHandler(this.cmdSendOutputReportControl_Click);
1.437 - //
1.438 + //
1.439 // cmdGetInputReportControl
1.440 - //
1.441 + //
1.442 this.cmdGetInputReportControl.Location = new System.Drawing.Point(10, 83);
1.443 this.cmdGetInputReportControl.Name = "cmdGetInputReportControl";
1.444 this.cmdGetInputReportControl.Size = new System.Drawing.Size(118, 50);
1.445 @@ -496,9 +496,9 @@
1.446 this.cmdGetInputReportControl.Text = "Get Input Report";
1.447 this.cmdGetInputReportControl.UseVisualStyleBackColor = true;
1.448 this.cmdGetInputReportControl.Click += new System.EventHandler(this.cmdGetInputReportControl_Click);
1.449 - //
1.450 + //
1.451 // fraControlTransfers
1.452 - //
1.453 + //
1.454 this.fraControlTransfers.BackColor = System.Drawing.SystemColors.Control;
1.455 this.fraControlTransfers.Controls.Add(this.cmdGetFeatureReport);
1.456 this.fraControlTransfers.Controls.Add(this.cmdSendFeatureReport);
1.457 @@ -513,9 +513,9 @@
1.458 this.fraControlTransfers.TabIndex = 15;
1.459 this.fraControlTransfers.TabStop = false;
1.460 this.fraControlTransfers.Text = "Control Transfers";
1.461 - //
1.462 + //
1.463 // cmdGetFeatureReport
1.464 - //
1.465 + //
1.466 this.cmdGetFeatureReport.Location = new System.Drawing.Point(141, 83);
1.467 this.cmdGetFeatureReport.Name = "cmdGetFeatureReport";
1.468 this.cmdGetFeatureReport.Size = new System.Drawing.Size(118, 50);
1.469 @@ -523,9 +523,9 @@
1.470 this.cmdGetFeatureReport.Text = "Get Feature Report";
1.471 this.cmdGetFeatureReport.UseVisualStyleBackColor = true;
1.472 this.cmdGetFeatureReport.Click += new System.EventHandler(this.cmdGetFeatureReport_Click);
1.473 - //
1.474 + //
1.475 // cmdSendFeatureReport
1.476 - //
1.477 + //
1.478 this.cmdSendFeatureReport.Location = new System.Drawing.Point(141, 27);
1.479 this.cmdSendFeatureReport.Name = "cmdSendFeatureReport";
1.480 this.cmdSendFeatureReport.Size = new System.Drawing.Size(118, 50);
1.481 @@ -533,9 +533,9 @@
1.482 this.cmdSendFeatureReport.Text = "Send Feature Report";
1.483 this.cmdSendFeatureReport.UseVisualStyleBackColor = true;
1.484 this.cmdSendFeatureReport.Click += new System.EventHandler(this.cmdSendFeatureReport_Click);
1.485 - //
1.486 + //
1.487 // fraSendAndGetContinuous
1.488 - //
1.489 + //
1.490 this.fraSendAndGetContinuous.BackColor = System.Drawing.SystemColors.Control;
1.491 this.fraSendAndGetContinuous.Controls.Add(this.radFeature);
1.492 this.fraSendAndGetContinuous.Controls.Add(this.radInputOutputControl);
1.493 @@ -550,9 +550,9 @@
1.494 this.fraSendAndGetContinuous.TabIndex = 17;
1.495 this.fraSendAndGetContinuous.TabStop = false;
1.496 this.fraSendAndGetContinuous.Text = "Send and Get Continuous";
1.497 - //
1.498 + //
1.499 // radInputOutputInterrupt
1.500 - //
1.501 + //
1.502 this.radInputOutputInterrupt.AutoSize = true;
1.503 this.radInputOutputInterrupt.Location = new System.Drawing.Point(17, 28);
1.504 this.radInputOutputInterrupt.Name = "radInputOutputInterrupt";
1.505 @@ -562,9 +562,9 @@
1.506 this.radInputOutputInterrupt.Text = "Input Output Interrupt";
1.507 this.radInputOutputInterrupt.UseVisualStyleBackColor = true;
1.508 this.radInputOutputInterrupt.CheckedChanged += new System.EventHandler(this.radInputOutputInterrupt_CheckedChanged);
1.509 - //
1.510 + //
1.511 // radInputOutputControl
1.512 - //
1.513 + //
1.514 this.radInputOutputControl.AutoSize = true;
1.515 this.radInputOutputControl.Location = new System.Drawing.Point(17, 52);
1.516 this.radInputOutputControl.Name = "radInputOutputControl";
1.517 @@ -574,9 +574,9 @@
1.518 this.radInputOutputControl.Text = "Input Output Control";
1.519 this.radInputOutputControl.UseVisualStyleBackColor = true;
1.520 this.radInputOutputControl.CheckedChanged += new System.EventHandler(this.radInputOutputControl_CheckedChanged);
1.521 - //
1.522 + //
1.523 // radFeature
1.524 - //
1.525 + //
1.526 this.radFeature.AutoSize = true;
1.527 this.radFeature.Location = new System.Drawing.Point(17, 76);
1.528 this.radFeature.Name = "radFeature";
1.529 @@ -586,9 +586,9 @@
1.530 this.radFeature.Text = "Feature";
1.531 this.radFeature.UseVisualStyleBackColor = true;
1.532 this.radFeature.CheckedChanged += new System.EventHandler(this.radFeature_CheckedChanged);
1.533 - //
1.534 + //
1.535 // FrmMain
1.536 - //
1.537 + //
1.538 this.ClientSize = new System.Drawing.Size(784, 756);
1.539 this.Controls.Add(this.fraSendAndGetContinuous);
1.540 this.Controls.Add(this.fraControlTransfers);
1.541 @@ -620,7 +620,7 @@
1.542 this.ResumeLayout(false);
1.543
1.544 }
1.545 - #endregion
1.546 + #endregion '"Windows Form Designer generated code "'
1.547
1.548 private Boolean _deviceDetected;
1.549 private IntPtr _deviceNotificationHandle;
1.550 @@ -704,9 +704,9 @@
1.551 /// Performs various application-specific functions that
1.552 /// involve accessing the application's form.
1.553 /// </summary>
1.554 - ///
1.555 + ///
1.556 /// <param name="action"> a FormActions member that names the action to perform on the form</param>
1.557 - /// <param name="formText"> text that the form displays or the code uses for
1.558 + /// <param name="formText"> text that the form displays or the code uses for
1.559 /// another purpose. Actions that don't use text ignore this parameter. </param>
1.560
1.561 private void AccessForm(FormActions action, String formText)
1.562 @@ -820,7 +820,7 @@
1.563 /// <summary>
1.564 /// Close the handle and FileStreams for a device.
1.565 /// </summary>
1.566 - ///
1.567 + ///
1.568 private void CloseCommunications()
1.569 {
1.570 if (_deviceData != null)
1.571 @@ -883,7 +883,7 @@
1.572 else
1.573 {
1.574 // Don't allow another transfer request until this one completes.
1.575 - // Move the focus away from the button to prevent the focus from
1.576 + // Move the focus away from the button to prevent the focus from
1.577 // switching to the next control in the tab order on disabling the button.
1.578
1.579 fraControlTransfers.Focus();
1.580 @@ -910,7 +910,7 @@
1.581 try
1.582 {
1.583 // Don't allow another transfer request until this one completes.
1.584 - // Move the focus away from the button to prevent the focus from
1.585 + // Move the focus away from the button to prevent the focus from
1.586 // switching to the next control in the tab order on disabling the button.
1.587
1.588 if (_transferInProgress)
1.589 @@ -937,7 +937,7 @@
1.590 /// </summary>
1.591 /// <param name="sender"></param>
1.592 /// <param name="e"></param>
1.593 - ///
1.594 + ///
1.595 private void cmdGetInputReportInterrupt_Click(object sender, EventArgs e)
1.596 {
1.597 try
1.598 @@ -949,7 +949,7 @@
1.599 else
1.600 {
1.601 // Don't allow another transfer request until this one completes.
1.602 - // Move the focus away from the button to prevent the focus from
1.603 + // Move the focus away from the button to prevent the focus from
1.604 // switching to the next control in the tab order on disabling the button.
1.605
1.606 fraInterruptTransfers.Focus();
1.607 @@ -1041,7 +1041,7 @@
1.608 else
1.609 {
1.610 // Don't allow another transfer request until this one completes.
1.611 - // Move the focus away from the button to prevent the focus from
1.612 + // Move the focus away from the button to prevent the focus from
1.613 // switching to the next control in the tab order on disabling the button.
1.614
1.615 fraControlTransfers.Focus();
1.616 @@ -1062,7 +1062,7 @@
1.617 /// </summary>
1.618 /// <param name="sender"></param>
1.619 /// <param name="e"></param>
1.620 - ///
1.621 + ///
1.622 private void cmdSendOutputReportControl_Click(object sender, EventArgs e)
1.623 {
1.624 try
1.625 @@ -1074,7 +1074,7 @@
1.626 else
1.627 {
1.628 // Don't allow another transfer request until this one completes.
1.629 - // Move the focus away from the button to prevent the focus from
1.630 + // Move the focus away from the button to prevent the focus from
1.631 // switching to the next control in the tab order on disabling the button.
1.632
1.633 fraControlTransfers.Focus();
1.634 @@ -1091,7 +1091,7 @@
1.635 }
1.636
1.637 /// <summary>
1.638 - /// Request to send an Output report using an interrupt transfer.
1.639 + /// Request to send an Output report using an interrupt transfer.
1.640 /// </summary>
1.641 /// <param name="sender"></param>
1.642 /// <param name="e"></param>
1.643 @@ -1107,7 +1107,7 @@
1.644 else
1.645 {
1.646 // Don't allow another transfer request until this one completes.
1.647 - // Move the focus away from the button to prevent the focus from
1.648 + // Move the focus away from the button to prevent the focus from
1.649 // switching to the next control in the tab order on disabling the button.
1.650
1.651 fraInterruptTransfers.Focus();
1.652 @@ -1204,7 +1204,7 @@
1.653 /// Called on removal of any device.
1.654 /// Calls a routine that searches to see if the desired device is still present.
1.655 /// </summary>
1.656 - ///
1.657 + ///
1.658 private void DeviceRemoved(object sender, EventArgs e)
1.659 {
1.660 try
1.661 @@ -1229,8 +1229,8 @@
1.662 /// <summary>
1.663 /// Displays received or written report data.
1.664 /// </summary>
1.665 - ///
1.666 - /// <param name="buffer"> contains the report data. </param>
1.667 + ///
1.668 + /// <param name="buffer"> contains the report data. </param>
1.669 /// <param name="currentReportType" > "Input", "Output", or "Feature"</param>
1.670 /// <param name="currentReadOrWritten" > "read" for Input and IN Feature reports, "written" for Output and OUT Feature reports.</param>
1.671
1.672 @@ -1274,7 +1274,7 @@
1.673 /// <summary>
1.674 /// Display a message if the user clicks a button when a transfer is in progress.
1.675 /// </summary>
1.676 - ///
1.677 + ///
1.678 private void DisplayTransferInProgressMessage()
1.679 {
1.680 AccessForm(FormActions.AddItemToListBox, "Command not executed because a transfer is in progress.");
1.681 @@ -1288,7 +1288,7 @@
1.682 /// <param name="e"></param>
1.683 /// <remarks>
1.684 /// The timer is enabled only if continuous (periodic) transfers have been requested.
1.685 - /// </remarks>
1.686 + /// </remarks>
1.687
1.688 private void DoPeriodicTransfers(object source, ElapsedEventArgs e)
1.689 {
1.690 @@ -1307,7 +1307,7 @@
1.691 /// Enable the command buttons on the form.
1.692 /// Needed after attempting a transfer and device not found.
1.693 /// </summary>
1.694 - ///
1.695 + ///
1.696 private void EnableFormControls()
1.697 {
1.698 cmdGetInputReportInterrupt.Enabled = true;
1.699 @@ -1322,9 +1322,9 @@
1.700 /// <summary>
1.701 /// Use the System.Management class to find a device by Vendor ID and Product ID using WMI. If found, display device properties.
1.702 /// </summary>
1.703 - /// <remarks>
1.704 + /// <remarks>
1.705 /// During debugging, if you stop the firmware but leave the device attached, the device may still be detected as present
1.706 - /// but will be unable to communicate. The device will show up in Windows Device Manager as well.
1.707 + /// but will be unable to communicate. The device will show up in Windows Device Manager as well.
1.708 /// This situation is unlikely to occur with a final product.
1.709 /// </remarks>
1.710
1.711 @@ -1338,26 +1338,45 @@
1.712
1.713 _deviceDetected = false;
1.714 var searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_PnPEntity");
1.715 + int usbDeviceCounter = 0;
1.716
1.717 foreach (ManagementObject queryObj in searcher.Get())
1.718 {
1.719 - if (queryObj["PNPDeviceID"].ToString().Contains(deviceIdString))
1.720 - {
1.721 - _deviceDetected = true;
1.722 - MyMarshalDataToForm(FormActions.AddItemToListBox, "--------");
1.723 - MyMarshalDataToForm(FormActions.AddItemToListBox, "My device found (WMI):");
1.724 + string deviceId = queryObj["PNPDeviceID"].ToString();
1.725 + if (deviceId.Contains(deviceIdString))
1.726 + {
1.727 + usbDeviceCounter++;
1.728 + _deviceDetected = true;
1.729 + MyMarshalDataToForm(FormActions.AddItemToListBox, "--------");
1.730 + MyMarshalDataToForm(FormActions.AddItemToListBox, "My device found (WMI):");
1.731
1.732 - // Display device properties.
1.733 + // Display device properties.
1.734
1.735 - foreach (WmiDeviceProperties wmiDeviceProperty in Enum.GetValues(typeof(WmiDeviceProperties)))
1.736 - {
1.737 - MyMarshalDataToForm(FormActions.AddItemToListBox, (wmiDeviceProperty.ToString() + ": " + queryObj[wmiDeviceProperty.ToString()]));
1.738 - Debug.WriteLine(wmiDeviceProperty.ToString() + ": {0}", queryObj[wmiDeviceProperty.ToString()]);
1.739 - }
1.740 - MyMarshalDataToForm(FormActions.AddItemToListBox, "--------");
1.741 - MyMarshalDataToForm(FormActions.ScrollToBottomOfListBox, "");
1.742 - }
1.743 + foreach (WmiDeviceProperties wmiDeviceProperty in Enum.GetValues(typeof(WmiDeviceProperties)))
1.744 + {
1.745 + MyMarshalDataToForm(FormActions.AddItemToListBox, (wmiDeviceProperty.ToString() + ": " + queryObj[wmiDeviceProperty.ToString()]));
1.746 + Debug.WriteLine(wmiDeviceProperty.ToString() + ": {0}", queryObj[wmiDeviceProperty.ToString()]);
1.747 + }
1.748 + MyMarshalDataToForm(FormActions.AddItemToListBox, "--------");
1.749 + MyMarshalDataToForm(FormActions.ScrollToBottomOfListBox, "");
1.750 + }
1.751 + else if (deviceId.StartsWith("USB\\"))
1.752 + {
1.753 + usbDeviceCounter++;
1.754 + MyMarshalDataToForm(FormActions.AddItemToListBox, "--------");
1.755 + MyMarshalDataToForm(FormActions.AddItemToListBox, "Skipping device:" + deviceId);
1.756 + foreach (WmiDeviceProperties wmiDeviceProperty in Enum.GetValues(typeof(WmiDeviceProperties)))
1.757 + {
1.758 + MyMarshalDataToForm(FormActions.AddItemToListBox, (wmiDeviceProperty.ToString() + ": " + queryObj[wmiDeviceProperty.ToString()]));
1.759 + Debug.WriteLine(wmiDeviceProperty.ToString() + ": {0}", queryObj[wmiDeviceProperty.ToString()]);
1.760 + }
1.761 + MyMarshalDataToForm(FormActions.AddItemToListBox, "--------");
1.762 + MyMarshalDataToForm(FormActions.ScrollToBottomOfListBox, "");
1.763 + }
1.764 }
1.765 +
1.766 + MyMarshalDataToForm(FormActions.AddItemToListBox, "Found " + usbDeviceCounter /*searcher.Get().Count*/ + " USB HID devices");
1.767 +
1.768 if (!_deviceDetected)
1.769 {
1.770 MyMarshalDataToForm(FormActions.AddItemToListBox, "My device not found (WMI)");
1.771 @@ -1376,7 +1395,7 @@
1.772 /// Call HID functions that use Win32 API functions to locate a HID-class device
1.773 /// by its Vendor ID and Product ID. Open a handle to the device.
1.774 /// </summary>
1.775 - ///
1.776 + ///
1.777 /// <returns>
1.778 /// True if the device is detected, False if not detected.
1.779 /// </returns>
1.780 @@ -1426,7 +1445,7 @@
1.781
1.782 if (!_hidHandle.IsInvalid)
1.783 {
1.784 - // The returned handle is valid,
1.785 + // The returned handle is valid,
1.786 // so find out if this is the device we're looking for.
1.787
1.788 _myHid.DeviceAttributes.Size = Marshal.SizeOf(_myHid.DeviceAttributes);
1.789 @@ -1514,7 +1533,7 @@
1.790 {
1.791 if (_myHid.Capabilities.InputReportByteLength > 0)
1.792 {
1.793 - // Set the size of the Input report buffer.
1.794 + // Set the size of the Input report buffer.
1.795
1.796 var inputReportBuffer = new Byte[_myHid.Capabilities.InputReportByteLength];
1.797
1.798 @@ -1617,7 +1636,7 @@
1.799
1.800 /// <summary>
1.801 /// Find and display the number of Input buffers
1.802 - /// (the number of Input reports the HID driver will store).
1.803 + /// (the number of Input reports the HID driver will store).
1.804 /// </summary>
1.805
1.806 private void GetInputReportBufferSize()
1.807 @@ -1643,10 +1662,10 @@
1.808 }
1.809
1.810 /// <summary>
1.811 - /// Retrieve a Vendor ID and Product ID in hexadecimal
1.812 + /// Retrieve a Vendor ID and Product ID in hexadecimal
1.813 /// from the form's text boxes and convert the text to Int32s.
1.814 /// </summary>
1.815 - ///
1.816 + ///
1.817 /// <param name="myVendorId"> the Vendor ID</param>
1.818 /// <param name="myProductId"> the Product ID</param>
1.819
1.820 @@ -1712,11 +1731,11 @@
1.821 }
1.822
1.823 /// <summary>
1.824 - /// Enables accessing a form's controls from another thread
1.825 + /// Enables accessing a form's controls from another thread
1.826 /// </summary>
1.827 - ///
1.828 + ///
1.829 /// <param name="action"> a FormActions member that names the action to perform on the form </param>
1.830 - /// <param name="textToDisplay"> text that the form displays or the code uses for
1.831 + /// <param name="textToDisplay"> text that the form displays or the code uses for
1.832 /// another purpose. Actions that don't use text ignore this parameter. </param>
1.833
1.834 private void MyMarshalDataToForm(FormActions action, String textToDisplay)
1.835 @@ -1876,7 +1895,7 @@
1.836
1.837 _periodicTransfersRequested = false;
1.838
1.839 - // Disable the timer that triggers the transfers.
1.840 + // Disable the timer that triggers the transfers.
1.841
1.842 _periodicTransfers.Stop();
1.843 cmdPeriodicTransfers.Enabled = true;
1.844 @@ -1929,10 +1948,10 @@
1.845
1.846 if ((_myHid.Capabilities.FeatureReportByteLength > 0))
1.847 {
1.848 - // The HID has a Feature report.
1.849 + // The HID has a Feature report.
1.850 // Read a report from the device.
1.851
1.852 - // Set the size of the Feature report buffer.
1.853 + // Set the size of the Feature report buffer.
1.854
1.855 if ((_myHid.Capabilities.FeatureReportByteLength > 0))
1.856 {
1.857 @@ -2009,7 +2028,7 @@
1.858
1.859 if (_myHid.Capabilities.InputReportByteLength > 0)
1.860 {
1.861 - // Set the size of the Input report buffer.
1.862 + // Set the size of the Input report buffer.
1.863
1.864 inputReportBuffer = new Byte[_myHid.Capabilities.InputReportByteLength];
1.865
1.866 @@ -2030,9 +2049,9 @@
1.867 {
1.868 _transferInProgress = true;
1.869
1.870 - // Read a report using interrupt transfers.
1.871 + // Read a report using interrupt transfers.
1.872 // Timeout if no report available.
1.873 - // To enable reading a report without blocking the calling thread, uses Filestream's ReadAsync method.
1.874 + // To enable reading a report without blocking the calling thread, uses Filestream's ReadAsync method.
1.875
1.876 // Create a delegate to execute on a timeout.
1.877
1.878 @@ -2056,7 +2075,7 @@
1.879
1.880 // Arrive here only if the operation completed.
1.881
1.882 - // Dispose to stop the timeout timer.
1.883 + // Dispose to stop the timeout timer.
1.884
1.885 cts.Dispose();
1.886
1.887 @@ -2096,7 +2115,6 @@
1.888 }
1.889 }
1.890 }
1.891 -
1.892 catch (Exception ex)
1.893 {
1.894 DisplayException(Name, ex);
1.895 @@ -2132,7 +2150,7 @@
1.896 if ((_myHid.Capabilities.FeatureReportByteLength > 0))
1.897 {
1.898 // The HID has a Feature report.
1.899 - // Set the size of the Feature report buffer.
1.900 + // Set the size of the Feature report buffer.
1.901
1.902 var outFeatureReportBuffer = new Byte[_myHid.Capabilities.FeatureReportByteLength];
1.903
1.904 @@ -2165,7 +2183,6 @@
1.905 ScrollToBottomOfListBox();
1.906 }
1.907 }
1.908 -
1.909 else
1.910 {
1.911 AccessForm(FormActions.AddItemToListBox, "The HID doesn't have a Feature report.");
1.912 @@ -2218,7 +2235,7 @@
1.913
1.914 if (_myHid.Capabilities.OutputReportByteLength > 0)
1.915 {
1.916 - // Set the size of the Output report buffer.
1.917 + // Set the size of the Output report buffer.
1.918
1.919 var outputReportBuffer = new Byte[_myHid.Capabilities.OutputReportByteLength];
1.920
1.921 @@ -2305,7 +2322,6 @@
1.922 AccessForm(FormActions.AddItemToListBox, "The HID doesn't have an Output report.");
1.923 }
1.924 }
1.925 -
1.926 catch (Exception ex)
1.927 {
1.928 DisplayException(Name, ex);
1.929 @@ -2417,7 +2433,7 @@
1.930 }
1.931
1.932 /// <summary>
1.933 - /// Set the number of Input buffers (the number of Input reports
1.934 + /// Set the number of Input buffers (the number of Input reports
1.935 /// the host will store) from the value in the text box.
1.936 /// </summary>
1.937
1.938 @@ -2542,7 +2558,7 @@
1.939 /// Provides a central mechanism for exception handling.
1.940 /// Displays a message box that describes the exception.
1.941 /// </summary>
1.942 - ///
1.943 + ///
1.944 /// <param name="moduleName"> the module where the exception occurred. </param>
1.945 /// <param name="e"> the exception </param>
1.946
1.947 @@ -2557,7 +2573,7 @@
1.948 MessageBox.Show(message, caption, MessageBoxButtons.OK);
1.949 Debug.Write(message);
1.950
1.951 - // Get the last error and display it.
1.952 + // Get the last error and display it.
1.953
1.954 Int32 error = Marshal.GetLastWin32Error();
1.955