CodePudding user response:
USB plug will be a news broadcastCan cover wndproc receives the message
This is the most simple
CodePudding user response:
Use libusb or cyusb libraryCodePudding user response:
Hello, I am also do the vb PC, could you please ask you some questions, this is my qq: 1812775970, could you add as a friend, thank youCodePudding user response:
Directly in a window to define a message filter or overloading wndproc, USB devices will be broadcast to all Windows when there is a change a message, it is ok to deal with the message, use a timer to make a sample, through the WMI device enumeration, with some characters of the device name (CH340) to distinguish, you look at:Dim WM_DEVICECHANGE As Integer=& amp; H219
Dim DBT_DEVICEREMOVECOMPLETE As Integer=& amp; H8004
Dim DBT_DEVICEARRIVAL As Integer=& amp; H8000
Protected Overrides Sub WndProc (ByRef m As Message)
MyBase. WndProc (m)
If m.M sg=WM_DEVICECHANGE Then
If m. Param. ToInt32=DBT_DEVICEARRIVAL Then usb insert
'TmrAutoSetPort. Enabled=True
ElseIf m. Param. ToInt32=DBT_DEVICEREMOVECOMPLETE Then
TmrAutoSetPort. Enabled=True
End the If
End the If
Private Sub tmrAutoSetPort_Tick (sender As Object, As EventArgs e) Handles tmrAutoSetPort. Tick
Dim b=New ManagementObjectSearcher (" select * from Win32_PnPEntity "). Get 'test plug and play device
Dim LST As New List (Of String)
Try
For Each c In b
Try
Be sad etPropertyValue chtistina georgina rossetti.british poetess If (" Name "). The ToString. The Contains (" CH340 ") Then
Be sad etPropertyValue chtistina georgina rossetti.british poetess LST. Add ((" Name "))
End the If
Catch the ex As Exception
End the Try
Next
Catch the ex As Exception
End the Try
End Sub
End Sub
In the code to detect the CH340 equipment and added to a list, pull out the handle didn't write, write their own.
CodePudding user response:
Oww, stick together, the two function End Sub position is wrong, change yourself,