Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Muiltiple PIC USB HID Devices & Visual Basic 2008

Status
Not open for further replies.

bkar

Junior Member level 3
Joined
Nov 1, 2010
Messages
26
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,626
Dear Friends,

I am using mcHID.dll from this link **broken link removed**. And successfully communicate PIC HID device with PC. Now I am interested to add multiple PIC based HID Device with the PC and collect the data from those device to PC. Can any body give me some good idea about both VB2008 & PIC Hid devices sources code.

Thanks in advance
bkar
 

bkar

Junior Member level 3
Joined
Nov 1, 2010
Messages
26
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,626
your link does work

if it is just a question of connecting multiple USB devices to a single USB port you could use a USB hub
https://www.ebay.co.uk/gds/Top-6-Multiport-USB-Hubs-/10000000177715714/g.html

Dear horace1,

I am trying describe my problems. And sorry for my bad English.I have created 6 individual USB HID device (PIC uC). Those devices can read temperature and send data to PC. Now I need a PC Software that could able read data from those customized HID devices. the link that I mentioned is perfect (Visual basic code) for controlling a single PIC based USB HID Device. But I need to control 6 USB HID devices!!!.

I just need some idea or a way to beginning with the help of...... If any body help here...I would be very grateful and obliged there by.

Thanks
bkar
 

horace1

Advanced Member level 5
Joined
Nov 18, 2008
Messages
2,118
Helped
596
Reputation
1,188
Reaction score
571
Trophy points
1,393
Location
Norwich, UK
Activity points
13,063
But I need to control 6 USB HID devices!!!.

you have already managed to connect to one USB HID device from VB.NET
I assume you get a list of attached USB devices using SetupDiGetClassDevsUM
https://msdn.microsoft.com/en-gb/library/windows/hardware/ff551069(v=vs.85).aspx

and then go thru the list checking the USB vendor and product IDs (VID and PID) using SetupDiEnumDeviceInterfacesUM
https://msdn.microsoft.com/en-gb/library/windows/hardware/ff551015(v=vs.85).aspx

and open the correct device
You should be able to open six devices in this way (i assume they all have different VID and PIDs) and communicate with them

the link you give to the VB project in your first post does not work
 
  • Like
Reactions: bkar

    bkar

    Points: 2
    Helpful Answer Positive Rating

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
50,786
Helped
14,600
Reputation
29,475
Reaction score
13,680
Trophy points
1,393
Location
Bochum, Germany
Activity points
290,842
OS have no problems to connect to multiple USB devices of the same type (same VID and PID). The question is if your USB dll is prepared to handle multple devices or just connects to the "next best"? Did you already try to find out?
 

bkar

Junior Member level 3
Joined
Nov 1, 2010
Messages
26
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,626
Re: Muiltiple PIC USB HID Devices & Visual Basic 2008

the link you give to the VB project in your first post does not work

Dear horace1,

If you see my entire project I believe it will be easy to understand the whole thing. I am uploading my entire project, there you will find that I only modify the "USBTemplate1" that I found from **broken link removed**. I used Visual Basic2012(PC) , MikroC Pro for PIC 6.4.0 Version(uC) & Proteus(Simulation). Please check the attachment.

And now the link https://msdn.microsoft.com/en-gb/libr...=vs.85%29.aspx What they told is too hard for me to understand. but mcHID.dll is more easier but this dll file can handle Only one USB HID devices as i known from that site(Please See comments).

If there is a way to modify this file(mcHID.dll)....e.g scanning various devices VID & PID and when VB compiler get correct VID & PID numbers it will starting received data from those devices.....and.....displaying through PC....

I think I can handle that.And sorry for my bad English as I am from Bangladesh.

Thanks
bkar

- - - Updated - - -

Dear FvM,

Please See my project. And If there any way please help me. :???:And One question to you what do you mean by the 'next best' ?

Thank you in advance
bkar
 

Attachments

  • OK For Single MC - Net.rar
    740.6 KB · Views: 106

bkar

Junior Member level 3
Joined
Nov 1, 2010
Messages
26
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,626
Dear horace1,
At last my problem about this topics has been solve. And I am going to share it. As I think it will be helpful a some one like me. The fact's are -

