Bluestar88
Member level 3
Hi guys,
I am trying to connect my hardware to PC by USB in visual basic 2005. my hardware is composed of: atmega32, two 68 ohm registers,a 1.5 kilo ohm register, Two diodes and...
for software which I can apply in PC, I used from https://helmpcb.com/software/usb-hid-template-for-visual-basic-2005.
fortunately, when I connect my hardware to PC, It can be recognize...I matched my hardware vendor ID and product ID with visual basic 2005 .. but visual basic 2005 can not recognize my hardware..
My code is here:
and I added mcHID.dll in system 32 ...But when I runs visual basic 2005 always it shows "Device is Not attached!" in textbox2.text....I think there is a problem from phandle...because it is zero....please help me...please...
I am trying to connect my hardware to PC by USB in visual basic 2005. my hardware is composed of: atmega32, two 68 ohm registers,a 1.5 kilo ohm register, Two diodes and...
for software which I can apply in PC, I used from https://helmpcb.com/software/usb-hid-template-for-visual-basic-2005.
fortunately, when I connect my hardware to PC, It can be recognize...I matched my hardware vendor ID and product ID with visual basic 2005 .. but visual basic 2005 can not recognize my hardware..
My code is here:
Code:
Public Class frmUSB
' vendor and product IDs
Private Const VendorID As Integer = &H16C0 'Replace with your device's
Private Const ProductID As Integer = &H5DC 'product and vendor IDs
' read and write buffers
Private Const BufferInSize As Integer = 1 'Size of the data buffer coming IN to the PC
Private Const BufferOutSize As Integer = 1 'Size of the data buffer going OUT from the PC
Dim BufferIn(BufferInSize) As Byte 'Received data will be stored here - the first byte in the array is unused
Dim BufferOut(BufferOutSize) As Byte 'Transmitted data is stored here - the first item in the array must be 0
' ****************************************************************
' when the form loads, connect to the HID controller - pass
' the form window handle so that you can receive notification
' events...
'*****************************************************************
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' do not remove!
ConnectToHID(Me)
If hidIsAvailable(VendorID, ProductID) Then
TextBox1.Text = "Device is attached!"
Button1.BackColor = Color.GreenYellow
Else
TextBox2.Text = "Device is Not attached!"
Button2.BackColor = Color.Red
End If
End Sub
'*****************************************************************
' disconnect from the HID controller...
'*****************************************************************
Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
DisconnectFromHID()
End Sub
'*****************************************************************
' a HID device has been plugged in...
'*****************************************************************
Public Sub OnPlugged(ByVal pHandle As Integer)
If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
TextBox1.Text = "Device is attached!"
Button1.BackColor = Color.GreenYellow
End If
End Sub
'*****************************************************************
' a HID device has been unplugged...
'*****************************************************************
Public Sub OnUnplugged(ByVal pHandle As Integer)
If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
hidSetReadNotify(hidGetHandle(VendorID, ProductID), False)
TextBox2.Text = "Device is Not attached!"
Button2.BackColor = Color.Red
End If
End Sub
'*****************************************************************
' controller changed notification - called
' after ALL HID devices are plugged or unplugged
'*****************************************************************
Public Sub OnChanged()
' get the handle of the device we are interested in, then set
' its read notify flag to true - this ensures you get a read
' notification message when there is some data to read...
Dim pHandle As Integer
pHandle = hidGetHandle(VendorID, ProductID)
hidSetReadNotify(hidGetHandle(VendorID, ProductID), True)
End Sub
'*****************************************************************
' on read event...
'*****************************************************************
Public Sub OnRead(ByVal pHandle As Integer)
' read the data (don't forget, pass the whole array)...
If hidRead(pHandle, BufferIn(0)) Then
' ** YOUR CODE HERE **
' first byte is the report ID, e.g. BufferIn(0)
' the other bytes are the data from the microcontroller...
End If
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
End Sub
End Class
and I added mcHID.dll in system 32 ...But when I runs visual basic 2005 always it shows "Device is Not attached!" in textbox2.text....I think there is a problem from phandle...because it is zero....please help me...please...