# HG changeset patch
# User sl
# Date 1400047075 -7200
# Node ID 5f7e2c772e63c47248cebac4646d2fdca81e723b
# Parent 29c8c6738077ba2eb49aa3316f0de820d04faa4d
Adding log s to display all our HID devices.
diff -r 29c8c6738077 -r 5f7e2c772e63 FrmMain.cs
--- a/FrmMain.cs Wed May 14 07:53:47 2014 +0200
+++ b/FrmMain.cs Wed May 14 07:57:55 2014 +0200
@@ -13,16 +13,16 @@
{
///
/// Project: GenericHid
- ///
+ ///
/// ***********************************************************************
/// Software License Agreement
///
- /// Licensor grants any person obtaining a copy of this software ("You")
- /// a worldwide, royalty-free, non-exclusive license, for the duration of
- /// the copyright, free of charge, to store and execute the Software in a
- /// computer system and to incorporate the Software or any portion of it
- /// in computer programs You write.
- ///
+ /// Licensor grants any person obtaining a copy of this software ("You")
+ /// a worldwide, royalty-free, non-exclusive license, for the duration of
+ /// the copyright, free of charge, to store and execute the Software in a
+ /// computer system and to incorporate the Software or any portion of it
+ /// in computer programs You write.
+ ///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -31,52 +31,52 @@
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
/// ***********************************************************************
- ///
- /// Author
- /// Jan Axelson
- ///
+ ///
+ /// Author
+ /// Jan Axelson
+ ///
/// This software was written using Visual Studio Express 2012 for Windows
/// Desktop building for the .NET Framework v4.5.
- ///
- /// Purpose:
+ ///
+ /// Purpose:
/// Demonstrates USB communications with a generic HID-class device
- ///
+ ///
/// Requirements:
/// Windows Vista or later and an attached USB generic Human Interface Device (HID).
- /// (Does not run on Windows XP or earlier because .NET Framework 4.5 will not install on these OSes.)
- ///
+ /// (Does not run on Windows XP or earlier because .NET Framework 4.5 will not install on these OSes.)
+ ///
/// Description:
- /// Finds an attached device that matches the vendor and product IDs in the form's
+ /// Finds an attached device that matches the vendor and product IDs in the form's
/// text boxes.
- ///
+ ///
/// Retrieves the device's capabilities.
/// Sends and requests HID reports.
- ///
- /// Uses the System.Management class and Windows Management Instrumentation (WMI) to detect
+ ///
+ /// Uses the System.Management class and Windows Management Instrumentation (WMI) to detect
/// when a device is attached or removed.
- ///
+ ///
/// A list box displays the data sent and received along with error and status messages.
/// You can select data to send and 1-time or periodic transfers.
- ///
+ ///
/// You can change the size of the host's Input report buffer and request to use control
/// transfers only to exchange Input and Output reports.
- ///
+ ///
/// To view additional debugging messages, in the Visual Studio development environment,
- /// from the main menu, select Build > Configuration Manager > Active Solution Configuration
+ /// from the main menu, select Build > Configuration Manager > Active Solution Configuration
/// and select Configuration > Debug and from the main menu, select View > Output.
- ///
- /// The application uses asynchronous FileStreams to read Input reports and write Output
- /// reports so the application's main thread doesn't have to wait for the device to retrieve a
- /// report when the HID driver's buffer is empty or send a report when the device's endpoint is busy.
- ///
+ ///
+ /// The application uses asynchronous FileStreams to read Input reports and write Output
+ /// reports so the application's main thread doesn't have to wait for the device to retrieve a
+ /// report when the HID driver's buffer is empty or send a report when the device's endpoint is busy.
+ ///
/// For code that finds a device and opens handles to it, see the FindTheHid routine in frmMain.cs.
- /// For code that reads from the device, see GetInputReportViaInterruptTransfer,
+ /// For code that reads from the device, see GetInputReportViaInterruptTransfer,
/// GetInputReportViaControlTransfer, and GetFeatureReport in Hid.cs.
- /// For code that writes to the device, see SendInputReportViaInterruptTransfer,
+ /// For code that writes to the device, see SendInputReportViaInterruptTransfer,
/// SendInputReportViaControlTransfer, and SendFeatureReport in Hid.cs.
- ///
+ ///
/// This project includes the following modules:
- ///
+ ///
/// GenericHid.cs - runs the application.
/// FrmMain.cs - routines specific to the form.
/// Hid.cs - routines specific to HID communications.
@@ -86,31 +86,31 @@
/// FileIODeclarations.cs - Declarations for file-related API functions.
/// DeviceManagementDeclarations.cs - Declarations for API functions used by DeviceManagement.cs.
/// DebuggingDeclarations.cs - Declarations for API functions used by Debugging.cs.
- ///
+ ///
/// Companion device firmware for several device CPUs is available from www.Lvr.com/hidpage.htm
/// You can use any generic HID (not a system mouse or keyboard) that sends and receives reports.
/// This application will not detect or communicate with non-HID-class devices.
- ///
+ ///
/// For more information about HIDs and USB, and additional example device firmware to use
- /// with this application, visit Lakeview Research at http://Lvr.com
- /// Send comments, bug reports, etc. to jan@Lvr.com or post on my PORTS forum: http://www.lvr.com/forum
- ///
+ /// with this application, visit Lakeview Research at http://Lvr.com
+ /// Send comments, bug reports, etc. to jan@Lvr.com or post on my PORTS forum: http://www.lvr.com/forum
+ ///
/// V6.2
/// 11/12/13
/// Disabled form buttons when a transfer is in progress.
/// Other minor edits for clarity and readability.
/// Will NOT run on Windows XP or earlier, see below.
- ///
+ ///
/// V6.1
/// 10/28/13
/// Uses the .NET System.Management class to detect device arrival and removal with WMI instead of Win32 RegisterDeviceNotification.
/// Other minor edits.
/// Will NOT run on Windows XP or earlier, see below.
- ///
+ ///
/// V6.0
/// 2/8/13
/// This version will NOT run on Windows XP or earlier because the code uses .NET Framework 4.5 to support asynchronous FileStreams.
- /// The .NET Framework 4.5 redistributable is compatible with Windows 8, Windows 7 SP1, Windows Server 2008 R2 SP1,
+ /// The .NET Framework 4.5 redistributable is compatible with Windows 8, Windows 7 SP1, Windows Server 2008 R2 SP1,
/// Windows Server 2008 SP2, Windows Vista SP2, and Windows Vista SP3.
/// For compatibility, replaced ToInt32 with ToInt64 here:
/// IntPtr pDevicePathName = new IntPtr(detailDataBuffer.ToInt64() + 4);
@@ -122,13 +122,13 @@
/// Revised user interface for more flexibility.
/// Moved interrupt-transfer and other HID-specific code to Hid.cs.
/// Used JetBrains ReSharper to clean up the code: http://www.jetbrains.com/resharper/
- ///
+ ///
/// V5.0
/// 3/30/11
/// Replaced ReadFile and WriteFile with FileStreams. Thanks to Joe Dunne and John on my Ports forum for tips on this.
/// Simplified Hid.cs.
/// Replaced the form timer with a system timer.
- ///
+ ///
/// V4.6
/// 1/12/10
/// Supports Vendor IDs and Product IDs up to FFFFh.
@@ -136,16 +136,16 @@
/// V4.52
/// 11/10/09
/// Changed HIDD_ATTRIBUTES to use UInt16
- ///
+ ///
/// V4.51
/// 2/11/09
/// Moved Free_ and similar to Finally blocks to ensure they execute.
- ///
+ ///
/// V4.5
/// 2/9/09
- /// Changes to support 64-bit systems, memory management, and other corrections.
+ /// Changes to support 64-bit systems, memory management, and other corrections.
/// Big thanks to Peter Nielsen.
- ///
+ ///
///
internal class FrmMain
@@ -183,7 +183,7 @@
public System.Windows.Forms.ListBox LstResults;
// NOTE: The following procedure is required by the Windows Form Designer
// It can be modified using the Windows Form Designer.
- // Do not modify it using the code editor.
+ // Do not modify it using the code editor.
internal System.Windows.Forms.GroupBox fraInputReportBufferSize;
internal System.Windows.Forms.TextBox txtInputReportBufferSize;
internal System.Windows.Forms.Button cmdInputReportBufferSize;
@@ -249,9 +249,9 @@
this.fraControlTransfers.SuspendLayout();
this.fraSendAndGetContinuous.SuspendLayout();
this.SuspendLayout();
- //
+ //
// fraBytesReceived
- //
+ //
this.FraBytesReceived.BackColor = System.Drawing.SystemColors.Control;
this.FraBytesReceived.Controls.Add(this.TxtBytesReceived);
this.FraBytesReceived.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
@@ -263,9 +263,9 @@
this.FraBytesReceived.TabIndex = 4;
this.FraBytesReceived.TabStop = false;
this.FraBytesReceived.Text = "Bytes Received";
- //
+ //
// txtBytesReceived
- //
+ //
this.TxtBytesReceived.AcceptsReturn = true;
this.TxtBytesReceived.BackColor = System.Drawing.SystemColors.Window;
this.TxtBytesReceived.Cursor = System.Windows.Forms.Cursors.IBeam;
@@ -278,9 +278,9 @@
this.TxtBytesReceived.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.TxtBytesReceived.Size = new System.Drawing.Size(72, 96);
this.TxtBytesReceived.TabIndex = 5;
- //
+ //
// fraBytesToSend
- //
+ //
this.FraBytesToSend.BackColor = System.Drawing.SystemColors.Control;
this.FraBytesToSend.Controls.Add(this.ChkAutoincrement);
this.FraBytesToSend.Controls.Add(this.CboByte1);
@@ -294,9 +294,9 @@
this.FraBytesToSend.TabIndex = 1;
this.FraBytesToSend.TabStop = false;
this.FraBytesToSend.Text = "Bytes to Send";
- //
+ //
// chkAutoincrement
- //
+ //
this.ChkAutoincrement.BackColor = System.Drawing.SystemColors.Control;
this.ChkAutoincrement.Cursor = System.Windows.Forms.Cursors.Default;
this.ChkAutoincrement.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
@@ -308,9 +308,9 @@
this.ChkAutoincrement.TabIndex = 6;
this.ChkAutoincrement.Text = "Autoincrement values";
this.ChkAutoincrement.UseVisualStyleBackColor = false;
- //
+ //
// cboByte1
- //
+ //
this.CboByte1.BackColor = System.Drawing.SystemColors.Window;
this.CboByte1.Cursor = System.Windows.Forms.Cursors.Default;
this.CboByte1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
@@ -321,9 +321,9 @@
this.CboByte1.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.CboByte1.Size = new System.Drawing.Size(101, 22);
this.CboByte1.TabIndex = 3;
- //
+ //
// cboByte0
- //
+ //
this.CboByte0.BackColor = System.Drawing.SystemColors.Window;
this.CboByte0.Cursor = System.Windows.Forms.Cursors.Default;
this.CboByte0.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
@@ -334,9 +334,9 @@
this.CboByte0.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.CboByte0.Size = new System.Drawing.Size(101, 22);
this.CboByte0.TabIndex = 2;
- //
+ //
// lstResults
- //
+ //
this.LstResults.BackColor = System.Drawing.SystemColors.Window;
this.LstResults.Cursor = System.Windows.Forms.Cursors.Default;
this.LstResults.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
@@ -348,9 +348,9 @@
this.LstResults.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.LstResults.Size = new System.Drawing.Size(760, 326);
this.LstResults.TabIndex = 0;
- //
+ //
// fraInputReportBufferSize
- //
+ //
this.fraInputReportBufferSize.Controls.Add(this.cmdInputReportBufferSize);
this.fraInputReportBufferSize.Controls.Add(this.txtInputReportBufferSize);
this.fraInputReportBufferSize.Location = new System.Drawing.Point(248, 16);
@@ -359,25 +359,25 @@
this.fraInputReportBufferSize.TabIndex = 9;
this.fraInputReportBufferSize.TabStop = false;
this.fraInputReportBufferSize.Text = "Input Report Buffer Size";
- //
+ //
// cmdInputReportBufferSize
- //
+ //
this.cmdInputReportBufferSize.Location = new System.Drawing.Point(96, 32);
this.cmdInputReportBufferSize.Name = "cmdInputReportBufferSize";
this.cmdInputReportBufferSize.Size = new System.Drawing.Size(96, 56);
this.cmdInputReportBufferSize.TabIndex = 1;
this.cmdInputReportBufferSize.Text = "Change Buffer Size";
this.cmdInputReportBufferSize.Click += new System.EventHandler(this.cmdInputReportBufferSize_Click);
- //
+ //
// txtInputReportBufferSize
- //
+ //
this.txtInputReportBufferSize.Location = new System.Drawing.Point(16, 40);
this.txtInputReportBufferSize.Name = "txtInputReportBufferSize";
this.txtInputReportBufferSize.Size = new System.Drawing.Size(56, 20);
this.txtInputReportBufferSize.TabIndex = 0;
- //
+ //
// fraDeviceIdentifiers
- //
+ //
this.fraDeviceIdentifiers.Controls.Add(this.txtProductID);
this.fraDeviceIdentifiers.Controls.Add(this.lblProductID);
this.fraDeviceIdentifiers.Controls.Add(this.txtVendorID);
@@ -388,52 +388,52 @@
this.fraDeviceIdentifiers.TabIndex = 10;
this.fraDeviceIdentifiers.TabStop = false;
this.fraDeviceIdentifiers.Text = "Device Identifiers";
- //
+ //
// txtProductID
- //
+ //
this.txtProductID.Location = new System.Drawing.Point(120, 56);
this.txtProductID.Name = "txtProductID";
this.txtProductID.Size = new System.Drawing.Size(72, 20);
this.txtProductID.TabIndex = 3;
this.txtProductID.Text = "1299";
this.txtProductID.TextChanged += new System.EventHandler(this.txtProductID_TextChanged);
- //
+ //
// lblProductID
- //
+ //
this.lblProductID.Location = new System.Drawing.Point(16, 56);
this.lblProductID.Name = "lblProductID";
this.lblProductID.Size = new System.Drawing.Size(112, 23);
this.lblProductID.TabIndex = 2;
this.lblProductID.Text = "Product ID (hex):";
- //
+ //
// txtVendorID
- //
+ //
this.txtVendorID.Location = new System.Drawing.Point(120, 24);
this.txtVendorID.Name = "txtVendorID";
this.txtVendorID.Size = new System.Drawing.Size(72, 20);
this.txtVendorID.TabIndex = 1;
this.txtVendorID.Text = "0925";
this.txtVendorID.TextChanged += new System.EventHandler(this.txtVendorID_TextChanged);
- //
+ //
// lblVendorID
- //
+ //
this.lblVendorID.Location = new System.Drawing.Point(16, 24);
this.lblVendorID.Name = "lblVendorID";
this.lblVendorID.Size = new System.Drawing.Size(112, 23);
this.lblVendorID.TabIndex = 0;
this.lblVendorID.Text = "Vendor ID (hex):";
- //
+ //
// cmdFindDevice
- //
+ //
this.cmdFindDevice.Location = new System.Drawing.Point(483, 37);
this.cmdFindDevice.Name = "cmdFindDevice";
this.cmdFindDevice.Size = new System.Drawing.Size(136, 55);
this.cmdFindDevice.TabIndex = 11;
this.cmdFindDevice.Text = "Find My Device";
this.cmdFindDevice.Click += new System.EventHandler(this.cmdFindDevice_Click);
- //
+ //
// cmdSendOutputReportInterrupt
- //
+ //
this.cmdSendOutputReportInterrupt.Location = new System.Drawing.Point(10, 27);
this.cmdSendOutputReportInterrupt.Name = "cmdSendOutputReportInterrupt";
this.cmdSendOutputReportInterrupt.Size = new System.Drawing.Size(118, 50);
@@ -441,9 +441,9 @@
this.cmdSendOutputReportInterrupt.Text = "Send Output Report";
this.cmdSendOutputReportInterrupt.UseVisualStyleBackColor = true;
this.cmdSendOutputReportInterrupt.Click += new System.EventHandler(this.cmdSendOutputReportInterrupt_Click);
- //
+ //
// cmdGetInputReportInterrupt
- //
+ //
this.cmdGetInputReportInterrupt.Location = new System.Drawing.Point(10, 83);
this.cmdGetInputReportInterrupt.Name = "cmdGetInputReportInterrupt";
this.cmdGetInputReportInterrupt.Size = new System.Drawing.Size(118, 50);
@@ -451,9 +451,9 @@
this.cmdGetInputReportInterrupt.Text = "Get Input Report";
this.cmdGetInputReportInterrupt.UseVisualStyleBackColor = true;
this.cmdGetInputReportInterrupt.Click += new System.EventHandler(this.cmdGetInputReportInterrupt_Click);
- //
+ //
// fraInterruptTransfers
- //
+ //
this.fraInterruptTransfers.BackColor = System.Drawing.SystemColors.Control;
this.fraInterruptTransfers.Controls.Add(this.cmdSendOutputReportInterrupt);
this.fraInterruptTransfers.Controls.Add(this.cmdGetInputReportInterrupt);
@@ -466,9 +466,9 @@
this.fraInterruptTransfers.TabIndex = 14;
this.fraInterruptTransfers.TabStop = false;
this.fraInterruptTransfers.Text = "Interrupt Transfers";
- //
+ //
// cmdPeriodicTransfers
- //
+ //
this.cmdPeriodicTransfers.Location = new System.Drawing.Point(153, 36);
this.cmdPeriodicTransfers.Name = "cmdPeriodicTransfers";
this.cmdPeriodicTransfers.Size = new System.Drawing.Size(118, 51);
@@ -476,9 +476,9 @@
this.cmdPeriodicTransfers.Text = "Start";
this.cmdPeriodicTransfers.UseVisualStyleBackColor = true;
this.cmdPeriodicTransfers.Click += new System.EventHandler(this.cmdPeriodicTransfers_Click);
- //
+ //
// cmdSendOutputReportControl
- //
+ //
this.cmdSendOutputReportControl.Location = new System.Drawing.Point(10, 27);
this.cmdSendOutputReportControl.Name = "cmdSendOutputReportControl";
this.cmdSendOutputReportControl.Size = new System.Drawing.Size(118, 50);
@@ -486,9 +486,9 @@
this.cmdSendOutputReportControl.Text = "Send Output Report";
this.cmdSendOutputReportControl.UseVisualStyleBackColor = true;
this.cmdSendOutputReportControl.Click += new System.EventHandler(this.cmdSendOutputReportControl_Click);
- //
+ //
// cmdGetInputReportControl
- //
+ //
this.cmdGetInputReportControl.Location = new System.Drawing.Point(10, 83);
this.cmdGetInputReportControl.Name = "cmdGetInputReportControl";
this.cmdGetInputReportControl.Size = new System.Drawing.Size(118, 50);
@@ -496,9 +496,9 @@
this.cmdGetInputReportControl.Text = "Get Input Report";
this.cmdGetInputReportControl.UseVisualStyleBackColor = true;
this.cmdGetInputReportControl.Click += new System.EventHandler(this.cmdGetInputReportControl_Click);
- //
+ //
// fraControlTransfers
- //
+ //
this.fraControlTransfers.BackColor = System.Drawing.SystemColors.Control;
this.fraControlTransfers.Controls.Add(this.cmdGetFeatureReport);
this.fraControlTransfers.Controls.Add(this.cmdSendFeatureReport);
@@ -513,9 +513,9 @@
this.fraControlTransfers.TabIndex = 15;
this.fraControlTransfers.TabStop = false;
this.fraControlTransfers.Text = "Control Transfers";
- //
+ //
// cmdGetFeatureReport
- //
+ //
this.cmdGetFeatureReport.Location = new System.Drawing.Point(141, 83);
this.cmdGetFeatureReport.Name = "cmdGetFeatureReport";
this.cmdGetFeatureReport.Size = new System.Drawing.Size(118, 50);
@@ -523,9 +523,9 @@
this.cmdGetFeatureReport.Text = "Get Feature Report";
this.cmdGetFeatureReport.UseVisualStyleBackColor = true;
this.cmdGetFeatureReport.Click += new System.EventHandler(this.cmdGetFeatureReport_Click);
- //
+ //
// cmdSendFeatureReport
- //
+ //
this.cmdSendFeatureReport.Location = new System.Drawing.Point(141, 27);
this.cmdSendFeatureReport.Name = "cmdSendFeatureReport";
this.cmdSendFeatureReport.Size = new System.Drawing.Size(118, 50);
@@ -533,9 +533,9 @@
this.cmdSendFeatureReport.Text = "Send Feature Report";
this.cmdSendFeatureReport.UseVisualStyleBackColor = true;
this.cmdSendFeatureReport.Click += new System.EventHandler(this.cmdSendFeatureReport_Click);
- //
+ //
// fraSendAndGetContinuous
- //
+ //
this.fraSendAndGetContinuous.BackColor = System.Drawing.SystemColors.Control;
this.fraSendAndGetContinuous.Controls.Add(this.radFeature);
this.fraSendAndGetContinuous.Controls.Add(this.radInputOutputControl);
@@ -550,9 +550,9 @@
this.fraSendAndGetContinuous.TabIndex = 17;
this.fraSendAndGetContinuous.TabStop = false;
this.fraSendAndGetContinuous.Text = "Send and Get Continuous";
- //
+ //
// radInputOutputInterrupt
- //
+ //
this.radInputOutputInterrupt.AutoSize = true;
this.radInputOutputInterrupt.Location = new System.Drawing.Point(17, 28);
this.radInputOutputInterrupt.Name = "radInputOutputInterrupt";
@@ -562,9 +562,9 @@
this.radInputOutputInterrupt.Text = "Input Output Interrupt";
this.radInputOutputInterrupt.UseVisualStyleBackColor = true;
this.radInputOutputInterrupt.CheckedChanged += new System.EventHandler(this.radInputOutputInterrupt_CheckedChanged);
- //
+ //
// radInputOutputControl
- //
+ //
this.radInputOutputControl.AutoSize = true;
this.radInputOutputControl.Location = new System.Drawing.Point(17, 52);
this.radInputOutputControl.Name = "radInputOutputControl";
@@ -574,9 +574,9 @@
this.radInputOutputControl.Text = "Input Output Control";
this.radInputOutputControl.UseVisualStyleBackColor = true;
this.radInputOutputControl.CheckedChanged += new System.EventHandler(this.radInputOutputControl_CheckedChanged);
- //
+ //
// radFeature
- //
+ //
this.radFeature.AutoSize = true;
this.radFeature.Location = new System.Drawing.Point(17, 76);
this.radFeature.Name = "radFeature";
@@ -586,9 +586,9 @@
this.radFeature.Text = "Feature";
this.radFeature.UseVisualStyleBackColor = true;
this.radFeature.CheckedChanged += new System.EventHandler(this.radFeature_CheckedChanged);
- //
+ //
// FrmMain
- //
+ //
this.ClientSize = new System.Drawing.Size(784, 756);
this.Controls.Add(this.fraSendAndGetContinuous);
this.Controls.Add(this.fraControlTransfers);
@@ -620,7 +620,7 @@
this.ResumeLayout(false);
}
- #endregion
+ #endregion '"Windows Form Designer generated code "'
private Boolean _deviceDetected;
private IntPtr _deviceNotificationHandle;
@@ -704,9 +704,9 @@
/// Performs various application-specific functions that
/// involve accessing the application's form.
///
- ///
+ ///
/// a FormActions member that names the action to perform on the form
- /// text that the form displays or the code uses for
+ /// text that the form displays or the code uses for
/// another purpose. Actions that don't use text ignore this parameter.
private void AccessForm(FormActions action, String formText)
@@ -820,7 +820,7 @@
///
/// Close the handle and FileStreams for a device.
///
- ///
+ ///
private void CloseCommunications()
{
if (_deviceData != null)
@@ -883,7 +883,7 @@
else
{
// Don't allow another transfer request until this one completes.
- // Move the focus away from the button to prevent the focus from
+ // Move the focus away from the button to prevent the focus from
// switching to the next control in the tab order on disabling the button.
fraControlTransfers.Focus();
@@ -910,7 +910,7 @@
try
{
// Don't allow another transfer request until this one completes.
- // Move the focus away from the button to prevent the focus from
+ // Move the focus away from the button to prevent the focus from
// switching to the next control in the tab order on disabling the button.
if (_transferInProgress)
@@ -937,7 +937,7 @@
///
///
///
- ///
+ ///
private void cmdGetInputReportInterrupt_Click(object sender, EventArgs e)
{
try
@@ -949,7 +949,7 @@
else
{
// Don't allow another transfer request until this one completes.
- // Move the focus away from the button to prevent the focus from
+ // Move the focus away from the button to prevent the focus from
// switching to the next control in the tab order on disabling the button.
fraInterruptTransfers.Focus();
@@ -1041,7 +1041,7 @@
else
{
// Don't allow another transfer request until this one completes.
- // Move the focus away from the button to prevent the focus from
+ // Move the focus away from the button to prevent the focus from
// switching to the next control in the tab order on disabling the button.
fraControlTransfers.Focus();
@@ -1062,7 +1062,7 @@
///
///
///
- ///
+ ///
private void cmdSendOutputReportControl_Click(object sender, EventArgs e)
{
try
@@ -1074,7 +1074,7 @@
else
{
// Don't allow another transfer request until this one completes.
- // Move the focus away from the button to prevent the focus from
+ // Move the focus away from the button to prevent the focus from
// switching to the next control in the tab order on disabling the button.
fraControlTransfers.Focus();
@@ -1091,7 +1091,7 @@
}
///
- /// Request to send an Output report using an interrupt transfer.
+ /// Request to send an Output report using an interrupt transfer.
///
///
///
@@ -1107,7 +1107,7 @@
else
{
// Don't allow another transfer request until this one completes.
- // Move the focus away from the button to prevent the focus from
+ // Move the focus away from the button to prevent the focus from
// switching to the next control in the tab order on disabling the button.
fraInterruptTransfers.Focus();
@@ -1204,7 +1204,7 @@
/// Called on removal of any device.
/// Calls a routine that searches to see if the desired device is still present.
///
- ///
+ ///
private void DeviceRemoved(object sender, EventArgs e)
{
try
@@ -1229,8 +1229,8 @@
///
/// Displays received or written report data.
///
- ///
- /// contains the report data.
+ ///
+ /// contains the report data.
/// "Input", "Output", or "Feature"
/// "read" for Input and IN Feature reports, "written" for Output and OUT Feature reports.
@@ -1274,7 +1274,7 @@
///
/// Display a message if the user clicks a button when a transfer is in progress.
///
- ///
+ ///
private void DisplayTransferInProgressMessage()
{
AccessForm(FormActions.AddItemToListBox, "Command not executed because a transfer is in progress.");
@@ -1288,7 +1288,7 @@
///
///
/// The timer is enabled only if continuous (periodic) transfers have been requested.
- ///
+ ///
private void DoPeriodicTransfers(object source, ElapsedEventArgs e)
{
@@ -1307,7 +1307,7 @@
/// Enable the command buttons on the form.
/// Needed after attempting a transfer and device not found.
///
- ///
+ ///
private void EnableFormControls()
{
cmdGetInputReportInterrupt.Enabled = true;
@@ -1322,9 +1322,9 @@
///
/// Use the System.Management class to find a device by Vendor ID and Product ID using WMI. If found, display device properties.
///
- ///
+ ///
/// During debugging, if you stop the firmware but leave the device attached, the device may still be detected as present
- /// but will be unable to communicate. The device will show up in Windows Device Manager as well.
+ /// but will be unable to communicate. The device will show up in Windows Device Manager as well.
/// This situation is unlikely to occur with a final product.
///
@@ -1338,26 +1338,45 @@
_deviceDetected = false;
var searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_PnPEntity");
+ int usbDeviceCounter = 0;
foreach (ManagementObject queryObj in searcher.Get())
{
- if (queryObj["PNPDeviceID"].ToString().Contains(deviceIdString))
- {
- _deviceDetected = true;
- MyMarshalDataToForm(FormActions.AddItemToListBox, "--------");
- MyMarshalDataToForm(FormActions.AddItemToListBox, "My device found (WMI):");
+ string deviceId = queryObj["PNPDeviceID"].ToString();
+ if (deviceId.Contains(deviceIdString))
+ {
+ usbDeviceCounter++;
+ _deviceDetected = true;
+ MyMarshalDataToForm(FormActions.AddItemToListBox, "--------");
+ MyMarshalDataToForm(FormActions.AddItemToListBox, "My device found (WMI):");
- // Display device properties.
+ // Display device properties.
- foreach (WmiDeviceProperties wmiDeviceProperty in Enum.GetValues(typeof(WmiDeviceProperties)))
- {
- MyMarshalDataToForm(FormActions.AddItemToListBox, (wmiDeviceProperty.ToString() + ": " + queryObj[wmiDeviceProperty.ToString()]));
- Debug.WriteLine(wmiDeviceProperty.ToString() + ": {0}", queryObj[wmiDeviceProperty.ToString()]);
- }
- MyMarshalDataToForm(FormActions.AddItemToListBox, "--------");
- MyMarshalDataToForm(FormActions.ScrollToBottomOfListBox, "");
- }
+ foreach (WmiDeviceProperties wmiDeviceProperty in Enum.GetValues(typeof(WmiDeviceProperties)))
+ {
+ MyMarshalDataToForm(FormActions.AddItemToListBox, (wmiDeviceProperty.ToString() + ": " + queryObj[wmiDeviceProperty.ToString()]));
+ Debug.WriteLine(wmiDeviceProperty.ToString() + ": {0}", queryObj[wmiDeviceProperty.ToString()]);
+ }
+ MyMarshalDataToForm(FormActions.AddItemToListBox, "--------");
+ MyMarshalDataToForm(FormActions.ScrollToBottomOfListBox, "");
+ }
+ else if (deviceId.StartsWith("USB\\"))
+ {
+ usbDeviceCounter++;
+ MyMarshalDataToForm(FormActions.AddItemToListBox, "--------");
+ MyMarshalDataToForm(FormActions.AddItemToListBox, "Skipping device:" + deviceId);
+ foreach (WmiDeviceProperties wmiDeviceProperty in Enum.GetValues(typeof(WmiDeviceProperties)))
+ {
+ MyMarshalDataToForm(FormActions.AddItemToListBox, (wmiDeviceProperty.ToString() + ": " + queryObj[wmiDeviceProperty.ToString()]));
+ Debug.WriteLine(wmiDeviceProperty.ToString() + ": {0}", queryObj[wmiDeviceProperty.ToString()]);
+ }
+ MyMarshalDataToForm(FormActions.AddItemToListBox, "--------");
+ MyMarshalDataToForm(FormActions.ScrollToBottomOfListBox, "");
+ }
}
+
+ MyMarshalDataToForm(FormActions.AddItemToListBox, "Found " + usbDeviceCounter /*searcher.Get().Count*/ + " USB HID devices");
+
if (!_deviceDetected)
{
MyMarshalDataToForm(FormActions.AddItemToListBox, "My device not found (WMI)");
@@ -1376,7 +1395,7 @@
/// Call HID functions that use Win32 API functions to locate a HID-class device
/// by its Vendor ID and Product ID. Open a handle to the device.
///
- ///
+ ///
///
/// True if the device is detected, False if not detected.
///
@@ -1426,7 +1445,7 @@
if (!_hidHandle.IsInvalid)
{
- // The returned handle is valid,
+ // The returned handle is valid,
// so find out if this is the device we're looking for.
_myHid.DeviceAttributes.Size = Marshal.SizeOf(_myHid.DeviceAttributes);
@@ -1514,7 +1533,7 @@
{
if (_myHid.Capabilities.InputReportByteLength > 0)
{
- // Set the size of the Input report buffer.
+ // Set the size of the Input report buffer.
var inputReportBuffer = new Byte[_myHid.Capabilities.InputReportByteLength];
@@ -1617,7 +1636,7 @@
///
/// Find and display the number of Input buffers
- /// (the number of Input reports the HID driver will store).
+ /// (the number of Input reports the HID driver will store).
///
private void GetInputReportBufferSize()
@@ -1643,10 +1662,10 @@
}
///
- /// Retrieve a Vendor ID and Product ID in hexadecimal
+ /// Retrieve a Vendor ID and Product ID in hexadecimal
/// from the form's text boxes and convert the text to Int32s.
///
- ///
+ ///
/// the Vendor ID
/// the Product ID
@@ -1712,11 +1731,11 @@
}
///
- /// Enables accessing a form's controls from another thread
+ /// Enables accessing a form's controls from another thread
///
- ///
+ ///
/// a FormActions member that names the action to perform on the form
- /// text that the form displays or the code uses for
+ /// text that the form displays or the code uses for
/// another purpose. Actions that don't use text ignore this parameter.
private void MyMarshalDataToForm(FormActions action, String textToDisplay)
@@ -1876,7 +1895,7 @@
_periodicTransfersRequested = false;
- // Disable the timer that triggers the transfers.
+ // Disable the timer that triggers the transfers.
_periodicTransfers.Stop();
cmdPeriodicTransfers.Enabled = true;
@@ -1929,10 +1948,10 @@
if ((_myHid.Capabilities.FeatureReportByteLength > 0))
{
- // The HID has a Feature report.
+ // The HID has a Feature report.
// Read a report from the device.
- // Set the size of the Feature report buffer.
+ // Set the size of the Feature report buffer.
if ((_myHid.Capabilities.FeatureReportByteLength > 0))
{
@@ -2009,7 +2028,7 @@
if (_myHid.Capabilities.InputReportByteLength > 0)
{
- // Set the size of the Input report buffer.
+ // Set the size of the Input report buffer.
inputReportBuffer = new Byte[_myHid.Capabilities.InputReportByteLength];
@@ -2030,9 +2049,9 @@
{
_transferInProgress = true;
- // Read a report using interrupt transfers.
+ // Read a report using interrupt transfers.
// Timeout if no report available.
- // To enable reading a report without blocking the calling thread, uses Filestream's ReadAsync method.
+ // To enable reading a report without blocking the calling thread, uses Filestream's ReadAsync method.
// Create a delegate to execute on a timeout.
@@ -2056,7 +2075,7 @@
// Arrive here only if the operation completed.
- // Dispose to stop the timeout timer.
+ // Dispose to stop the timeout timer.
cts.Dispose();
@@ -2096,7 +2115,6 @@
}
}
}
-
catch (Exception ex)
{
DisplayException(Name, ex);
@@ -2132,7 +2150,7 @@
if ((_myHid.Capabilities.FeatureReportByteLength > 0))
{
// The HID has a Feature report.
- // Set the size of the Feature report buffer.
+ // Set the size of the Feature report buffer.
var outFeatureReportBuffer = new Byte[_myHid.Capabilities.FeatureReportByteLength];
@@ -2165,7 +2183,6 @@
ScrollToBottomOfListBox();
}
}
-
else
{
AccessForm(FormActions.AddItemToListBox, "The HID doesn't have a Feature report.");
@@ -2218,7 +2235,7 @@
if (_myHid.Capabilities.OutputReportByteLength > 0)
{
- // Set the size of the Output report buffer.
+ // Set the size of the Output report buffer.
var outputReportBuffer = new Byte[_myHid.Capabilities.OutputReportByteLength];
@@ -2305,7 +2322,6 @@
AccessForm(FormActions.AddItemToListBox, "The HID doesn't have an Output report.");
}
}
-
catch (Exception ex)
{
DisplayException(Name, ex);
@@ -2417,7 +2433,7 @@
}
///
- /// Set the number of Input buffers (the number of Input reports
+ /// Set the number of Input buffers (the number of Input reports
/// the host will store) from the value in the text box.
///
@@ -2542,7 +2558,7 @@
/// Provides a central mechanism for exception handling.
/// Displays a message box that describes the exception.
///
- ///
+ ///
/// the module where the exception occurred.
/// the exception
@@ -2557,7 +2573,7 @@
MessageBox.Show(message, caption, MessageBoxButtons.OK);
Debug.Write(message);
- // Get the last error and display it.
+ // Get the last error and display it.
Int32 error = Marshal.GetLastWin32Error();