1. In visual basic source code Each device has to be different VID & PID number. like below -
<Code>
Private Const VendorID1 As Integer = &H1231 'For Device A
Private Const ProductID1 As Integer = &H1 'For Device A
Private Const VendorID2 As Integer = &H1232 'For Device B
Private Const ProductID2 As Integer = &H2 'For Device B
Private Const VendorID3 As Integer = &H1233 'For Device C
Private Const ProductID3 As Integer = &H3 'For Device C
</Code>
2. Also have to modified Onplugged, Onunplugged and Onchange function. like below -
<code>
'*****************************************************************
' a HID device has been plugged in...
'*****************************************************************
Public Sub OnPlugged(ByVal pHandle As Integer)
If hidGetVendorID(pHandle) = VendorID1 And hidGetProductID(pHandle) = ProductID1 Then
Label186.Text = "Status : Device A Plugged"
DeviceAoff.Visible = False
DeviceAon.Visible = True
Label4.Text = "Device A Status: Device is connected"
End If
If hidGetVendorID(pHandle) = VendorID2 And hidGetProductID(pHandle) = ProductID2 Then
Label187.Text = "Status : Device B Plugged"
DeviceBoff.Visible = False
DeviceBon.Visible = True
Label97.Text = "Device B Status: Device is connected"
End If
If hidGetVendorID(pHandle) = VendorID3 And hidGetProductID(pHandle) = ProductID3 Then
Label188.Text = "Status : Device C Plugged"
DeviceCoff.Visible = False
DeviceCon.Visible = True
Label98.Text = "Device C Status: Device is connected"
End If


End Sub

'*****************************************************************
' a HID device has been unplugged...
'*****************************************************************
Public Sub OnUnplugged(ByVal pHandle)
If hidGetVendorID(pHandle) = VendorID1 And hidGetProductID(pHandle) = ProductID1 Then
hidSetReadNotify(hidGetHandle(VendorID1, ProductID1), False)
Label186.Text = "Status : Device A Unplugged"
DeviceAoff.Visible = True
DeviceAon.Visible = False
Label4.Text = "Device A Status: Device is not connected"
End If
If hidGetVendorID(pHandle) = VendorID2 And hidGetProductID(pHandle) = ProductID2 Then
hidSetReadNotify(hidGetHandle(VendorID2, ProductID2), False)
Label187.Text = "Status : Device B Unplugged"
DeviceBoff.Visible = True
DeviceBon.Visible = False
Label97.Text = "Device B Status: Device is not connected"
End If
If hidGetVendorID(pHandle) = VendorID3 And hidGetProductID(pHandle) = ProductID3 Then
hidSetReadNotify(hidGetHandle(VendorID3, ProductID3), False)
Label188.Text = "Status : Device C Unplugged"
DeviceCoff.Visible = True
DeviceCon.Visible = False
Label98.Text = "Device C Status: Device is not connected"
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(VendorID1, ProductID1)
hidSetReadNotify(hidGetHandle(VendorID1, ProductID1), True)
pHandle = hidGetHandle(VendorID2, ProductID2)
hidSetReadNotify(hidGetHandle(VendorID2, ProductID2), True)
pHandle = hidGetHandle(VendorID3, ProductID3)
hidSetReadNotify(hidGetHandle(VendorID3, ProductID3), True)

End Sub
</code>

And finally
3. Have to modified Onread event, like below-
<code>
'*****************************************************************
' on read event...
'*****************************************************************
Public Sub OnRead(ByVal pHandle As Integer)
Label2.Text = Format(Now, "Long Time")
SamplingTime = TimeOfDay.Minute.ToString
' read the data (don't forget, pass the whole array)...
If pHandle = hidGetHandle(VendorID1, ProductID1) Then
Label4.Text = "Device A Status: Reading Data"

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...
samaple10 = Chr(BufferIn(1)) & Chr(BufferIn(2)) & Chr(BufferIn(3)) & Chr(BufferIn(4)) & Chr(BufferIn(5)) & Chr(BufferIn(6))
samaple11 = Chr(BufferIn(7)) & Chr(BufferIn(8)) & Chr(BufferIn(9)) & Chr(BufferIn(10)) & Chr(BufferIn(11)) & Chr(BufferIn(12))
samaple12 = Chr(BufferIn(13)) & Chr(BufferIn(14)) & Chr(BufferIn(15)) & Chr(BufferIn(16)) & Chr(BufferIn(17)) & Chr(BufferIn(18))
samaple13 = Chr(BufferIn(19)) & Chr(BufferIn(20)) & Chr(BufferIn(21)) & Chr(BufferIn(22)) & Chr(BufferIn(23)) & Chr(BufferIn(24))
samaple14 = Chr(BufferIn(25)) & Chr(BufferIn(26)) & Chr(BufferIn(27)) & Chr(BufferIn(28)) & Chr(BufferIn(29)) & Chr(BufferIn(30))
samaple15 = Chr(BufferIn(31)) & Chr(BufferIn(32)) & Chr(BufferIn(33)) & Chr(BufferIn(34)) & Chr(BufferIn(35)) & Chr(BufferIn(36))
samaple16 = Chr(BufferIn(37)) & Chr(BufferIn(38)) & Chr(BufferIn(39)) & Chr(BufferIn(40)) & Chr(BufferIn(41)) & Chr(BufferIn(42))
samaple17 = Chr(BufferIn(43)) & Chr(BufferIn(44)) & Chr(BufferIn(45)) & Chr(BufferIn(46)) & Chr(BufferIn(47)) & Chr(BufferIn(48))
samaple18 = Chr(BufferIn(49)) & Chr(BufferIn(50)) & Chr(BufferIn(51)) & Chr(BufferIn(52)) & Chr(BufferIn(53)) & Chr(BufferIn(54))
samaple19 = Chr(BufferIn(55)) & Chr(BufferIn(56)) & Chr(BufferIn(57)) & Chr(BufferIn(58)) & Chr(BufferIn(59)) & Chr(BufferIn(60))
unused1 = Chr(BufferIn(61)) & Chr(BufferIn(62)) & Chr(BufferIn(63)) & Chr(BufferIn(64))
Label16.Text = samaple10
Label17.Text = samaple11
Label18.Text = samaple12
Label19.Text = samaple13
Label20.Text = samaple14
Label21.Text = samaple15
Label22.Text = samaple16
Label23.Text = samaple17
Label24.Text = samaple18
Label25.Text = samaple19
'Label4.Text = "Device A Status: Device Idle"
End If
End If
If pHandle = hidGetHandle(VendorID2, ProductID2) Then

Label97.Text = "Device B Status: Reading Data"

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...
samaple20 = Chr(BufferIn(1)) & Chr(BufferIn(2)) & Chr(BufferIn(3)) & Chr(BufferIn(4)) & Chr(BufferIn(5)) & Chr(BufferIn(6))
samaple21 = Chr(BufferIn(7)) & Chr(BufferIn(8)) & Chr(BufferIn(9)) & Chr(BufferIn(10)) & Chr(BufferIn(11)) & Chr(BufferIn(12))
samaple22 = Chr(BufferIn(13)) & Chr(BufferIn(14)) & Chr(BufferIn(15)) & Chr(BufferIn(16)) & Chr(BufferIn(17)) & Chr(BufferIn(18))
samaple23 = Chr(BufferIn(19)) & Chr(BufferIn(20)) & Chr(BufferIn(21)) & Chr(BufferIn(22)) & Chr(BufferIn(23)) & Chr(BufferIn(24))
samaple24 = Chr(BufferIn(25)) & Chr(BufferIn(26)) & Chr(BufferIn(27)) & Chr(BufferIn(28)) & Chr(BufferIn(29)) & Chr(BufferIn(30))
samaple25 = Chr(BufferIn(31)) & Chr(BufferIn(32)) & Chr(BufferIn(33)) & Chr(BufferIn(34)) & Chr(BufferIn(35)) & Chr(BufferIn(36))
samaple26 = Chr(BufferIn(37)) & Chr(BufferIn(38)) & Chr(BufferIn(39)) & Chr(BufferIn(40)) & Chr(BufferIn(41)) & Chr(BufferIn(42))
samaple27 = Chr(BufferIn(43)) & Chr(BufferIn(44)) & Chr(BufferIn(45)) & Chr(BufferIn(46)) & Chr(BufferIn(47)) & Chr(BufferIn(48))
samaple28 = Chr(BufferIn(49)) & Chr(BufferIn(50)) & Chr(BufferIn(51)) & Chr(BufferIn(52)) & Chr(BufferIn(53)) & Chr(BufferIn(54))
samaple29 = Chr(BufferIn(55)) & Chr(BufferIn(56)) & Chr(BufferIn(57)) & Chr(BufferIn(58)) & Chr(BufferIn(59)) & Chr(BufferIn(60))
unused2 = Chr(BufferIn(61)) & Chr(BufferIn(62)) & Chr(BufferIn(63)) & Chr(BufferIn(64))
Label55.Text = samaple20
Label54.Text = samaple21
Label53.Text = samaple22
Label52.Text = samaple23
Label51.Text = samaple24
Label50.Text = samaple25
Label49.Text = samaple26
Label48.Text = samaple27
Label47.Text = samaple28
Label46.Text = samaple29
'Label97.Text = "Device B Status: Device Idle"
End If
End If
If pHandle = hidGetHandle(VendorID3, ProductID3) Then
Label98.Text = "Device C Status: Reading Data"
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...
samaple30 = Chr(BufferIn(1)) & Chr(BufferIn(2)) & Chr(BufferIn(3)) & Chr(BufferIn(4)) & Chr(BufferIn(5)) & Chr(BufferIn(6))
samaple31 = Chr(BufferIn(7)) & Chr(BufferIn(8)) & Chr(BufferIn(9)) & Chr(BufferIn(10)) & Chr(BufferIn(11)) & Chr(BufferIn(12))
samaple32 = Chr(BufferIn(13)) & Chr(BufferIn(14)) & Chr(BufferIn(15)) & Chr(BufferIn(16)) & Chr(BufferIn(17)) & Chr(BufferIn(18))
samaple33 = Chr(BufferIn(19)) & Chr(BufferIn(20)) & Chr(BufferIn(21)) & Chr(BufferIn(22)) & Chr(BufferIn(23)) & Chr(BufferIn(24))
samaple34 = Chr(BufferIn(25)) & Chr(BufferIn(26)) & Chr(BufferIn(27)) & Chr(BufferIn(28)) & Chr(BufferIn(29)) & Chr(BufferIn(30))
samaple35 = Chr(BufferIn(31)) & Chr(BufferIn(32)) & Chr(BufferIn(33)) & Chr(BufferIn(34)) & Chr(BufferIn(35)) & Chr(BufferIn(36))
samaple36 = Chr(BufferIn(37)) & Chr(BufferIn(38)) & Chr(BufferIn(39)) & Chr(BufferIn(40)) & Chr(BufferIn(41)) & Chr(BufferIn(42))
samaple37 = Chr(BufferIn(43)) & Chr(BufferIn(44)) & Chr(BufferIn(45)) & Chr(BufferIn(46)) & Chr(BufferIn(47)) & Chr(BufferIn(48))
samaple38 = Chr(BufferIn(49)) & Chr(BufferIn(50)) & Chr(BufferIn(51)) & Chr(BufferIn(52)) & Chr(BufferIn(53)) & Chr(BufferIn(54))
samaple39 = Chr(BufferIn(55)) & Chr(BufferIn(56)) & Chr(BufferIn(57)) & Chr(BufferIn(58)) & Chr(BufferIn(59)) & Chr(BufferIn(60))
unused3 = Chr(BufferIn(61)) & Chr(BufferIn(62)) & Chr(BufferIn(63)) & Chr(BufferIn(64))
Label85.Text = samaple30
Label84.Text = samaple31
Label83.Text = samaple32
Label82.Text = samaple33
Label81.Text = samaple34
Label80.Text = samaple35
Label79.Text = samaple36
Label78.Text = samaple37
Label77.Text = samaple38
Label76.Text = samaple39
'Label98.Text = "Device C Status: Device Idle"
End If
End If
End Sub
</code>


I am not a very good ex-plainer. I hope you understand what I meant. I share this because this forum helps me a lot .

With this code I am able to get data form the individual 3 devices. I think with this process we can communicate more devices with the PC .

Thank you,

Bahadur Kar
Transcom Electronics
Bangladesh
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top